2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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.
16 Point::Point(int x
, int y
)
22 Point::Point(const QPoint
& p
)
33 Point::Point(const QString
& str
, int ysize
) {
35 int length
= str
.length();
38 if(str
[0].isLetter()) {
39 char c
= str
[0].toAscii();
40 if(c
>= 'a' && c
<= 'z')
42 else if(c
>= 'A' && c
<= 'Z')
45 y
= ysize
- str
.mid(1).toInt();
48 y
= ysize
- str
.toInt();
51 QString
Point::row(int ysize
) const {
53 return QString::number(ysize
- y
);
57 QString
Point::numcol(int xsize
) const {
59 return QString::number(xsize
- x
);
64 QString
Point::col() const {
67 return QChar(static_cast<char>(x
- 26 + 'A'));
69 return QChar(static_cast<char>(x
+ 'a'));
74 QString
Point::alpharow() const {
77 return QChar(static_cast<char>(y
- 26 + 'A'));
79 return QChar(static_cast<char>(y
+ 'a'));
85 QString
Point::toString(int ysize
) const {
86 return col() + row(ysize
);
89 Point
Point::operator+(const Point
& other
) const {
90 return Point(x
+ other
.x
, y
+ other
.y
);
93 Point
Point::operator+=(const Point
& other
) {
94 return *this = *this + other
;
97 Point
Point::operator-() const {
101 Point
Point::operator-(const Point
& other
) const {
102 return Point(x
- other
.x
, y
- other
.y
);
105 Point
Point::operator*(int n
) const {
106 return Point(x
* n
, y
* n
);
109 Point
Point::operator/(int n
) const {
110 return Point(x
/ n
, y
/ n
);
113 Point
Point::div(int n
) const {
114 return Point(x
>= 0 ? x
/ n
: x
/ n
- 1,
115 y
>= 0 ? y
/ n
: y
/ n
- 1);
118 bool Point::operator==(const Point
& other
) const {
119 return x
== other
.x
&& y
== other
.y
;
122 bool Point::operator!=(const Point
& other
) const
124 return !(*this == other
);
127 bool Point::operator<(const Point
& other
) const
129 return y
< other
.y
|| (y
== other
.y
&& x
< other
.x
);
132 bool Point::operator<=(const Point
& other
) const
134 return y
<= other
.y
|| (y
== other
.y
&& x
<= other
.x
);
137 bool Point::resembles(const Point
& other
) const
139 return (other
.x
== -1 || x
== other
.x
) &&
140 (other
.y
== -1 || y
== other
.y
);
143 Point::operator QPoint() const
148 Point
Point::normalizeInfinity() const
151 normalizeInfinityHelper(x
),
152 normalizeInfinityHelper(y
)
156 double Point::norm() const
158 return sqrt((double)(x
*x
+ y
*y
));
161 int Point::normalizeInfinityHelper(int n
) const
166 return n
> 0 ? 1 : -1;
169 QDebug
operator<<(QDebug dbg
, const Point
& p
)
171 dbg
<< "(" << (p
.x
== -1 ? "?" : qPrintable(QString::number(p
.x
)))
172 << ", " << (p
.y
== -1 ? "?" : qPrintable(QString::number(p
.y
))) << ")";