#include <rect.h>
Inheritance diagram for Rect:
Public Member Functions | |
Rect () | |
To construct an empty Rect. | |
Rect (INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY) | |
To construct a Rect with an inclusive lower left hand corner position of (Left, Lower) and an exclusive upper right hand corner position of (Right, Upper). | |
Rect (const Coord &Low, UINT32 Width, UINT32 Height) | |
To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified. | |
Rect (const Coord &Low, const Coord &High) | |
To construct a rectangle with an inclusive lower left hand corner position of Low and an exclusive upper right hand corner position of High. | |
Rect (const Rect &Rect) | |
Copy constructor. | |
Rect & | operator= (const Rect &Rect) |
Equals operator. | |
INT32 | Width () const |
To find the width of the Rect. | |
INT32 | Height () const |
To find the height of the Rect. | |
Coord | LowCorner () const |
To find the lower left hand coordinates of the Rect. | |
Coord | HighCorner () const |
To find the upper right hand coordinates of the Rect. | |
Coord | Centre () const |
To find the centre of the Rect It calculates Coord(lox+(width/2),loy+(height/2)). | |
BOOL | IsIntersectedWith (const Rect &) const |
To check for rectangle intersection. | |
Rect | Intersection (const Rect &) const |
Rect | Union (const Rect &) const |
INT32 | SplitRect (const Rect &R, Rect *SubRects) |
BOOL | ContainsCoord (const Coord &) const |
To check for coordinate containment. | |
BOOL | ContainsRectCoord (const Coord &) const |
To check for coordinate containment. This will work for coordinates which have been extracted from other rectangles (i.e. the top right corner is considered inclusive for this operation, not exclusive). | |
BOOL | ContainsRect (const Rect &) const |
To check for rectangle containment. | |
BOOL | IsAdjacent (const Rect &, MILLIPOINT Fuzzy) const |
void | MakeEmpty () |
Make the rectangle an empty one (all coordinates are set to 0). | |
BOOL | IsEmpty () const |
To check for empty rectangle. | |
BOOL | IsValid () const |
To check for a valid rectangle. | |
void | Inflate (INT32 XInc, INT32 YInc) |
Inflate a rectangle by given amounts. Negative values will deflate the rectangle. | |
void | Inflate (INT32 XInc) |
Inflate a rectangle by given amount. Negative values will deflate the rectangle. | |
void | Translate (INT32 XOfs, INT32 YOfs) |
Translate a rectangle by given offset. | |
void | IncludePoint (const Coord &) |
INT32 | operator== (const Rect &) const |
Test for equality of two rectangles. As all invalid rectangles have the same results when used for Union/Intersection, any two invalid rectangles are considered equal. | |
INT32 | operator!= (const Rect &) const |
Test for inequality of two rectangles. As all invalid rectangles have the same results when used for Union/Intersection, any two invalid rectangles are considered equal. | |
Public Attributes | |
Coord | lo |
Coord | hi |
The inclusivity can be explained as follows:
A point at (lo.x, lo.y) is inside the rectangle A point at (hi.x, hi.y) is outside the rectangle
Any rectangle that does not obey the inequalites lo.y <= hi.y and lo.x <= hi.x is deemed to be 'invalid'. Invalid rectangles have special properties. They will cause errors when used in some operations, but not in others. The general rule is that if the rectangle is used as an entity, then the operation will succeed (taking account of the 'invalidity' of the rectangle). If, however, the actual coordinates of the invalid rectangle must be used/changed in the operation, then an error (usually an assertion failure) will occur.
For example, using invalid rectangles in Unions and Intersections is ok, because the invalid rectangle is ignored, and the 'other' rectangle is returned as the result. This means that if both rectangles are invalid, then an invalid rectangle is returned.
Conversely, trying to use operations like Translate(), Inflate(), Width() or Height() on invalid rectangles is considered to be an error, and will cause an assertion failure.
See the individual function descriptions for more details.
Definition at line 159 of file rect.h.
|
To construct an empty Rect.
Definition at line 398 of file rect.h.
|
|
To construct a Rect with an inclusive lower left hand corner position of (Left, Lower) and an exclusive upper right hand corner position of (Right, Upper).
Definition at line 429 of file rect.h. 00430 { 00431 // Defensive programming, detect an invalid rectangle 00432 ENSURE((LowX <= HighX) && (LowY <= HighY), 00433 "Rect::Rect(INT32, INT32, INT32, INT32) was\n passed invalid coordinates"); 00434 00435 lo.x = LowX; 00436 lo.y = LowY; 00437 00438 hi.x = HighX; 00439 hi.y = HighY; 00440 }
|
|
To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified.
Definition at line 494 of file rect.h.
|
|
To construct a rectangle with an inclusive lower left hand corner position of Low and an exclusive upper right hand corner position of High.
Definition at line 464 of file rect.h. 00465 { 00466 // Defensive programming, detect an invalid rectangle 00467 ENSURE((Low.x <= High.x) && (Low.y <= High.y), 00468 "Rect::Rect(Coord, Coord) was\n passed invalid coordinates"); 00469 00470 lo = Low; 00471 hi = High; 00472 }
|
|
Copy constructor.
Definition at line 519 of file rect.h.
|
|
To find the centre of the Rect It calculates Coord(lox+(width/2),loy+(height/2)).
Definition at line 667 of file rect.h. 00668 { 00669 // Detect an invalid rectangle 00670 ENSURE(IsValid(), "Rect::Centre() was called on\nan invalid rectangle."); 00671 00672 return Coord(lo.x + Width() / 2, lo.y + Height() / 2); 00673 }
|
|
To check for coordinate containment.
Definition at line 725 of file rect.h. 00726 { 00727 // Check for an an empty rectangle 00728 if (IsEmpty()) 00729 return FALSE; 00730 00731 // Detect an invalid rectangle 00732 ENSURE(IsValid(), "Rect::ContainsCoord() was called on\nan invalid rectangle."); 00733 00734 return ((Point.x >= lo.x) && (Point.x < hi.x) && 00735 (Point.y >= lo.y) && (Point.y < hi.y)); 00736 }
|
|
To check for rectangle containment.
Definition at line 795 of file rect.h. 00796 { 00797 // Check for an an empty rectangle 00798 if (IsEmpty()) 00799 return FALSE; 00800 00801 // Detect an invalid rectangle 00802 ENSURE(IsValid(), "Rect::ContainsRect() was called on\nan invalid rectangle."); 00803 00804 return ((Rect.lo.x >= lo.x) && (Rect.hi.x <= hi.x) && 00805 (Rect.lo.y >= lo.y) && (Rect.hi.y <= hi.y)); 00806 }
|
|
To check for coordinate containment. This will work for coordinates which have been extracted from other rectangles (i.e. the top right corner is considered inclusive for this operation, not exclusive).
Definition at line 761 of file rect.h. 00762 { 00763 // Check for an an empty rectangle 00764 if (IsEmpty()) 00765 return FALSE; 00766 00767 // Detect an invalid rectangle 00768 ENSURE(IsValid(), "Rect::ContainsRectCoord() was called on\nan invalid rectangle."); 00769 00770 return ((Point.x >= lo.x) && (Point.x <= hi.x) && 00771 (Point.y >= lo.y) && (Point.y <= hi.y)); 00772 }
|
|
To find the height of the Rect.
Definition at line 589 of file rect.h. 00590 { 00591 // Detect an invalid rectangle 00592 ENSURE(IsValid(), "Rect::Height() was called on\nan invalid rectangle."); 00593 00594 return(hi.y - lo.y); 00595 }
|
|
To find the upper right hand coordinates of the Rect.
Definition at line 640 of file rect.h. 00641 { 00642 // Detect an invalid rectangle 00643 ENSURE(IsValid(), "Rect::HighCorner() was called on\nan invalid rectangle."); 00644 00645 return(hi); 00646 }
|
|
|
|
Inflate a rectangle by given amount. Negative values will deflate the rectangle.
Definition at line 367 of file rect.h. 00368 { 00369 // Detect an invalid rectangle 00370 ENSURE(IsValid(), "Rect::Inflate(INT32) was called on an \ninvalid rectangle."); 00371 00372 lo.x -= Inc; 00373 lo.y -= Inc; 00374 00375 hi.x += Inc; 00376 hi.y += Inc; 00377 }
|
|
Inflate a rectangle by given amounts. Negative values will deflate the rectangle.
Definition at line 335 of file rect.h. 00336 { 00337 // Detect an invalid rectangle 00338 ENSURE(IsValid(), "Rect::Inflate(INT32, INT32) was called on an \ninvalid rectangle."); 00339 00340 lo.x -= XInc; 00341 lo.y -= YInc; 00342 00343 hi.x += XInc; 00344 hi.y += YInc; 00345 }
|
|
|
|
|
|
To check for empty rectangle.
Definition at line 845 of file rect.h.
|
|
To check for rectangle intersection.
Definition at line 694 of file rect.h. 00695 { 00696 // Detect an invalid rectangle 00697 if ((!IsValid()) || (!R.IsValid())) 00698 return FALSE; 00699 00700 return ((hi.x > R.lo.x) && (lo.x < R.hi.x) && 00701 (hi.y > R.lo.y) && (lo.y < R.hi.y)); 00702 }
|
|
To check for a valid rectangle.
Definition at line 869 of file rect.h.
|
|
To find the lower left hand coordinates of the Rect.
Definition at line 614 of file rect.h. 00615 { 00616 // Detect an invalid rectangle 00617 ENSURE(IsValid(), "Rect::LowCorner() was called on\nan invalid rectangle."); 00618 00619 return(lo); 00620 }
|
|
Make the rectangle an empty one (all coordinates are set to 0).
Definition at line 821 of file rect.h.
|
|
Test for inequality of two rectangles. As all invalid rectangles have the same results when used for Union/Intersection, any two invalid rectangles are considered equal.
Definition at line 305 of file rect.h. 00306 { 00307 // Invalid rectangles are equal 00308 if ((!IsValid()) && (!R.IsValid())) 00309 return FALSE; 00310 00311 return ((lo.x != R.lo.x) || (lo.y != R.lo.y) || 00312 (hi.x != R.hi.x) || (hi.y != R.hi.y)); 00313 }
|
|
Equals operator.
Definition at line 541 of file rect.h.
|
|
Test for equality of two rectangles. As all invalid rectangles have the same results when used for Union/Intersection, any two invalid rectangles are considered equal.
Definition at line 270 of file rect.h. 00271 { 00272 // Invalid rectangles are equal 00273 if ((!IsValid()) && (!R.IsValid())) 00274 return TRUE; 00275 00276 // Could use structure compare? Would it be portable? Probably not... 00277 00278 return ((lo.x == R.lo.x) && (lo.y == R.lo.y) && 00279 (hi.x == R.hi.x) && (hi.y == R.hi.y)); 00280 }
|
|
|
|
Translate a rectangle by given offset.
Definition at line 235 of file rect.h. 00236 { 00237 // Detect an invalid rectangle 00238 ENSURE(IsValid(), "Rect::Translate() was called on an \ninvalid rectangle."); 00239 00240 lo.x += XOfs; 00241 lo.y += YOfs; 00242 00243 hi.x += XOfs; 00244 hi.y += YOfs; 00245 }
|
|
|
|
To find the width of the Rect.
Definition at line 565 of file rect.h. 00566 { 00567 // Detect an invalid rectangle 00568 ENSURE(IsValid(), "Rect::Width() was called on\nan invalid rectangle."); 00569 00570 return (hi.x - lo.x); 00571 }
|
|
|
|
|