OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Classes for window system geometry
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_GEOMETRY_H)
10#define OWL_GEOMETRY_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17
18#if !defined(UNIX)
19#if !defined(OWL_OBJSTRM_H)
20# include <owl/objstrm.h> // Need persist streaming classes & operators
21#endif
22#endif
23
25
26#include <algorithm>
27
28namespace owl {
29
30//
31// Forward declare some of the classes defined in this file
32//
33class _OWLCLASS TSize;
34class _OWLCLASS TRect;
35
36//
37// Integer square root for area calculations. Is fairly fast.
38//
41
42} // OWL namespace
43
44//
45// Get base window system geometry structs compatible with MSW
46//
47#include <owl/wsysinc.h>
48
49namespace owl {
50
51#include <owl/preclass.h>
52
53/// \addtogroup graphics
54/// @{
55
56/// General use absolute 2-D rectangular location enum
57//
58/// TAbsLocation contains general-use absolute two-dimensional rectangular
59/// locations. It is used primarily to describe the locations of a gadget window,
60/// such as a toolbar or a status bar, within a decorated frame.
61//
63 alNone = 0, ///< No location specified
64 alTop = 1, ///< Refers to top edge of frame
65 alBottom = 2, ///< Refers to bottom edge of frame
66 alLeft = 3, ///< Refers to left edge of frame
67 alRight = 4, ///< Refers to right edge of frame
68};
69
70//
71/// \class TPoint
72// ~~~~~ ~~~~~~
73/// TPoint is a support class, derived from tagPOINT. The tagPOINT struct is defined
74/// as
75/// \code
76/// struct tagPOINT {
77/// int x;
78/// int y;
79/// };
80/// \endcode
81/// TPoint encapsulates the notion of a two-dimensional point that usually
82/// represents a screen position. TPoint inherits two data members, the coordinates
83/// x and y, from tagPOINT. Member functions and operators are provided for
84/// comparing, assigning, and manipulating points. Overloaded << and >> operators
85/// allow chained insertion and extraction of TPoint objects with streams.
86//
87class _OWLCLASS TPoint : public tagPOINT {
88 public:
89 // Constructors
90 //
91 TPoint();
92 TPoint(int _x, int _y);
93 TPoint(const tagPOINT & point);
94 TPoint(const TPoint & point);
95 TPoint(const tagSIZE & size);
96 explicit TPoint(LPARAM packedPoint);
97
98 // Information functions/operators
99 //
100 bool operator ==(const TPoint& other) const;
101 bool operator !=(const TPoint& other) const;
102 int X() const;
103 int Y() const;
104 int Magnitude() const;
105
106 // Functions/binary-operators that return points or sizes
107 //
108 TPoint OffsetBy(int dx, int dy) const;
109 TPoint operator +(const TSize& size) const;
110 TSize operator -(const TPoint& point) const;
111 TPoint operator -(const TSize& size) const;
112 TPoint operator -() const;
113
114 // Functions/assignement-operators that modify this point
115 //
116 TPoint& Offset(int dx, int dy);
117 TPoint& operator +=(const TSize& size);
118 TPoint& operator -=(const TSize& size);
119};
120
125
126//
127/// \class TPointL
128// ~~~~~ ~~~~~~~
129/// TPointL is similar to TPoint, but uses long rather than int variables.
130/// \todo Do we really need this? Isn't long same as int for 32-bit? What about 64-bit
131//
132class _OWLCLASS TPointL : public POINTL {
133 public:
134 // Constructors
135 //
136 TPointL();
137 TPointL(long _x, long _y);
138 TPointL(const POINTL & point);
139 TPointL(const TPointL & point);
140
141 // Information functions/operators
142 //
143 bool operator ==(const TPointL& other) const;
144 bool operator !=(const TPointL& other) const;
145 long X() const;
146 long Y() const;
147
148 // Functions/binary-operators that return points or sizes
149 //
150 TPointL OffsetBy(long dx, long dy) const;
151 TPointL operator +(const TSize& size) const;
152 TPointL operator -(const TPointL& point) const;
153 TPointL operator -(const TSize& size) const;
154 TPointL operator -() const;
155
156 // Functions/assignement-operators that modify this point
157 //
158 TPointL& Offset(long dx, long dy);
159 TPointL& operator +=(const TSize& size);
160 TPointL& operator -=(const TSize& size);
161};
162
167
168//
169/// Base struct for the TPointF class
170//
171struct tPOINTF {
172 float x;
173 float y;
174};
175
176//
177/// \class TPointF
178// ~~~~~ ~~~~~~~
179/// TPointF is similar to TPoint, but uses floating variables rather than integers.
180//
181class _OWLCLASS TPointF : public tPOINTF {
182 public:
183 // Constructors
184 //
185 TPointF();
186 TPointF(float _x, float _y);
187// TPointF(const tagPOINTF & point) {x = point.x; y = point.y;}
188 TPointF(const TPointF & point);
189
190 // Information functions/operators
191 //
192 bool operator ==(const TPointF& other) const;
193 bool operator !=(const TPointF& other) const;
194 float X() const;
195 float Y() const;
196
197 // Functions/binary-operators that return points or sizes
198 //
199 TPointF OffsetBy(float dx, float dy) const;
200 TPointF operator +(const TPointF& size) const;
201 TPointF operator -(const TPointF& point) const;
202 TPointF operator -() const;
203
204 // Functions/assignement-operators that modify this point
205 //
206 TPointF& Offset(float dx, float dy);
207 TPointF& operator +=(const TPointF& size);
208 TPointF& operator -=(const TPointF& size);
209};
210
215
216//
217/// \class TSize
218// ~~~~~ ~~~~~
219/// The tagSIZE struct is defined as
220/// \code
221/// struct tagSIZE {
222/// int cx;
223/// int cy;
224/// };
225/// \endcode
226/// TSize encapsulates the notion of a two-dimensional quantity that usually
227/// represents a displacement or the height and width of a rectangle. TSize inherits
228/// the two data members cx and cy from tagSIZE. Member functions and operators are
229/// provided for comparing, assigning, and manipulating sizes. Overloaded << and >>
230/// operators allow chained insertion and extraction of TSize objects with streams.
231//
232// !CQ look at phasing out this class & using only TPoint
233//
234class _OWLCLASS TSize : public tagSIZE {
235 public:
236 // Constructors
237 //
238 TSize();
239 TSize(int dx, int dy);
240 TSize(const tagPOINT & point);
241 TSize(const tagSIZE & size);
242 TSize(const TSize & size);
243 explicit TSize(DWORD packedExtents);
244
245 // Information functions/operators
246 //
247 bool operator ==(const TSize& other) const;
248 bool operator !=(const TSize& other) const;
249 int X() const;
250 int Y() const;
251 int Magnitude() const;
252
253 // Functions/binary-operators that return sizes
254 //
255 TSize operator +(const TSize& size) const;
256 TSize operator -(const TSize& size) const;
257 TSize operator -() const;
258
259 // Functions/assignement-operators that modify this size
260 //
261 TSize& operator +=(const TSize& size);
262 TSize& operator -=(const TSize& size);
263};
264
269
270//
271/// \class TRect
272// ~~~~~ ~~~~~
273/// TRect is a mathematical class derived from tagRect. The tagRect struct is
274/// defined as
275/// \code
276/// struct tagRECT {
277/// int left;
278/// int top;
279/// int right;
280/// int bottom;
281/// };
282/// \endcode
283/// TRect encapsulates the properties of rectangles with sides parallel to the x-
284/// and y-axes. In ObjectWindows, these rectangles define the boundaries of windows,
285/// boxes, and clipping regions. TRect inherits four data members from tagRect left,
286/// top, right, and bottom. These represent the top left and bottom right (x, y)
287/// coordinates of the rectangle. Note that x increases from left to right, and y
288/// increases from top to bottom.
289///
290/// TRect places no restrictions on the relative positions of top left and bottom
291/// right, so it is legal to have left > right and top > bottom. However, many
292/// manipulations--such as determining width and height, and forming unions and
293/// intersections--are simplified by normalizing the TRect objects involved.
294/// Normalizing a rectangle means interchanging the corner point coordinate values
295/// so that left < right and top < bottom. Normalization does not alter the physical
296/// properties of a rectangle. myRect.Normalized creates normalized copy of myRect
297/// without changing myRect, while myRect.Normalize changes myRect to a normalized
298/// format. Both members return the normalized rectangle.
299///
300/// TRect constructors are provided to create rectangles from either four ints, two
301/// TPoint objects, or one TPoint and one TSize object. In the latter case, the
302/// TPoint object specifies the top left point (also known as the rectangle's
303/// origin) and the TSize object supplies the width and height of the rectangle.
304/// Member functions perform a variety of rectangle tests and manipulations.
305/// Overloaded << and >> operators allow chained insertion and extraction of TRect
306/// objects with streams.
307//
308class _OWLCLASS TRect : public tagRECT {
309 public:
310 // Constructors
311 //
312 TRect();
313 TRect(const tagRECT & rect);
314 TRect(const TRect & rect);
315 TRect(int _left, int _top, int _right, int _bottom);
316 TRect(const TPoint& upLeft, const TPoint& loRight);
317 TRect(const TPoint& origin, const TSize& extent);
318
319 // (Re)Initializers
320 //
321 void SetNull();
322 void SetEmpty();
323 void Set(int _left, int _top, int _right, int _bottom);
324 void SetWH(int _left, int _top, int w, int h);
325
326 // Type Conversion operators
327 //
328 operator const TPoint*() const;
329 operator TPoint*();
330
331 // Testing functions
332 //
333 bool IsEmpty() const;
334 bool IsNull() const;
335 bool operator ==(const TRect& other) const;
336 bool operator !=(const TRect& other) const;
337
338 // Information/access functions (const and non-const)
339 //
340 int Left() const;
341 int X() const;
342 int Top() const;
343 int Y() const;
344 int Right() const;
345 int Bottom() const;
346
347 const TPoint& TopLeft() const;
348 TPoint& TopLeft();
349 TPoint TopRight() const;
350 TPoint BottomLeft() const;
351 const TPoint& BottomRight() const;
352 TPoint& BottomRight();
353
354 int Width() const;
355 int Height() const;
356 TSize Size() const;
357 long Area() const;
358
359 bool Contains(const TPoint& point) const;
360 bool Contains(const TRect& other) const;
361 bool Touches(const TRect& other) const;
362 TRect OffsetBy(int dx, int dy) const;
363 TRect operator +(const TSize& size) const;
364 TRect operator -(const TSize& size) const;
365 TRect MovedTo(int x, int y);
366 TRect InflatedBy(int dx, int dy) const;
367 TRect InflatedBy(const TSize& size) const;
368 TRect Normalized() const;
369 TRect operator &(const TRect& other) const;
370 TRect operator |(const TRect& other) const;
371
372 int Subtract(const TRect& other, TRect result[]) const;
373
374 // Manipulation functions/operators
375 //
376 TRect& Normalize();
377 TRect& Offset(int dx, int dy);
378 TRect& operator +=(const TSize& delta);
379 TRect& operator -=(const TSize& delta);
380 TRect& MoveTo(int x, int y);
381 TRect& Inflate(int dx, int dy);
382 TRect& DeflateRect(int dx, int dy); //DLN MFC look-alike
383 TRect& Inflate(const TSize& delta);
384 TRect& DeflateRect(const TSize& delta); //DLN MFC look-alike
385 TRect& operator &=(const TRect& other);
386 TRect& operator |=(const TRect& other);
387};
388
393
394/// @}
395
396#include <owl/posclass.h>
397
398//----------------------------------------------------------------------------
399// Inlines
400//
401
402//----------------------------------------------------------------------------
403// TPoint
404//
405
406
407
408
409//
410/// Constructs an uninitialized point.
411//
412inline
414{
415 x = 0;
416 y = 0;
417}
418
419//
420/// Creates a TPoint object with the given coordinates.
421//
422inline
424{
425 x = _x;
426 y = _y;
427}
428
429//
430/// Creates a TPoint object with x = point.x, y = point.y.
431//
432inline
433TPoint::TPoint(const tagPOINT & point)
434{
435 x = point.x;
436 y = point.y;
437}
438
439//
440/// Makes a copy of the point.
441//
442inline
444{
445 x = point.x;
446 y = point.y;
447}
448
449//
450/// Creates a TPoint object with x = size.cx and y = size.cy.
451//
452inline
453TPoint::TPoint(const tagSIZE & size)
454{
455 x = size.cx;
456 y = size.cy;
457}
458
459//
460/// Returns the x coordinate of the point.
461//
462inline int
464{
465 return x;
466}
467
468//
469/// Returns the Y coordinate of the point.
470//
471inline int
473{
474 return y;
475}
476
477//
478/// Calculates an offset to this point using the given displacement arguments.
479/// Returns the point (x + dx, y + dy). This point is not changed.
480//
481inline TPoint
482TPoint::OffsetBy(int dx, int dy) const
483{
484 return TPoint(x + dx, y + dy);
485}
486
487//
488/// Returns the point (-x, -y). This point is not changed.
489//
490inline TPoint
492{
493 return TPoint(-x, -y);
494}
495
496//
497/// Returns true if this point is equal to the other point; otherwise returns false.
498//
499inline bool
501{
502 return ToBool(other.x == x && other.y == y);
503}
504
505//
506/// Returns false if this point is equal to the other point; otherwise returns true.
507//
508inline bool
510{
511 return ToBool(other.x != x || other.y != y);
512}
513
514//
515/// Calculates an offset to this point using the given size argument as the
516/// displacement. Returns the point (x + size.cx, y + size.cy). This point is not
517/// changed.
518//
519inline TPoint
520TPoint::operator +(const TSize& size) const
521{
522 return TPoint(x + size.cx, y + size.cy);
523}
524
525//
526/// Calculates a distance from this point to the point argument. Returns the TSize
527/// object (x - point.x, y - point.y). This point is not changed.
528//
529inline TSize
531{
532 return TSize(x - point.x, y - point.y);
533}
534
535//
536/// Calculates a negative offset to this point using the given size argument as the
537/// displacement. Returns the point (x - size.cx, y - size.cy). This point is not
538/// changed.
539//
540inline TPoint
541TPoint::operator -(const TSize& size) const
542{
543 return TPoint(x - size.cx, y - size.cy);
544}
545
546//
547/// Offsets this point by the given delta arguments. This point is changed to (x +
548/// dx, y + dy). Returns a reference to this point.
549//
550inline TPoint&
552{
553 x += dx;
554 y += dy;
555 return *this;
556}
557
558//
559/// Offsets this point by the given size argument. This point is changed to(x +
560/// size.cx, y + size.cy). Returns a reference to this point.
561//
562inline TPoint&
564{
565 x += size.cx;
566 y += size.cy;
567 return *this;
568}
569
570//
571/// Negatively offsets this point by the given size argument. This point is changed
572/// to (x - size.cx, y - size.cy). Returns a reference to this point.
573//
574inline TPoint&
576{
577 x -= size.cx;
578 y -= size.cy;
579 return *this;
580}
581
582//----------------------------------------------------------------------------
583// TPointL
584//
585
586//
587/// Default constructor that does nothing.
588//
589inline
591{
592 x = 0;
593 y = 0;
594}
595
596//
597/// Constructs the point to a specific location.
598//
599inline
601{
602 x = _x;
603 y = _y;
604}
605
606//
607/// Alias constructor that initializes from an existing point.
608//
609inline
610TPointL::TPointL(const POINTL & point)
611{
612 x = point.x;
613 y = point.y;
614}
615
616//
617/// Copy constructor. Makes a copy of the location.
618//
619inline
621{
622 x = point.x;
623 y = point.y;
624}
625
626//
627/// Returns the X component of the point.
628//
629inline long
631{
632 return x;
633}
634
635//
636/// Returns the Y component of the point.
637//
638inline long
640{
641 return y;
642}
643
644//
645/// Returns the new point (x+dx, y+dy). Creates a new point shifted by the offset,
646/// preserving the original point.
647//
648inline TPointL
649TPointL::OffsetBy(long dx, long dy) const
650{
651 return TPointL(x + dx, y + dy);
652}
653
654//
655/// Returns the negative of the point.
656//
657inline TPointL
659{
660 return TPointL(-x, -y);
661}
662
663//
664/// Returns true if positions are the same.
665//
666inline bool
668{
669 return ToBool(other.x == x && other.y == y);
670}
671
672//
673/// Returns true if the positions are not the same.
674//
675inline bool
677{
678 return ToBool(other.x != x || other.y != y);
679}
680
681//
682/// Returns the new point (x+cx, y+cy).
683//
684inline TPointL
685TPointL::operator +(const TSize& size) const
686{
687 return TPointL(x + size.cx, y + size.cy);
688}
689
690//
691/// Returns the difference between the two points.
692//
693inline TPointL
695{
696 return TPointL(x - point.x, y - point.y);
697}
698
699//
700/// Return the new point (x-cx, y-cy).
701//
702inline TPointL
703TPointL::operator -(const TSize& size) const
704{
705 return TPointL(x - size.cx, y - size.cy);
706}
707
708//
709/// Returns the point (x+dx, y+dy), shifting the point by the offset.
710//
711inline TPointL&
713{
714 x += dx;
715 y += dy;
716 return *this;
717}
718
719//
720/// Return the point (x+cx, y+cy).
721//
722inline TPointL&
724{
725 x += size.cx;
726 y += size.cy;
727 return *this;
728}
729
730//
731/// Return the point (x-cx, y-cy).
732//
733inline TPointL&
735{
736 x -= size.cx;
737 y -= size.cy;
738 return *this;
739}
740
741
742//----------------------------------------------------------------------------
743// TPointF
744//
745
746//
747/// Default constructor that does nothing.
748//
749inline
751{
752 x = 0.0f;
753 y = 0.0f;
754}
755
756//
757/// Constructor that initializes the location.
758//
759inline
760TPointF::TPointF(float _x, float _y)
761{
762 x = _x;
763 y = _y;
764}
765
766//
767/// Constructor that copies the location.
768//
769inline
771{
772 x = point.x;
773 y = point.y;
774}
775
776//
777/// Returns X component of the point.
778//
779inline float
781{
782 return x;
783}
784
785//
786/// Returns Y component of the point.
787//
788inline float
790{
791 return y;
792}
793
794//
795/// Moves the point by an offset.
796//
797inline TPointF
798TPointF::OffsetBy(float dx, float dy) const
799{
800 return TPointF(x + dx, y + dy);
801}
802
803//
804/// Returns the negative of the point.
805//
806inline TPointF
808{
809 return TPointF(-x, -y);
810}
811
812//
813/// Returns true if the points are at the same location.
814//
815inline bool
817{
818 return ToBool(other.x == x && other.y == y);
819}
820
821//
822/// Return true if the points are not at the same location.
823//
824inline bool
826{
827 return ToBool(other.x != x || other.y != y);
828}
829
830//
831/// Returns a new point (x+cx, y+cy).
832//
833inline TPointF
834TPointF::operator +(const TPointF& size) const
835{
836 return TPointF(x + size.x, y + size.y);
837}
838
839//
840/// Returns a new point subtracted from the current point.
841//
842inline TPointF
844{
845 return TPointF(x - point.x, y - point.y);
846}
847
848//
849/// Moves the point by an offset.
850//
851inline TPointF&
852TPointF::Offset(float dx, float dy)
853{
854 x += dx;
855 y += dy;
856 return *this;
857}
858
859//
860/// Returns the new point moved by the offset.
861//
862inline TPointF&
864{
865 x += size.x;
866 y += size.y;
867 return *this;
868}
869
870//
871/// Returns the new point subtracted from the current.
872//
873inline TPointF&
875{
876 x -= size.x;
877 y -= size.y;
878 return *this;
879}
880
881//----------------------------------------------------------------------------
882// TRect
883//
884
885//
886/// Default constructor that does nothing.
887//
888inline
890{
891 SetNull();
892}
893
894//
895/// Empties this rectangle by setting left, top, right, and bottom to 0.
896//
897inline void
899{
900 SetNull();
901}
902
903//
904/// Type conversion operators converting the pointer to this rectangle to type
905/// pointer to TPoint.
906/// Return an array of two points (upperleft and bottomright)
907//
908inline
909TRect::operator const TPoint*() const
910{
911 return (const TPoint*)this;
912}
913
914//
915/// Type conversion operators converting the pointer to this rectangle to type
916/// pointer to TPoint.
917/// Return an array of two points (upperleft and bottomright)
918//
919inline
920TRect::operator TPoint*()
921{
922 return (TPoint*)this;
923}
924
925//
926/// Returns the left value.
927//
928inline int
930{
931 return left;
932}
933
934//
935/// Returns the left value.
936//
937inline int
938TRect::X() const
939{
940 return left;
941}
942
943//
944/// Returns the top value.
945//
946inline int
948{
949 return top;
950}
951
952//
953/// Returns the top value.
954//
955inline int
956TRect::Y() const
957{
958 return top;
959}
960
961//
962/// Returns the right value.
963//
964inline int
966{
967 return right;
968}
969
970//
971/// Returns the bottom value.
972//
973inline int
975{
976 return bottom;
977}
978
979//
980/// Returns the upperleft point.
981//
982inline const TPoint&
984{
985 return *(TPoint*)&left;
986}
987
988//
989/// Returns the upperleft point.
990//
991inline TPoint&
993{
994 return *(TPoint*)&left;
995}
996
997//
998/// Returns the upperright point.
999//
1000inline TPoint
1002{
1003 return TPoint(right, top);
1004}
1005
1006//
1007/// Returns the TPoint object representing the bottom left corner of this rectangle.
1008//
1009inline TPoint
1011{
1012 return TPoint(left, bottom);
1013}
1014
1015//
1016/// Returns the TPoint object representing the bottom right corner of this
1017/// rectangle.
1018//
1019inline const TPoint&
1021{
1022 return *(TPoint*)&right;
1023}
1024
1025//
1026/// Returns the TPoint object representing the bottom right corner of this
1027/// rectangle.
1028//
1029inline TPoint&
1031{
1032 return *(TPoint*)&right;
1033}
1034
1035//
1036/// Returns the width of this rectangle (right - left).
1037//
1038inline int
1040{
1041 return right-left;
1042}
1043
1044//
1045/// Returns the height of this rectangle (bottom - top).
1046//
1047inline int
1049{
1050 return bottom-top;
1051}
1052
1053//
1054/// Returns the size of rectangle.
1055//
1056inline TSize
1058{
1059 return TSize(Width(), Height());
1060}
1061
1062//
1063/// Returns the area of this rectangle.
1064//
1065inline long
1067{
1068 return long(Width())*long(Height());
1069}
1070
1071//
1072/// Sets the left, top, right, and bottom of the rectangle to 0.
1073//
1074inline void
1076{
1077 left = 0;
1078 top = 0;
1079 right = 0;
1080 bottom = 0;
1081}
1082
1083//
1084/// Repositions and resizes this rectangle to the given values.
1085//
1086inline void
1088{
1089 left = _left;
1090 top = _top;
1091 right = _right;
1092 bottom = _bottom;
1093}
1094
1095//
1096/// Determines the rectangle, given its upperleft point, width, and height
1097//
1098inline void
1099TRect::SetWH(int _left, int _top, int w, int h)
1100{
1101 left = _left;
1102 top = _top;
1103 right = _left + w;
1104 bottom = _top + h;
1105}
1106
1107//
1108/// Copy from an existing rectangle.
1109//
1110inline
1111TRect::TRect(const tagRECT & rect)
1112{
1113 *(tagRECT *)this = rect;
1114}
1115
1116//
1117/// Copy from an existing rectangle.
1118//
1119inline
1121{
1122 *(tagRECT *)this = *(tagRECT *)&rect;
1123}
1124
1125//
1126/// Constructor that sets all the values explicitly.
1127//
1128inline
1130{
1132}
1133
1134//
1135/// Creates a rectangle with the given top left and bottom right points.
1136//
1137inline
1142
1143//
1144/// Creates a rectangle with its origin (top left) at origin, width at extent.cx,
1145/// height at extent.cy.
1146//
1147inline
1149{
1150 Set(origin.x, origin.y, origin.x + extent.cx, origin.y + extent.cy);
1151}
1152
1153//
1154/// Returns true if left >= right or top >= bottom; otherwise, returns false.
1155//
1156inline bool
1158{
1159 return ToBool(left >= right || top >= bottom);
1160}
1161
1162//
1163/// Returns true if left, right, top, and bottom are all 0; otherwise, returns
1164/// false.
1165//
1166inline bool
1168{
1169 return ToBool(!left && !right && !top && !bottom);
1170}
1171
1172//
1173/// Returns true if this rectangle has identical corner coordinates to the other
1174/// rectangle; otherwise, returns false.
1175//
1176inline bool
1178{
1179 return ToBool(other.left==left && other.top==top
1180 && other.right==right && other.bottom==bottom);
1181}
1182
1183//
1184/// Returns false if this rectangle has identical corner coordinates to the other
1185/// rectangle; otherwise, returns true.
1186//
1187inline bool
1189{
1190 return ToBool(!(other==*this));
1191}
1192
1193//
1194/// Returns true if the given point lies within this rectangle; otherwise, it
1195/// returns false. If point is on the left vertical or on the top horizontal borders
1196/// of the rectangle, Contains also returns true, but if point is on the right
1197/// vertical or bottom horizontal borders, Contains returns false.
1198//
1199inline bool
1201{
1202 return ToBool(point.x >= left && point.x < right
1203 && point.y >= top && point.y < bottom);
1204}
1205
1206//
1207/// Returns true if the other rectangle lies on or within this rectangle; otherwise,
1208/// it returns false.
1209//
1210inline bool
1212{
1213 return ToBool(other.left >= left && other.right <= right
1214 && other.top >= top && other.bottom <= bottom);
1215}
1216
1217//
1218/// Returns true if the other rectangle shares any interior points with this
1219/// rectangle; otherwise, returns false.
1220//
1221inline bool
1223{
1224 return ToBool(other.right > left && other.left < right
1225 && other.bottom > top && other.top < bottom);
1226}
1227
1228//
1229/// Returns a rectangle with the corners offset by the given delta values. The
1230/// returned rectangle has a top left corner at (left + dx, top + dy) and a right
1231/// bottom corner at (right + dx, bottom + dy). The calling rectangle object is unchanged
1232//
1233inline TRect
1234TRect::OffsetBy(int dx, int dy) const
1235{
1236 return TRect(left+dx, top+dy, right+dx, bottom+dy);
1237}
1238
1239//
1240/// Returns a rectangle offset positively by the delta values' given sizes. The
1241/// returned rectangle has a top left corner at (left + size.x, top + size.y) and a
1242/// right bottom corner at (right + size.x, bottom + size.y). The calling rectangle
1243/// object is unchanged.
1244//
1245inline TRect
1246TRect::operator +(const TSize& size) const
1247{
1248 return OffsetBy(size.cx, size.cy);
1249}
1250
1251//
1252/// Returns a rectangle offset negatively by the delta values' given sizes. The
1253/// returned rectangle has a top left corner at (left - size.cx, top - size.cy) and
1254/// a right bottom corner at (right - size.cx, bottom - size.cy). The calling
1255/// rectangle object is unchanged.
1256//
1257inline TRect
1258TRect::operator -(const TSize& size) const
1259{
1260 return OffsetBy(-size.cx, -size.cy);
1261}
1262
1263//
1264/// Moves the upper left point of the rectangle while maintaining the
1265/// current dimension.
1266/// \todo This should be const, to indicate that the original rectangle is not modified,
1267/// just like InflatedBy()
1268//
1269inline TRect
1270TRect::MovedTo(int x, int y)
1271{
1272 return TRect(x, y, x + Width(), y + Height());
1273}
1274
1275//
1276/// Returns a rectangle inflated by the given delta arguments.
1277/// The top left corner of the returned rectangle is (left - dx, top - dy), while
1278/// its bottom right corner is (right + dx, bottom + dy). The calling rectangle object is unchanged.
1279//
1280inline TRect
1281TRect::InflatedBy(int dx, int dy) const
1282{
1283 return TRect(left-dx, top-dy, right+dx, bottom+dy);
1284}
1285
1286//
1287/// Returns a rectangle inflated by the given delta arguments.
1288/// The new corners are (left - size.cx, top - size.cy) and (right + size.cx, bottom +
1289/// size.cy). The calling rectangle object is unchanged.
1290//
1291inline TRect
1292TRect::InflatedBy(const TSize& size) const
1293{
1294 return InflatedBy(size.cx, size.cy);
1295}
1296
1297//
1298/// Returns a normalized rectangle with the top left corner at (Min(left, right),
1299/// Min(top, bottom)) and the bottom right corner at (Max(left, right), Max(top,
1300/// bottom)). The calling rectangle object is unchanged. A valid but nonnormal
1301/// rectangle might have left > right or top > bottom or both. In such cases, many
1302/// manipulations (such as determining width and height) become unnecessarily
1303/// complicated. Normalizing a rectangle means interchanging the corner point values
1304/// so that left < right and top < bottom. The physical properties of a rectangle
1305/// are unchanged by this process.
1306/// Note that many calculations assume a normalized rectangle. Some Windows API
1307/// functions behave erratically if an inside-out Rect is passed.
1308//
1309inline TRect
1311{
1312 return TRect(std::min(left, right), std::min(top, bottom),
1313 std::max(left, right), std::max(top, bottom));
1314}
1315
1316//
1317/// Returns the intersection of this rectangle and the other rectangle. The calling
1318/// rectangle object is unchanged. Returns a NULL rectangle if the two don't
1319/// intersect.
1320//
1321inline TRect
1323{
1324 if (Touches(other))
1325 return TRect(std::max(left, other.left), std::max(top, other.top),
1326 std::min(right, other.right), std::min(bottom, other.bottom));
1327 return TRect(0, 0, 0, 0);
1328}
1329
1330//
1331/// Returns the union of this rectangle and the other rectangle. The calling
1332/// rectangle object is unchanged.
1333//
1334inline TRect
1336{
1337 return TRect(std::min(left, other.left), std::min(top, other.top),
1338 std::max(right, other.right), std::max(bottom, other.bottom));
1339}
1340
1341//
1342/// Changes this rectangle so its corners are offset by the given delta values,
1343/// delta.x and delta.y. The revised rectangle has a top left corner at (left +
1344/// delta.x, top + delta.y) and a right bottom corner at (right + delta.x, bottom +
1345/// delta.y). The revised rectangle is returned.
1346//
1347inline TRect&
1349{
1350 Offset(delta.cx, delta.cy);
1351 return *this;
1352}
1353
1354//
1355/// Changes this rectangle so its corners are offset negatively by the given delta
1356/// values, delta.x and delta.y. The revised rectangle has a top left corner at
1357/// (left - delta.x, top - delta.y) and a right bottom corner at (right - delta.x,
1358/// bottom - delta.y). The revised rectangle is returned.
1359//
1360inline TRect&
1362{
1363 return *this += -delta;
1364}
1365
1366//
1367/// Moves the upper left corner of the rectangle to a new location and
1368/// maintains the current dimension.
1369//
1370inline TRect&
1371TRect::MoveTo(int x, int y)
1372{
1373 right = x + Width();
1374 bottom = y + Height();
1375 left = x;
1376 top = y;
1377 return *this;
1378}
1379
1380//
1381/// Inflates a rectangle inflated by the given delta arguments.
1382/// The new corners are (left - size.cx, top - size.cy) and (right +
1383/// size.cx, bottom + size.cy).
1384//
1385inline TRect&
1387{
1388 return Inflate(delta.cx, delta.cy);
1389}
1390
1391/// DLN MFC look-alike
1392inline TRect&
1394{
1395 return Inflate(-delta.cx, -delta.cy);
1396}
1397
1398//----------------------------------------------------------------------------
1399// TSize
1400//
1401
1402//
1403/// Default constructor that does nothing.
1404//
1405inline
1407{
1408 cx = 0;
1409 cy = 0;
1410}
1411
1412//
1413/// Creates a TSize object with cx = dx and cy = dy.
1414//
1415inline
1417{
1418 cx = dx;
1419 cy = dy;
1420}
1421
1422//
1423/// Creates a TSize object with cx = point.x and cy = point.y.
1424//
1425inline
1426TSize::TSize(const tagPOINT & point)
1427{
1428 cx = point.x;
1429 cy = point.y;
1430}
1431
1432//
1433/// Creates a TSize object with cx = size.cx and cy = size.cy.
1434//
1435inline
1436TSize::TSize(const tagSIZE & size)
1437{
1438 cx = size.cx;
1439 cy = size.cy;
1440}
1441
1442//
1443/// Creates a TSize object with cx = size.cx and cy = size.cy.
1444//
1445inline
1446TSize::TSize(const TSize & size)
1447{
1448 cx = size.cx;
1449 cy = size.cy;
1450}
1451
1452//
1453/// Creates a size by extracting the extents from the given argument.
1454///
1455/// The constructor assumes that the low-word of the given argument is the horizontal extent and
1456/// the high-word of the given argument is the vertical extent.
1457//
1458inline
1464
1465//
1466/// Returns the width.
1467//
1468inline int
1470{
1471 return cx;
1472}
1473
1474//
1475/// Returns the height.
1476//
1477inline int
1479{
1480 return cy;
1481}
1482
1483//
1484/// Returns the TSize object (-cx, -cy). This object is not changed.
1485//
1486inline TSize
1488{
1489 return TSize(-cx, -cy);
1490}
1491
1492//
1493/// Returns true if this TSize object is equal to the other TSize object; otherwise
1494/// returns false.
1495//
1496inline bool
1498{
1499 return ToBool(other.cx==cx && other.cy==cy);
1500}
1501
1502//
1503/// Returns false if this TSize object is equal to the other TSize object; otherwise
1504/// returns true.
1505//
1506inline bool
1508{
1509 return ToBool(other.cx!=cx || other.cy!=cy);
1510}
1511
1512//
1513/// Calculates an offset to this TSize object using the given size argument as the
1514/// displacement. Returns the object (cx + size.cx, cy + size.cy). This TSize object
1515/// is not changed.
1516//
1517inline TSize
1518TSize::operator +(const TSize& size) const
1519{
1520 return TSize(cx+size.cx, cy+size.cy);
1521}
1522
1523//
1524/// Calculates a negative offset to this TSize object using the given size argument
1525/// as the displacement. Returns the point (cx - size.cx, cy - size.cy). This object
1526/// is not changed.
1527//
1528inline TSize
1529TSize::operator -(const TSize& size) const
1530{
1531 return TSize(cx-size.cx, cy-size.cy);
1532}
1533
1534//
1535/// Offsets this TSize object by the given size argument. This TSize object is
1536/// changed to (cx + size.cx, cy + size.cy). Returns a reference to this object.
1537//
1538inline TSize&
1540{
1541 cx += size.cx;
1542 cy += size.cy;
1543 return *this;
1544}
1545
1546//
1547/// Negatively offsets this TSize object by the given size argument. This object is
1548/// changed to (cx - size.cx, cy - size.cy). Returns a reference to this object.
1549//
1550inline TSize&
1552{
1553 cx -= size.cx;
1554 cy -= size.cy;
1555 return *this;
1556}
1557
1558} // OWL namespace
1559
1560#endif // OWL_GEOMETRY_H
TPointF is similar to TPoint, but uses floating variables rather than integers.
Definition geometry.h:181
TPointF & operator+=(const TPointF &size)
Returns the new point moved by the offset.
Definition geometry.h:863
TPointF operator+(const TPointF &size) const
Returns a new point (x+cx, y+cy).
Definition geometry.h:834
float X() const
Returns X component of the point.
Definition geometry.h:780
bool operator==(const TPointF &other) const
Returns true if the points are at the same location.
Definition geometry.h:816
TPointF & Offset(float dx, float dy)
Moves the point by an offset.
Definition geometry.h:852
TPointF()
Default constructor that does nothing.
Definition geometry.h:750
float Y() const
Returns Y component of the point.
Definition geometry.h:789
TPointF & operator-=(const TPointF &size)
Returns the new point subtracted from the current.
Definition geometry.h:874
bool operator!=(const TPointF &other) const
Return true if the points are not at the same location.
Definition geometry.h:825
TPointF operator-() const
Returns the negative of the point.
Definition geometry.h:807
TPointF OffsetBy(float dx, float dy) const
Moves the point by an offset.
Definition geometry.h:798
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TPoint operator-() const
Returns the point (-x, -y). This point is not changed.
Definition geometry.h:491
bool operator==(const TPoint &other) const
Returns true if this point is equal to the other point; otherwise returns false.
Definition geometry.h:500
TPoint OffsetBy(int dx, int dy) const
Calculates an offset to this point using the given displacement arguments.
Definition geometry.h:482
TPoint & operator-=(const TSize &size)
Negatively offsets this point by the given size argument.
Definition geometry.h:575
bool operator!=(const TPoint &other) const
Returns false if this point is equal to the other point; otherwise returns true.
Definition geometry.h:509
TPoint & operator+=(const TSize &size)
Offsets this point by the given size argument.
Definition geometry.h:563
TPoint operator+(const TSize &size) const
Calculates an offset to this point using the given size argument as the displacement.
Definition geometry.h:520
TPoint()
Constructs an uninitialized point.
Definition geometry.h:413
TPoint & Offset(int dx, int dy)
Offsets this point by the given delta arguments.
Definition geometry.h:551
int X() const
Returns the x coordinate of the point.
Definition geometry.h:463
int Y() const
Returns the Y coordinate of the point.
Definition geometry.h:472
TPointL is similar to TPoint, but uses long rather than int variables.
Definition geometry.h:132
bool operator!=(const TPointL &other) const
Returns true if the positions are not the same.
Definition geometry.h:676
TPointL operator-() const
Returns the negative of the point.
Definition geometry.h:658
TPointL & operator-=(const TSize &size)
Return the point (x-cx, y-cy).
Definition geometry.h:734
long Y() const
Returns the Y component of the point.
Definition geometry.h:639
TPointL operator+(const TSize &size) const
Returns the new point (x+cx, y+cy).
Definition geometry.h:685
TPointL & operator+=(const TSize &size)
Return the point (x+cx, y+cy).
Definition geometry.h:723
TPointL OffsetBy(long dx, long dy) const
Returns the new point (x+dx, y+dy).
Definition geometry.h:649
TPointL()
Default constructor that does nothing.
Definition geometry.h:590
long X() const
Returns the X component of the point.
Definition geometry.h:630
TPointL & Offset(long dx, long dy)
Returns the point (x+dx, y+dy), shifting the point by the offset.
Definition geometry.h:712
bool operator==(const TPointL &other) const
Returns true if positions are the same.
Definition geometry.h:667
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TRect MovedTo(int x, int y)
Moves the upper left point of the rectangle while maintaining the current dimension.
Definition geometry.h:1270
bool operator!=(const TRect &other) const
Returns false if this rectangle has identical corner coordinates to the other rectangle; otherwise,...
Definition geometry.h:1188
int Height() const
Returns the height of this rectangle (bottom - top).
Definition geometry.h:1048
TRect OffsetBy(int dx, int dy) const
Returns a rectangle with the corners offset by the given delta values.
Definition geometry.h:1234
bool IsNull() const
Returns true if left, right, top, and bottom are all 0; otherwise, returns false.
Definition geometry.h:1167
void SetEmpty()
Empties this rectangle by setting left, top, right, and bottom to 0.
Definition geometry.h:898
void Set(int _left, int _top, int _right, int _bottom)
Repositions and resizes this rectangle to the given values.
Definition geometry.h:1087
int X() const
Returns the left value.
Definition geometry.h:938
TRect & Offset(int dx, int dy)
Changes this rectangle so its corners are offset by the given delta values.
Definition geometry.cpp:114
bool operator==(const TRect &other) const
Returns true if this rectangle has identical corner coordinates to the other rectangle; otherwise,...
Definition geometry.h:1177
TRect InflatedBy(int dx, int dy) const
Returns a rectangle inflated by the given delta arguments.
Definition geometry.h:1281
void SetWH(int _left, int _top, int w, int h)
Determines the rectangle, given its upperleft point, width, and height.
Definition geometry.h:1099
TRect Normalized() const
Returns a normalized rectangle with the top left corner at (Min(left, right), Min(top,...
Definition geometry.h:1310
TRect & Inflate(int dx, int dy)
Inflates a rectangle inflated by the given delta arguments.
Definition geometry.cpp:129
long Area() const
Returns the area of this rectangle.
Definition geometry.h:1066
const TPoint & BottomRight() const
Returns the TPoint object representing the bottom right corner of this rectangle.
Definition geometry.h:1020
TRect & operator-=(const TSize &delta)
Changes this rectangle so its corners are offset negatively by the given delta values,...
Definition geometry.h:1361
int Right() const
Returns the right value.
Definition geometry.h:965
const TPoint & TopLeft() const
Returns the upperleft point.
Definition geometry.h:983
TRect operator+(const TSize &size) const
Returns a rectangle offset positively by the delta values' given sizes.
Definition geometry.h:1246
int Width() const
Returns the width of this rectangle (right - left).
Definition geometry.h:1039
bool Touches(const TRect &other) const
Returns true if the other rectangle shares any interior points with this rectangle; otherwise,...
Definition geometry.h:1222
TRect operator-(const TSize &size) const
Returns a rectangle offset negatively by the delta values' given sizes.
Definition geometry.h:1258
bool Contains(const TPoint &point) const
Returns true if the given point lies within this rectangle; otherwise, it returns false.
Definition geometry.h:1200
void SetNull()
Sets the left, top, right, and bottom of the rectangle to 0.
Definition geometry.h:1075
TRect & DeflateRect(int dx, int dy)
Definition geometry.cpp:142
TRect()
Default constructor that does nothing.
Definition geometry.h:889
int Top() const
Returns the top value.
Definition geometry.h:947
TRect operator|(const TRect &other) const
Returns the union of this rectangle and the other rectangle.
Definition geometry.h:1335
TRect & operator+=(const TSize &delta)
Changes this rectangle so its corners are offset by the given delta values, delta....
Definition geometry.h:1348
TRect operator&(const TRect &other) const
Returns the intersection of this rectangle and the other rectangle.
Definition geometry.h:1322
TRect & MoveTo(int x, int y)
Moves the upper left corner of the rectangle to a new location and maintains the current dimension.
Definition geometry.h:1371
int Bottom() const
Returns the bottom value.
Definition geometry.h:974
TPoint BottomLeft() const
Returns the TPoint object representing the bottom left corner of this rectangle.
Definition geometry.h:1010
int Y() const
Returns the top value.
Definition geometry.h:956
int Left() const
Returns the left value.
Definition geometry.h:929
TSize Size() const
Returns the size of rectangle.
Definition geometry.h:1057
bool IsEmpty() const
Returns true if left >= right or top >= bottom; otherwise, returns false.
Definition geometry.h:1157
TPoint TopRight() const
Returns the upperright point.
Definition geometry.h:1001
The tagSIZE struct is defined as.
Definition geometry.h:234
TSize & operator+=(const TSize &size)
Offsets this TSize object by the given size argument.
Definition geometry.h:1539
bool operator!=(const TSize &other) const
Returns false if this TSize object is equal to the other TSize object; otherwise returns true.
Definition geometry.h:1507
TSize operator+(const TSize &size) const
Calculates an offset to this TSize object using the given size argument as the displacement.
Definition geometry.h:1518
bool operator==(const TSize &other) const
Returns true if this TSize object is equal to the other TSize object; otherwise returns false.
Definition geometry.h:1497
int Y() const
Returns the height.
Definition geometry.h:1478
TSize & operator-=(const TSize &size)
Negatively offsets this TSize object by the given size argument.
Definition geometry.h:1551
TSize operator-() const
Returns the TSize object (-cx, -cy). This object is not changed.
Definition geometry.h:1487
TSize()
Default constructor that does nothing.
Definition geometry.h:1406
int X() const
Returns the width.
Definition geometry.h:1469
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
Base class for writing streamable objects.
Definition objstrm.h:480
TAbsLocation
General use absolute 2-D rectangular location enum.
Definition geometry.h:62
@ alTop
Refers to top edge of frame.
Definition geometry.h:64
@ alRight
Refers to right edge of frame.
Definition geometry.h:67
@ alBottom
Refers to bottom edge of frame.
Definition geometry.h:65
@ alLeft
Refers to left edge of frame.
Definition geometry.h:66
@ alNone
No location specified.
Definition geometry.h:63
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
__int64 int64
Definition number.h:36
signed long int32
Definition number.h:30
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
Definition color.h:498
int16 Sqrt(int32 val)
Definition geometry.cpp:23
bool ToBool(const T &t)
Definition defs.h:291
signed short int16
Definition number.h:29
std::istream tistream
Definition strmdefs.h:39
std::ostream tostream
Definition strmdefs.h:40
owl::ipstream & operator>>(owl::ipstream &is, TColor &c)
Extract the color value from a persistent input stream.
Definition color.h:489
#define _OWLFUNC(p)
Definition defs.h:341
#define _OWLCFUNC(p)
Definition defs.h:342
#define _OWLCLASS
Definition defs.h:338
Base struct for the TPointF class.
Definition geometry.h:171
Includes windowing system headers, with necessary macros defined.