2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
17 Point::Point(int x
, int y
)
23 Point::Point(const QPoint
& p
)
34 Point::Point(const QString
& str
, int ysize
) {
36 int length
= str
.length();
39 if(str
[0].isLetter()) {
40 char c
= str
[0].toAscii();
41 if(c
>= 'a' && c
<= 'z')
43 else if(c
>= 'A' && c
<= 'Z')
46 y
= ysize
- str
.mid(1).toInt();
49 y
= ysize
- str
.toInt();
52 QString
Point::row(int ysize
) const {
54 return QString::number(ysize
- y
);
59 QString
Point::col() const {
62 return QChar(static_cast<char>(x
- 26 + 'A'));
64 return QChar(static_cast<char>(x
+ 'a'));
70 QString
Point::toString(int ysize
) const {
71 return col() + row(ysize
);
74 Point
Point::operator+(const Point
& other
) const {
75 return Point(x
+ other
.x
, y
+ other
.y
);
78 Point
Point::operator+=(const Point
& other
) {
79 return *this = *this + other
;
82 Point
Point::operator-() const {
86 Point
Point::operator-(const Point
& other
) const {
87 return Point(x
- other
.x
, y
- other
.y
);
90 Point
Point::operator*(int n
) const {
91 return Point(x
* n
, y
* n
);
94 Point
Point::operator/(int n
) const {
95 return Point(x
/ n
, y
/ n
);
98 Point
Point::div(int n
) const {
99 return Point(x
>= 0 ? x
/ n
: x
/ n
- 1,
100 y
>= 0 ? y
/ n
: y
/ n
- 1);
103 bool Point::operator==(const Point
& other
) const {
104 return x
== other
.x
&& y
== other
.y
;
107 bool Point::operator!=(const Point
& other
) const
109 return !(*this == other
);
112 bool Point::operator<(const Point
& other
) const
114 return y
< other
.y
|| (y
== other
.y
&& x
< other
.x
);
117 bool Point::operator<=(const Point
& other
) const
119 return y
<= other
.y
|| (y
== other
.y
&& x
<= other
.x
);
122 bool Point::resembles(const Point
& other
) const
124 return (other
.x
== -1 || x
== other
.x
) &&
125 (other
.y
== -1 || y
== other
.y
);
128 Point::operator QPoint() const
133 Point
Point::normalizeInfinity() const
136 normalizeInfinityHelper(x
),
137 normalizeInfinityHelper(y
)
141 double Point::norm() const
143 return sqrt((double)(x
*x
+ y
*y
));
146 int Point::normalizeInfinityHelper(int n
) const
151 return n
> 0 ? 1 : -1;
154 std::ostream
& operator<<(std::ostream
& os
, const Point
& p
)
156 return os
<< "(" << (p
.x
== -1 ? QString("?") : QString::number(p
.x
))
157 << ", " << (p
.y
== -1 ? QString("?") : QString::number(p
.y
)) << ")";