Isle
Loading...
Searching...
No Matches
mxgeometry.h
Go to the documentation of this file.
1#ifndef MXGEOMETRY_H
2#define MXGEOMETRY_H
3
4#include "mxlist.h"
5#include "mxutilities.h"
6
12template <class T>
13class MxPoint {
14protected:
15 T m_x;
16 T m_y;
18public:
23
28 MxPoint(const MxPoint& p_p)
29 {
30 m_x = p_p.m_x;
31 m_y = p_p.m_y;
32 }
33
39 MxPoint(T p_x, T p_y)
40 {
41 m_x = p_x;
42 m_y = p_y;
43 }
44
48 T GetX() const { return m_x; }
49
53 T GetY() const { return m_y; }
54
59 void SetX(T p_x) { m_x = p_x; }
60
65 void SetY(T p_y) { m_y = p_y; }
66
71 void operator+=(const MxPoint& p_p)
72 {
73 m_x += p_p.m_x;
74 m_y += p_p.m_y;
75 }
76
81 void operator-=(const MxPoint& p_p)
82 {
83 m_x -= p_p.m_x;
84 m_y -= p_p.m_y;
85 }
86
91 MxPoint operator+(const MxPoint& p_p) const { return MxPoint(m_x + p_p.m_x, m_y + p_p.m_y); }
92
97 MxPoint operator-(const MxPoint& p_p) const { return MxPoint(m_x - p_p.m_x, m_y - p_p.m_y); }
98};
99
105template <class T>
106class MxSize {
107protected:
111public:
116
121 MxSize(const MxSize& p_s)
122 {
123 m_width = p_s.m_width;
124 m_height = p_s.m_height;
125 }
131 MxSize(T p_width, T p_height)
132 {
133 m_width = p_width;
134 m_height = p_height;
135 }
139 T GetWidth() const { return m_width; }
140
144 T GetHeight() const { return m_height; }
145
150 void SetWidth(T p_width) { m_width = p_width; }
151
156 void SetHeight(T p_height) { m_height = p_height; }
157};
158
164template <class T>
165class MxRect {
166protected:
172public:
177
182 MxRect(const MxRect& p_r)
183 {
184 m_left = p_r.m_left;
185 m_top = p_r.m_top;
186 m_right = p_r.m_right;
187 m_bottom = p_r.m_bottom;
188 }
189
197 MxRect(T p_l, T p_t, T p_r, T p_b)
198 {
199 m_left = p_l;
200 m_top = p_t;
201 m_right = p_r;
202 m_bottom = p_b;
203 }
204
210 MxRect(const MxPoint<T>& p_p, const MxSize<T>& p_s)
211 {
212 m_left = p_p.GetX();
213 m_top = p_p.GetY();
214 m_right = p_p.GetX() + p_s.GetWidth() - 1;
215 m_bottom = p_p.GetY() + p_s.GetHeight() - 1;
216 }
217
221 T GetLeft() const { return m_left; }
226 void SetLeft(T p_left) { m_left = p_left; }
227
231 T GetTop() const { return m_top; }
236 void SetTop(T p_top) { m_top = p_top; }
237
241 T GetRight() const { return m_right; }
246 void SetRight(T p_right) { m_right = p_right; }
247
251 T GetBottom() const { return m_bottom; }
256 void SetBottom(T p_bottom) { m_bottom = p_bottom; }
257
262 T GetWidth() const { return (m_right - m_left + 1); }
263
268 T GetHeight() const { return (m_bottom - m_top + 1); }
269
273 MxPoint<T> GetLT() const { return MxPoint<T>(m_left, m_top); }
274
279
284 MxBool Empty() const { return m_left >= m_right || m_top >= m_bottom; }
285
290 MxBool Contains(const MxPoint<T>& p_p) const
291 {
292 return p_p.GetX() >= m_left && p_p.GetX() <= m_right && p_p.GetY() >= m_top && p_p.GetY() <= m_bottom;
293 }
294
299 MxBool Intersects(const MxRect& p_r) const
300 {
301 return p_r.m_right > m_left && p_r.m_left < m_right && p_r.m_bottom > m_top && p_r.m_top < m_bottom;
302 }
303
308 void operator=(const MxRect& p_r)
309 {
310 m_left = p_r.m_left;
311 m_top = p_r.m_top;
312 m_right = p_r.m_right;
313 m_bottom = p_r.m_bottom;
314 }
315
320 MxBool operator==(const MxRect& p_r) const
321 {
322 return m_left == p_r.m_left && m_top == p_r.m_top && m_right == p_r.m_right && m_bottom == p_r.m_bottom;
323 }
324
329 MxBool operator!=(const MxRect& p_r) const { return !operator==(p_r); }
330
335 void operator+=(const MxPoint<T>& p_p)
336 {
337 m_left += p_p.GetX();
338 m_top += p_p.GetY();
339 m_right += p_p.GetX();
340 m_bottom += p_p.GetY();
341 }
342
347 void operator-=(const MxPoint<T>& p_p)
348 {
349 m_left -= p_p.GetX();
350 m_top -= p_p.GetY();
351 m_right -= p_p.GetX();
352 m_bottom -= p_p.GetY();
353 }
354
360 void operator&=(const MxRect& p_r)
361 {
362 m_left = Max(p_r.m_left, m_left);
363 m_top = Max(p_r.m_top, m_top);
364 m_right = Min(p_r.m_right, m_right);
366 }
367
373 void operator|=(const MxRect& p_r)
374 {
375 m_left = Min(p_r.m_left, m_left);
376 m_top = Min(p_r.m_top, m_top);
377 m_right = Max(p_r.m_right, m_right);
379 }
380
385 MxRect operator+(const MxPoint<T>& p_p) const
386 {
387 return MxRect(m_left + p_p.GetX(), m_top + p_p.GetY(), m_left + p_p.GetX(), m_bottom + p_p.GetY());
388 }
389
394 MxRect operator-(const MxPoint<T>& p_p) const
395 {
396 return MxRect(m_left - p_p.GetX(), m_top - p_p.GetY(), m_left - p_p.GetX(), m_bottom - p_p.GetY());
397 }
398
403 MxRect operator&(const MxRect& p_r) const
404 {
405 return MxRect(
406 Max(p_r.m_left, m_left),
407 Max(p_r.m_top, m_top),
408 Min(p_r.m_right, m_right),
409 Min(p_r.m_bottom, m_bottom)
410 );
411 }
412
417 MxRect operator|(const MxRect& p_r) const
418 {
419 return MxRect(
420 Min(p_r.m_left, m_left),
421 Min(p_r.m_top, m_top),
422 Max(p_r.m_right, m_right),
423 Max(p_r.m_bottom, m_bottom)
424 );
425 }
426};
427
428/******************************* MxPoint16 **********************************/
429
434class MxPoint16 : public MxPoint<MxS16> {
435public:
440
445 MxPoint16(const MxPoint16& p_p) : MxPoint<MxS16>(p_p) {}
446
452 MxPoint16(MxS16 p_x, MxS16 p_y) : MxPoint<MxS16>(p_x, p_y) {}
453};
454
459class MxPoint16List : public MxPtrList<MxPoint16> {
460public:
465 MxPoint16List(MxBool p_ownership) : MxPtrList<MxPoint16>(p_ownership) {}
466};
467
472class MxPoint16ListCursor : public MxPtrListCursor<MxPoint16> {
473public:
479};
480
481/******************************* MxPoint32 **********************************/
482
487class MxPoint32 : public MxPoint<MxS32> {
488public:
493
498 MxPoint32(const MxPoint32& p_p) : MxPoint<MxS32>(p_p) {}
499
505 MxPoint32(MxS32 p_x, MxS32 p_y) : MxPoint<MxS32>(p_x, p_y) {}
506};
507
512class MxPoint32List : public MxPtrList<MxPoint32> {
513public:
518 MxPoint32List(MxBool p_ownership) : MxPtrList<MxPoint32>(p_ownership) {}
519};
520
525class MxPoint32ListCursor : public MxPtrListCursor<MxPoint32> {
526public:
532};
533
534/******************************** MxSize16 **********************************/
535
540class MxSize16 : public MxSize<MxS16> {
541public:
546
551 MxSize16(const MxSize16& p_s) : MxSize<MxS16>(p_s) {}
552
558 MxSize16(MxS16 p_width, MxS16 p_height) : MxSize<MxS16>(p_width, p_height) {}
559};
560
565class MxSize16List : public MxPtrList<MxSize16> {
566public:
571 MxSize16List(MxBool p_ownership) : MxPtrList<MxSize16>(p_ownership) {}
572};
573
578class MxSize16ListCursor : public MxPtrListCursor<MxSize16> {
579public:
585};
586
587/******************************** MxSize32 **********************************/
588
593class MxSize32 : public MxSize<MxS32> {
594public:
599
604 MxSize32(const MxSize32& p_s) : MxSize<MxS32>(p_s) {}
605
611 MxSize32(MxS32 p_width, MxS32 p_height) : MxSize<MxS32>(p_width, p_height) {}
612};
613
618class MxSize32List : public MxPtrList<MxSize32> {
619public:
624 MxSize32List(MxBool p_ownership) : MxPtrList<MxSize32>(p_ownership) {}
625};
626
631class MxSize32ListCursor : public MxPtrListCursor<MxSize32> {
632public:
638};
639
640/******************************** MxRect16 **********************************/
641
646class MxRect16 : public MxRect<MxS16> {
647public:
652
657 MxRect16(const MxRect16& p_r) : MxRect<MxS16>(p_r) {}
658
666 MxRect16(MxS16 p_l, MxS16 p_t, MxS16 p_r, MxS16 p_b) : MxRect<MxS16>(p_l, p_t, p_r, p_b) {}
667
673 MxRect16(MxPoint16& p_p, MxSize16& p_s) : MxRect<MxS16>(p_p, p_s) {}
674};
675
679class MxRect16List : public MxPtrList<MxRect16> {
680public:
685 MxRect16List(MxBool p_ownership) : MxPtrList<MxRect16>(p_ownership) {}
686};
687
691class MxRect16ListCursor : public MxPtrListCursor<MxRect16> {
692public:
698};
699
700/******************************** MxRect32 **********************************/
701
706class MxRect32 : public MxRect<MxS32> {
707public:
712
717 MxRect32(const MxRect32& p_r) : MxRect<MxS32>(p_r) {}
718
726 MxRect32(MxS32 p_l, MxS32 p_t, MxS32 p_r, MxS32 p_b) : MxRect<MxS32>(p_l, p_t, p_r, p_b) {}
727
728#ifndef COMPAT_MODE
734 MxRect32(MxPoint32& p_p, MxSize32& p_s) : MxRect<MxS32>(p_p, p_s) {}
735#else
741 MxRect32(const MxPoint32& p_p, const MxSize32& p_s) : MxRect<MxS32>(p_p, p_s) {}
742#endif
743};
744
749class MxRect32List : public MxPtrList<MxRect32> {
750public:
755 MxRect32List(MxBool p_ownership) : MxPtrList<MxRect32>(p_ownership) {}
756};
757
761class MxRect32ListCursor : public MxPtrListCursor<MxRect32> {
762public:
768};
769
770#endif // MXGEOMETRY_H
[AI] Cursor for iterating MxPoint16List.
Definition: mxgeometry.h:472
MxPoint16ListCursor(MxPoint16List *p_list)
[AI] Construct for a given list.
Definition: mxgeometry.h:478
[AI] List class for pointers to MxPoint16.
Definition: mxgeometry.h:459
MxPoint16List(MxBool p_ownership)
[AI] Construct with ownership flag.
Definition: mxgeometry.h:465
[AI] 2D point with 16-bit signed integer coordinates.
Definition: mxgeometry.h:434
MxPoint16()
[AI] Default constructor.
Definition: mxgeometry.h:439
MxPoint16(const MxPoint16 &p_p)
[AI] Copy constructor.
Definition: mxgeometry.h:445
MxPoint16(MxS16 p_x, MxS16 p_y)
[AI] Constructor with explicit coordinates.
Definition: mxgeometry.h:452
[AI] Cursor for iterating MxPoint32List.
Definition: mxgeometry.h:525
MxPoint32ListCursor(MxPoint32List *p_list)
[AI] Construct for a given list.
Definition: mxgeometry.h:531
[AI] List class for pointers to MxPoint32.
Definition: mxgeometry.h:512
MxPoint32List(MxBool p_ownership)
[AI] Construct with ownership flag.
Definition: mxgeometry.h:518
[AI] 2D point with 32-bit signed integer coordinates.
Definition: mxgeometry.h:487
MxPoint32(const MxPoint32 &p_p)
[AI] Copy constructor.
Definition: mxgeometry.h:498
MxPoint32()
[AI] Default constructor.
Definition: mxgeometry.h:492
MxPoint32(MxS32 p_x, MxS32 p_y)
[AI] Constructor with explicit coordinates.
Definition: mxgeometry.h:505
[AI] 2D point class templated on its coordinate type.
Definition: mxgeometry.h:13
MxPoint()
[AI] Default constructor, does not initialize coordinates.
Definition: mxgeometry.h:22
void SetY(T p_y)
[AI] Set Y coordinate.
Definition: mxgeometry.h:65
MxPoint(const MxPoint &p_p)
[AI] Copy constructor.
Definition: mxgeometry.h:28
T m_x
[AI] X coordinate.
Definition: mxgeometry.h:15
MxPoint(T p_x, T p_y)
[AI] Constructor with explicit coordinates.
Definition: mxgeometry.h:39
MxPoint operator+(const MxPoint &p_p) const
[AI] Add another point, returning the result.
Definition: mxgeometry.h:91
T GetY() const
[AI] Get Y coordinate.
Definition: mxgeometry.h:53
MxPoint operator-(const MxPoint &p_p) const
[AI] Subtract another point, returning the result.
Definition: mxgeometry.h:97
void SetX(T p_x)
[AI] Set X coordinate.
Definition: mxgeometry.h:59
T GetX() const
[AI] Get X coordinate.
Definition: mxgeometry.h:48
void operator-=(const MxPoint &p_p)
[AI] Subtract another point's coordinates from this point.
Definition: mxgeometry.h:81
T m_y
[AI] Y coordinate.
Definition: mxgeometry.h:16
void operator+=(const MxPoint &p_p)
[AI] Add another point's coordinates to this point.
Definition: mxgeometry.h:71
[AI]
Definition: mxlist.h:148
[AI] Cursor for iterating lists of MxRect16 pointers.
Definition: mxgeometry.h:691
MxRect16ListCursor(MxRect16List *p_list)
[AI] Construct for a given list.
Definition: mxgeometry.h:697
[AI] List for pointers to MxRect16 rectangles.
Definition: mxgeometry.h:679
MxRect16List(MxBool p_ownership)
[AI] Construct with ownership flag.
Definition: mxgeometry.h:685
[AI] Rectangle using 16-bit signed integer coordinates.
Definition: mxgeometry.h:646
MxRect16(const MxRect16 &p_r)
[AI] Copy constructor.
Definition: mxgeometry.h:657
MxRect16(MxS16 p_l, MxS16 p_t, MxS16 p_r, MxS16 p_b)
[AI] Constructor from coordinates.
Definition: mxgeometry.h:666
MxRect16(MxPoint16 &p_p, MxSize16 &p_s)
[AI] Construct a rectangle from point and size.
Definition: mxgeometry.h:673
MxRect16()
[AI] Default constructor.
Definition: mxgeometry.h:651
[AI] Cursor for iterating lists of MxRect32 pointers.
Definition: mxgeometry.h:761
MxRect32ListCursor(MxRect32List *p_list)
[AI] Construct for a given list.
Definition: mxgeometry.h:767
[AI] List for pointers to MxRect32 rectangles.
Definition: mxgeometry.h:749
MxRect32List(MxBool p_ownership)
[AI] Construct with ownership.
Definition: mxgeometry.h:755
[AI] Rectangle using 32-bit signed integer coordinates.
Definition: mxgeometry.h:706
MxRect32(MxPoint32 &p_p, MxSize32 &p_s)
[AI] Construct using MxPoint32 and MxSize32.
Definition: mxgeometry.h:734
MxRect32()
[AI] Default constructor.
Definition: mxgeometry.h:711
MxRect32(MxS32 p_l, MxS32 p_t, MxS32 p_r, MxS32 p_b)
[AI] Construct from explicit coordinates.
Definition: mxgeometry.h:726
MxRect32(const MxRect32 &p_r)
[AI] Copy constructor.
Definition: mxgeometry.h:717
[AI] 2D rectangle class templated on its value type.
Definition: mxgeometry.h:165
void SetLeft(T p_left)
[AI] Set the left edge.
Definition: mxgeometry.h:226
MxBool Empty() const
[AI] Returns whether the rectangle is empty or not.
Definition: mxgeometry.h:284
MxRect()
[AI] Default constructor, does not initialize rectangle.
Definition: mxgeometry.h:176
MxRect operator&(const MxRect &p_r) const
[AI] Returns the intersection of this rectangle and another.
Definition: mxgeometry.h:403
T GetTop() const
[AI] Get the top edge.
Definition: mxgeometry.h:231
MxBool operator==(const MxRect &p_r) const
[AI] Equality operator.
Definition: mxgeometry.h:320
MxBool Contains(const MxPoint< T > &p_p) const
[AI] Test whether a point is inside the rectangle (inclusive).
Definition: mxgeometry.h:290
void operator+=(const MxPoint< T > &p_p)
[AI] Translate the rectangle by a point, in-place.
Definition: mxgeometry.h:335
MxBool Intersects(const MxRect &p_r) const
[AI] Returns whether this rectangle intersects another.
Definition: mxgeometry.h:299
MxBool operator!=(const MxRect &p_r) const
[AI] Inequality operator.
Definition: mxgeometry.h:329
void operator=(const MxRect &p_r)
[AI] Assignment operator.
Definition: mxgeometry.h:308
T GetWidth() const
[AI] Get the rectangle's width.
Definition: mxgeometry.h:262
MxRect(const MxRect &p_r)
[AI] Copy constructor.
Definition: mxgeometry.h:182
void SetBottom(T p_bottom)
[AI] Set the bottom edge.
Definition: mxgeometry.h:256
void operator|=(const MxRect &p_r)
[AI] Unites this rectangle with another in-place.
Definition: mxgeometry.h:373
MxRect operator-(const MxPoint< T > &p_p) const
[AI] Returns a translated rectangle (by negative).
Definition: mxgeometry.h:394
MxPoint< T > GetRB() const
[AI] Get the bottom-right point of the rectangle.
Definition: mxgeometry.h:278
T GetRight() const
[AI] Get the right edge.
Definition: mxgeometry.h:241
void operator-=(const MxPoint< T > &p_p)
[AI] Translate the rectangle by the negative of a point, in-place.
Definition: mxgeometry.h:347
T GetHeight() const
[AI] Get the rectangle's height.
Definition: mxgeometry.h:268
MxRect(const MxPoint< T > &p_p, const MxSize< T > &p_s)
[AI] Construct from point and size.
Definition: mxgeometry.h:210
MxRect(T p_l, T p_t, T p_r, T p_b)
[AI] Construct from coordinates.
Definition: mxgeometry.h:197
T GetLeft() const
[AI] Get the left edge.
Definition: mxgeometry.h:221
void SetTop(T p_top)
[AI] Set the top edge.
Definition: mxgeometry.h:236
MxRect operator+(const MxPoint< T > &p_p) const
[AI] Returns a translated rectangle.
Definition: mxgeometry.h:385
T m_right
[AI] Right edge (maximum x).
Definition: mxgeometry.h:169
T GetBottom() const
[AI] Get the bottom edge.
Definition: mxgeometry.h:251
T m_left
[AI] Left edge (minimum x).
Definition: mxgeometry.h:167
T m_bottom
[AI] Bottom edge (maximum y).
Definition: mxgeometry.h:170
void operator&=(const MxRect &p_r)
[AI] Intersect rectangle in-place with another.
Definition: mxgeometry.h:360
MxPoint< T > GetLT() const
[AI] Get the top-left point of the rectangle.
Definition: mxgeometry.h:273
void SetRight(T p_right)
[AI] Set the right edge.
Definition: mxgeometry.h:246
MxRect operator|(const MxRect &p_r) const
[AI] Returns the bounding rectangle (union) of this and another.
Definition: mxgeometry.h:417
T m_top
[AI] Top edge (minimum y).
Definition: mxgeometry.h:168
[AI] Cursor for iterating MxSize16List.
Definition: mxgeometry.h:578
MxSize16ListCursor(MxSize16List *p_list)
[AI] Construct for a given list.
Definition: mxgeometry.h:584
[AI] List class for pointers to MxSize16.
Definition: mxgeometry.h:565
MxSize16List(MxBool p_ownership)
[AI] Construct with ownership flag.
Definition: mxgeometry.h:571
[AI] Size with 16-bit signed integer width and height.
Definition: mxgeometry.h:540
MxSize16(MxS16 p_width, MxS16 p_height)
[AI] Constructor with specified width and height.
Definition: mxgeometry.h:558
MxSize16(const MxSize16 &p_s)
[AI] Copy constructor.
Definition: mxgeometry.h:551
MxSize16()
[AI] Default constructor.
Definition: mxgeometry.h:545
[AI] Cursor for iterating MxSize32List.
Definition: mxgeometry.h:631
MxSize32ListCursor(MxSize32List *p_list)
[AI] Construct for a given list.
Definition: mxgeometry.h:637
[AI] List class for pointers to MxSize32.
Definition: mxgeometry.h:618
MxSize32List(MxBool p_ownership)
[AI] Construct with ownership flag.
Definition: mxgeometry.h:624
[AI] Size with 32-bit signed integer width and height.
Definition: mxgeometry.h:593
MxSize32(const MxSize32 &p_s)
[AI] Copy constructor.
Definition: mxgeometry.h:604
MxSize32(MxS32 p_width, MxS32 p_height)
[AI] Constructor with specified width and height.
Definition: mxgeometry.h:611
MxSize32()
[AI] Default constructor.
Definition: mxgeometry.h:598
[AI] 2D size class templated on its value type.
Definition: mxgeometry.h:106
void SetHeight(T p_height)
[AI] Set the height.
Definition: mxgeometry.h:156
MxSize()
[AI] Default constructor, does not initialize size.
Definition: mxgeometry.h:115
void SetWidth(T p_width)
[AI] Set the width.
Definition: mxgeometry.h:150
T GetHeight() const
[AI] Get the height.
Definition: mxgeometry.h:144
T m_height
[AI] Height.
Definition: mxgeometry.h:109
T GetWidth() const
[AI] Get the width.
Definition: mxgeometry.h:139
T m_width
[AI] Width.
Definition: mxgeometry.h:108
MxSize(T p_width, T p_height)
[AI] Constructor with explicit width and height.
Definition: mxgeometry.h:131
MxSize(const MxSize &p_s)
[AI] Copy constructor.
Definition: mxgeometry.h:121
T Max(T p_t1, T p_t2)
[AI] Returns the maximum of two values.
Definition: legoutil.h:39
T Min(T p_t1, T p_t2)
[AI] Returns the minimum of two values.
Definition: legoutil.h:14
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
signed short MxS16
[AI]
Definition: mxtypes.h:26
signed int MxS32
[AI]
Definition: mxtypes.h:38