App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Geometry.hpp
Go to the documentation of this file.
1
6 // forward declaration
7 namespace app {
8 class Point;
9 class Vect;
10 class Rect;
11 }
12
13 #ifndef GEOMETRY_HPP_
14 #define GEOMETRY_HPP_
15
16 namespace app {
17
22 class Point {
23 public:
24 int x;
25 int y;
26
28 Point() { x = 0; y = 0; }
29
31
36 Point(int x, int y) { this->x = x; this->y = y; }
37
39
43 int isPositive() const { if (x < 0 || y < 0) { return 0; } else { return 1; } }
44 };
45
50 class Vect {
51 public:
52 Point from;
53 Point to;
54
56 Vect() { from = Point(0, 0); to = Point(0, 0); }
57
59
63 Vect(const Point to) { from = Point(0, 0); this->to = to; }
64
66
71 Vect(int tox, int toy) { from = Point(0, 0); to = Point(tox, toy); }
72
74
79 Vect(const Point from, const Point to) { this->from = from; this->to = to; }
80
82
89 Vect(int fromx, int fromy, int tox, int toy) { from = Point(fromx, fromy); to = Point(tox, toy); }
90
92 int getdx() { return to.x - from.x; }
93
95 int getdy() { return to.y - from.y; }
96 };
97
104 class Rect {
105 public:
106
107 Point tl;
108 Point br;
109
111 Rect() { tl = Point(0, 0); br = Point(0, 0); }
112
114
119 Rect(const Point tl, const Point br) { this->tl = tl; this->br = br; }
120
122
129 Rect(int tlx, int tly, int brx, int bry) { tl = Point(tlx, tly); br = Point(brx, bry); }
130
132
136 int isValid() const { if ((getWidth() <=0) || (getHeight() <= 0)) { return 0; } else { return 1; } }
137
139
143 int isPositive() const { if (tl.isPositive() && br.isPositive()) { return 1; } else { return 0; } }
144
146 int getWidth() const { return (br.x - tl.x); }
147
149 int getHeight() const { return (br.y - tl.y); }
150
152
157 int moveTo(const Point ntl);
158
160
165 Rect makeCopyAt(const Point ntl) const;
166
168
174 static Rect makeCopyAt(const Rect &src, Point ntl);
175
177
186 int resizeBy(const Vect dtl, const Vect dbr);
187
189
199 static Rect makeResizedCopy(const Rect &src, const Vect dtl, const Vect dbr);
200
202
211 static Rect getIntersection(const Rect &rct1, const Rect &rct2);
212
214
223 int getDifference(const Rect &other, Vect &dtl, Vect &dbr) const;
224 };
225
226 }
227 #endif /* GEOMETRY_HPP_ */