#include <wrkrect.h>
Public Member Functions | |
WorkRect () | |
To construct an empty WorkRect. | |
WorkRect (XLONG LowX, XLONG LowY, XLONG HighX, XLONG HighY) | |
To construct a WorkRect with an inclusive lower left hand corner position of (Left, Lower) and an exclusive upper right hand corner position of (Right, Upper). | |
WorkRect (const WorkCoord &Low, XLONG Width, XLONG Height) | |
To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified. | |
WorkRect (const WorkCoord &Low, const WorkCoord &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. | |
WorkRect (const WorkRect &WorkRect) | |
Copy constructor. | |
WorkRect & | operator= (const WorkRect &WorkRect) |
Equals operator. | |
XLONG | Width () const |
To find the width of the WorkRect. | |
XLONG | Height () const |
To find the height of the WorkRect. | |
WorkCoord | LowCorner () const |
To find the lower left hand coordinates of the WorkRect. | |
WorkCoord | HighCorner () const |
To find the upper right hand coordinates of the WorkRect. | |
WorkCoord | Centre () const |
To find the centre of the WorkRect It calculates WorkCoord(lox+(width/2),loy+(height/2)). | |
BOOL | IsIntersectedWith (const WorkRect &) const |
To check for rectangle intersection. | |
WorkRect | Intersection (const WorkRect &) const |
WorkRect | Union (const WorkRect &) const |
INT32 | SplitRect (const WorkRect &R, WorkRect *SubRects) |
BOOL | ContainsCoord (const WorkCoord &) const |
To check for coordinate containment. | |
BOOL | ContainsRectCoord (const WorkCoord &) 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 WorkRect &) const |
To check for rectangle containment. | |
BOOL | IsAdjacent (const WorkRect &, 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 (XLONG XInc, XLONG YInc) |
Inflate a rectangle by given amounts. Negative values will deflate the rectangle. | |
void | Inflate (XLONG XInc) |
Inflate a rectangle by given amount. Negative values will deflate the rectangle. | |
void | Translate (XLONG XOfs, XLONG YOfs) |
Translate a rectangle by given offset. | |
void | IncludePoint (const WorkCoord &) |
INT32 | operator== (const WorkRect &) 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 WorkRect &) 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 | |
WorkCoord | lo |
WorkCoord | 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 160 of file wrkrect.h.
|
To construct an empty WorkRect.
Definition at line 400 of file wrkrect.h.
|
|
To construct a WorkRect 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 431 of file wrkrect.h. 00432 { 00433 // Defensive programming, detect an invalid rectangle 00434 ENSURE((LowX <= HighX) && (LowY <= HighY), 00435 "WorkRect::WorkRect(XLONG, XLONG, XLONG, XLONG) was\n passed invalid coordinates"); 00436 00437 lo.x = LowX; 00438 lo.y = LowY; 00439 00440 hi.x = HighX; 00441 hi.y = HighY; 00442 }
|
|
To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified.
Definition at line 496 of file wrkrect.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 466 of file wrkrect.h. 00467 { 00468 // Defensive programming, detect an invalid rectangle 00469 ENSURE((Low.x <= High.x) && (Low.y <= High.y), 00470 "WorkRect::WorkRect(WorkCoord, WorkCoord) was\n passed invalid coordinates"); 00471 00472 lo = Low; 00473 hi = High; 00474 }
|
|
Copy constructor.
Definition at line 521 of file wrkrect.h.
|
|
To find the centre of the WorkRect It calculates WorkCoord(lox+(width/2),loy+(height/2)).
Definition at line 669 of file wrkrect.h. 00670 { 00671 // Detect an invalid rectangle 00672 ENSURE(IsValid(), "WorkRect::Centre() was called on\nan invalid rectangle."); 00673 00674 return WorkCoord(lo.x + Width() / 2, lo.y + Height() / 2); 00675 }
|
|
To check for coordinate containment.
Definition at line 727 of file wrkrect.h. 00728 { 00729 // Check for an an empty rectangle 00730 if (IsEmpty()) 00731 return FALSE; 00732 00733 // Detect an invalid rectangle 00734 ENSURE(IsValid(), "WorkRect::ContainsCoord() was called on\nan invalid rectangle."); 00735 00736 return ((Point.x >= lo.x) && (Point.x < hi.x) && 00737 (Point.y >= lo.y) && (Point.y < hi.y)); 00738 }
|
|
To check for rectangle containment.
Definition at line 797 of file wrkrect.h. 00798 { 00799 // Check for an an empty rectangle 00800 if (IsEmpty()) 00801 return FALSE; 00802 00803 // Detect an invalid rectangle 00804 ENSURE(IsValid(), "WorkRect::ContainsRect() was called on\nan invalid rectangle."); 00805 00806 return ((Rect.lo.x >= lo.x) && (Rect.hi.x <= hi.x) && 00807 (Rect.lo.y >= lo.y) && (Rect.hi.y <= hi.y)); 00808 }
|
|
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 763 of file wrkrect.h. 00764 { 00765 // Check for an an empty rectangle 00766 if (IsEmpty()) 00767 return FALSE; 00768 00769 // Detect an invalid rectangle 00770 ENSURE(IsValid(), "WorkRect::ContainsRectCoord() was called on\nan invalid rectangle."); 00771 00772 return ((Point.x >= lo.x) && (Point.x <= hi.x) && 00773 (Point.y >= lo.y) && (Point.y <= hi.y)); 00774 }
|
|
To find the height of the WorkRect.
Definition at line 591 of file wrkrect.h. 00592 { 00593 // Detect an invalid rectangle 00594 ENSURE(IsValid(), "WorkRect::Height() was called on\nan invalid rectangle."); 00595 00596 return(hi.y - lo.y); 00597 }
|
|
To find the upper right hand coordinates of the WorkRect.
Definition at line 642 of file wrkrect.h. 00643 { 00644 // Detect an invalid rectangle 00645 ENSURE(IsValid(), "WorkRect::HighCorner() was called on\nan invalid rectangle."); 00646 00647 return(hi); 00648 }
|
|
|
|
Inflate a rectangle by given amount. Negative values will deflate the rectangle.
Definition at line 369 of file wrkrect.h. 00370 { 00371 // Detect an invalid rectangle 00372 ENSURE(IsValid(), "WorkRect::Inflate(XLONG) was called on an \ninvalid rectangle."); 00373 00374 lo.x -= Inc; 00375 lo.y -= Inc; 00376 00377 hi.x += Inc; 00378 hi.y += Inc; 00379 }
|
|
Inflate a rectangle by given amounts. Negative values will deflate the rectangle.
Definition at line 337 of file wrkrect.h. 00338 { 00339 // Detect an invalid rectangle 00340 ENSURE(IsValid(), "WorkRect::Inflate(XLONG, XLONG) was called on an \ninvalid rectangle."); 00341 00342 lo.x -= XInc; 00343 lo.y -= YInc; 00344 00345 hi.x += XInc; 00346 hi.y += YInc; 00347 }
|
|
|
|
|
|
To check for empty rectangle.
Definition at line 847 of file wrkrect.h.
|
|
To check for rectangle intersection.
Definition at line 696 of file wrkrect.h. 00697 { 00698 // Detect an invalid rectangle 00699 if ((!IsValid()) || (!R.IsValid())) 00700 return FALSE; 00701 00702 return ((hi.x > R.lo.x) && (lo.x < R.hi.x) && 00703 (hi.y > R.lo.y) && (lo.y < R.hi.y)); 00704 }
|
|
To check for a valid rectangle.
Definition at line 871 of file wrkrect.h.
|
|
To find the lower left hand coordinates of the WorkRect.
Definition at line 616 of file wrkrect.h. 00617 { 00618 // Detect an invalid rectangle 00619 ENSURE(IsValid(), "WorkRect::LowCorner() was called on\nan invalid rectangle."); 00620 00621 return(lo); 00622 }
|
|
Make the rectangle an empty one (all coordinates are set to 0).
Definition at line 823 of file wrkrect.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 307 of file wrkrect.h. 00308 { 00309 // Invalid rectangles are equal 00310 if ((!IsValid()) && (!R.IsValid())) 00311 return FALSE; 00312 00313 return ((lo.x != R.lo.x) || (lo.y != R.lo.y) || 00314 (hi.x != R.hi.x) || (hi.y != R.hi.y)); 00315 }
|
|
Equals operator.
Definition at line 543 of file wrkrect.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 272 of file wrkrect.h. 00273 { 00274 // Invalid rectangles are equal 00275 if ((!IsValid()) && (!R.IsValid())) 00276 return TRUE; 00277 00278 // Could use structure compare? Would it be portable? Probably not... 00279 00280 return ((lo.x == R.lo.x) && (lo.y == R.lo.y) && 00281 (hi.x == R.hi.x) && (hi.y == R.hi.y)); 00282 }
|
|
|
|
Translate a rectangle by given offset.
Definition at line 237 of file wrkrect.h. 00238 { 00239 // Detect an invalid rectangle 00240 ENSURE(IsValid(), "WorkRect::Translate() was called on an \ninvalid rectangle."); 00241 00242 lo.x += XOfs; 00243 lo.y += YOfs; 00244 00245 hi.x += XOfs; 00246 hi.y += YOfs; 00247 }
|
|
|
|
To find the width of the WorkRect.
Definition at line 567 of file wrkrect.h. 00568 { 00569 // Detect an invalid rectangle 00570 ENSURE(IsValid(), "WorkRect::Width() was called on\nan invalid rectangle."); 00571 00572 return (hi.x - lo.x); 00573 }
|
|
|
|
|