#include <userrect.h>
Public Member Functions | |
UserRect () | |
To construct an empty UserRect. | |
UserRect (INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY) | |
To construct a UserRect with an inclusive lower left hand corner position of (Left, Lower) and an exclusive upper right hand corner position of (Right, Upper). | |
UserRect (const UserCoord &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. | |
UserRect (const UserCoord &Low, const UserCoord &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. | |
UserRect (const UserRect &UserRect) | |
Copy constructor. | |
UserRect & | operator= (const UserRect &UserRect) |
Equals operator. | |
INT32 | Width () const |
To find the width of the UserRect. | |
INT32 | Height () const |
To find the height of the UserRect. | |
UserCoord | LowCorner () const |
To find the lower left hand coordinates of the UserRect. | |
UserCoord | HighCorner () const |
To find the upper right hand coordinates of the UserRect. | |
UserCoord | Centre () const |
To find the centre of the UserRect It calculates UserCoord(lox+(width/2),loy+(height/2)). | |
BOOL | IsIntersectedWith (const UserRect &) const |
To check for rectangle intersection. | |
UserRect | Intersection (const UserRect &) const |
Compute intersection of two rectangles. | |
UserRect | Union (const UserRect &) const |
Compute union of two rectangles. | |
INT32 | SplitRect (const UserRect &R, UserRect *SubRects) |
Splits a rectangle into sub-rectangles which all exclude the interecting rectangle R. The number of sub-rects generated depends on how the rectangles intersect. _______________________ ___________________ | | | | | *this A | | *this A | |_ _ _ ________ _ _ _ | |_ _ _ _ _ ________|__________ | | | | | | | | | B | R | C | | B | | | |_ _ _ |________| _ _ _ | |__________|________| R | | | | | | D Index=4 | | Index=2 | |_______________________| |___________________|. | |
BOOL | ContainsCoord (const UserCoord &) const |
To check for coordinate containment. | |
BOOL | ContainsRectCoord (const UserCoord &) 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 UserRect &) const |
To check for rectangle containment. | |
BOOL | IsAdjacent (const UserRect &, MILLIPOINT Fuzzy) const |
To check for adjacent rectangles. | |
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 UserCoord &) |
Expand a rectangle so that it includes the given point. | |
INT32 | operator== (const UserRect &) 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 UserRect &) 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. | |
DocRect | ToSpread (Spread *pSpread) |
Convert a UserRect to a SpreadRect (AKA DocRect). | |
Public Attributes | |
UserCoord | lo |
UserCoord | 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 164 of file userrect.h.
|
To construct an empty UserRect.
Definition at line 408 of file userrect.h.
|
|
To construct a UserRect 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 439 of file userrect.h. 00440 { 00441 // Defensive programming, detect an invalid rectangle 00442 ENSURE((LowX <= HighX) && (LowY <= HighY), 00443 "UserRect::UserRect(INT32, INT32, INT32, INT32) was\n passed invalid coordinates"); 00444 00445 lo.x = LowX; 00446 lo.y = LowY; 00447 00448 hi.x = HighX; 00449 hi.y = HighY; 00450 }
|
|
To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified.
Definition at line 504 of file userrect.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 474 of file userrect.h. 00475 { 00476 // Defensive programming, detect an invalid rectangle 00477 ENSURE((Low.x <= High.x) && (Low.y <= High.y), 00478 "UserRect::UserRect(UserCoord, UserCoord) was\n passed invalid coordinates"); 00479 00480 lo = Low; 00481 hi = High; 00482 }
|
|
Copy constructor.
Definition at line 529 of file userrect.h.
|
|
To find the centre of the UserRect It calculates UserCoord(lox+(width/2),loy+(height/2)).
Definition at line 677 of file userrect.h. 00678 { 00679 // Detect an invalid rectangle 00680 ENSURE(IsValid(), "UserRect::Centre() was called on\nan invalid rectangle."); 00681 00682 return UserCoord(lo.x + Width() / 2, lo.y + Height() / 2); 00683 }
|
|
To check for coordinate containment.
Definition at line 735 of file userrect.h. 00736 { 00737 // Check for an an empty rectangle 00738 if (IsEmpty()) 00739 return FALSE; 00740 00741 // Detect an invalid rectangle 00742 ENSURE(IsValid(), "UserRect::ContainsCoord() was called on\nan invalid rectangle."); 00743 00744 return ((Point.x >= lo.x) && (Point.x < hi.x) && 00745 (Point.y >= lo.y) && (Point.y < hi.y)); 00746 }
|
|
To check for rectangle containment.
Definition at line 805 of file userrect.h. 00806 { 00807 // Check for an an empty rectangle 00808 if (IsEmpty()) 00809 return FALSE; 00810 00811 // Detect an invalid rectangle 00812 ENSURE(IsValid(), "UserRect::ContainsRect() was called on\nan invalid rectangle."); 00813 00814 return ((Rect.lo.x >= lo.x) && (Rect.hi.x <= hi.x) && 00815 (Rect.lo.y >= lo.y) && (Rect.hi.y <= hi.y)); 00816 }
|
|
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 771 of file userrect.h. 00772 { 00773 // Check for an an empty rectangle 00774 if (IsEmpty()) 00775 return FALSE; 00776 00777 // Detect an invalid rectangle 00778 ENSURE(IsValid(), "UserRect::ContainsRectCoord() was called on\nan invalid rectangle."); 00779 00780 return ((Point.x >= lo.x) && (Point.x <= hi.x) && 00781 (Point.y >= lo.y) && (Point.y <= hi.y)); 00782 }
|
|
To find the height of the UserRect.
Definition at line 599 of file userrect.h. 00600 { 00601 // Detect an invalid rectangle 00602 ENSURE(IsValid(), "UserRect::Height() was called on\nan invalid rectangle."); 00603 00604 return(hi.y - lo.y); 00605 }
|
|
To find the upper right hand coordinates of the UserRect.
Definition at line 650 of file userrect.h. 00651 { 00652 // Detect an invalid rectangle 00653 ENSURE(IsValid(), "UserRect::HighCorner() was called on\nan invalid rectangle."); 00654 00655 return(hi); 00656 }
|
|
Expand a rectangle so that it includes the given point.
Definition at line 388 of file userrect.cpp. 00389 { 00390 // Detect an invalid rectangle 00391 ENSURE(IsValid(), "UserRect::IncludePoint() was called on an \ninvalid rectangle."); 00392 00393 // Extend lower corner to include point if necessary 00394 lo.x = min(lo.x, Point.x); 00395 lo.y = min(lo.y, Point.y); 00396 00397 // Extend upper corner to include point if necessary 00398 // (remember upper corner is exclusive) 00399 hi.x = max(hi.x, (INT32)(Point.x + 1L)); 00400 hi.y = max(hi.y, (INT32)(Point.y + 1L)); 00401 }
|
|
Inflate a rectangle by given amount. Negative values will deflate the rectangle.
Definition at line 377 of file userrect.h. 00378 { 00379 // Detect an invalid rectangle 00380 ENSURE(IsValid(), "UserRect::Inflate(INT32) was called on an \ninvalid rectangle."); 00381 00382 lo.x -= Inc; 00383 lo.y -= Inc; 00384 00385 hi.x += Inc; 00386 hi.y += Inc; 00387 }
|
|
Inflate a rectangle by given amounts. Negative values will deflate the rectangle.
Definition at line 345 of file userrect.h. 00346 { 00347 // Detect an invalid rectangle 00348 ENSURE(IsValid(), "UserRect::Inflate(INT32, INT32) was called on an \ninvalid rectangle."); 00349 00350 lo.x -= XInc; 00351 lo.y -= YInc; 00352 00353 hi.x += XInc; 00354 hi.y += YInc; 00355 }
|
|
Compute intersection of two rectangles.
Definition at line 293 of file userrect.cpp. 00294 { 00295 // Special cases for invalid rectangles... 00296 if (!IsValid()) 00297 return R; 00298 if (!R.IsValid()) 00299 return *this; 00300 00301 // Special cases when empty rectangles 00302 if (IsEmpty()) 00303 return *this; 00304 if (R.IsEmpty()) 00305 return R; 00306 00307 // Return the result 00308 UserRect I; 00309 I.lo.x = max(lo.x, R.lo.x); 00310 I.lo.y = max(lo.y, R.lo.y); 00311 I.hi.x = min(hi.x, R.hi.x); 00312 I.hi.y = min(hi.y, R.hi.y); 00313 return I; 00314 }
|
|
To check for adjacent rectangles.
Definition at line 188 of file userrect.cpp. 00189 { 00190 // Check for an an empty rectangle 00191 if (IsEmpty()) 00192 return FALSE; 00193 00194 // Detect an invalid rectangle 00195 ENSURE(IsValid(), "UserRect::IsAdjacent() was called on\nan invalid rectangle."); 00196 00197 #if 0 00198 // This is the expansion of the rampant return statement below 00199 00200 // Near top or bottom 00201 BOOL NearBot = (ABS(Rect.hi.y - lo.y)) <= Fuzzy; 00202 BOOL NearTop = (ABS(Rect.lo.y - hi.y)) <= Fuzzy; 00203 00204 // Near left or right 00205 BOOL NearLeft = (ABS(Rect.hi.x - lo.x)) <= Fuzzy; 00206 BOOL NearRight = (ABS(Rect.lo.x - hi.x)) <= Fuzzy; 00207 00208 // Overlaps 00209 BOOL OverLeft = (ABS(Rect.lo.x - lo.x)) <= Fuzzy; 00210 BOOL OverRight = (ABS(Rect.hi.x - hi.x)) <= Fuzzy; 00211 BOOL OverTop = (ABS(Rect.hi.y - hi.y)) <= Fuzzy; 00212 BOOL OverBot = (ABS(Rect.lo.y - lo.y)) <= Fuzzy; 00213 00214 // Adjacent to the top or bottom? 00215 BOOL TopOrBot = (NearTop || NearBot) && OverLeft && OverRight; 00216 BOOL LeftOrRight = (NearLeft || NearRight) && OverTop && OverBot; 00217 00218 return (TopOrBot || LeftOrRight); 00219 #endif 00220 00221 // This is explained more carefully in the section above that is excluded from the build 00222 return (( ((ABS(Rect.lo.x - lo.x))<=Fuzzy) && ((ABS(Rect.hi.x - hi.x))<=Fuzzy) && 00223 (((ABS(Rect.hi.y - lo.y))<=Fuzzy) || ((ABS(Rect.lo.y - hi.y))<=Fuzzy)) ) || 00224 ( ((ABS(Rect.lo.y - lo.y))<=Fuzzy) && ((ABS(Rect.hi.y - hi.y))<=Fuzzy) && 00225 (((ABS(Rect.hi.x - lo.x))<=Fuzzy) || ((ABS(Rect.lo.x - hi.x))<=Fuzzy)) )); 00226 }
|
|
To check for empty rectangle.
Definition at line 855 of file userrect.h.
|
|
To check for rectangle intersection.
Definition at line 704 of file userrect.h. 00705 { 00706 // Detect an invalid rectangle 00707 if ((!IsValid()) || (!R.IsValid())) 00708 return FALSE; 00709 00710 return ((hi.x > R.lo.x) && (lo.x < R.hi.x) && 00711 (hi.y > R.lo.y) && (lo.y < R.hi.y)); 00712 }
|
|
To check for a valid rectangle.
Definition at line 879 of file userrect.h.
|
|
To find the lower left hand coordinates of the UserRect.
Definition at line 624 of file userrect.h. 00625 { 00626 // Detect an invalid rectangle 00627 ENSURE(IsValid(), "UserRect::LowCorner() was called on\nan invalid rectangle."); 00628 00629 return(lo); 00630 }
|
|
Make the rectangle an empty one (all coordinates are set to 0).
Definition at line 831 of file userrect.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 315 of file userrect.h. 00316 { 00317 // Invalid rectangles are equal 00318 if ((!IsValid()) && (!R.IsValid())) 00319 return FALSE; 00320 00321 return ((lo.x != R.lo.x) || (lo.y != R.lo.y) || 00322 (hi.x != R.hi.x) || (hi.y != R.hi.y)); 00323 }
|
|
Equals operator.
Definition at line 551 of file userrect.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 280 of file userrect.h. 00281 { 00282 // Invalid rectangles are equal 00283 if ((!IsValid()) && (!R.IsValid())) 00284 return TRUE; 00285 00286 // Could use structure compare? Would it be portable? Probably not... 00287 00288 return ((lo.x == R.lo.x) && (lo.y == R.lo.y) && 00289 (hi.x == R.hi.x) && (hi.y == R.hi.y)); 00290 }
|
|
Splits a rectangle into sub-rectangles which all exclude the interecting rectangle R. The number of sub-rects generated depends on how the rectangles intersect. _______________________ ___________________ | | | | | *this A | | *this A | |_ _ _ ________ _ _ _ | |_ _ _ _ _ ________|__________ | | | | | | | | | B | R | C | | B | | | |_ _ _ |________| _ _ _ | |__________|________| R | | | | | | D Index=4 | | Index=2 | |_______________________| |___________________|.
Definition at line 346 of file userrect.cpp. 00347 { 00348 if (!this->IsIntersectedWith(R)) 00349 return 0; // No intersection 00350 00351 INT32 Index = 0; 00352 00353 if (R.hi.y < hi.y) 00354 SubRects[Index++] = UserRect(lo.x, R.hi.y, hi.x, hi.y); // Sub-Rect A 00355 00356 if (R.lo.y > lo.y) 00357 SubRects[Index++] = UserRect(lo.x, lo.y, hi.x, R.lo.y); // Sub-Rect D 00358 00359 INT32 Ry0 = max(R.lo.y, lo.y); 00360 INT32 Ry1 = min(R.hi.y, hi.y); 00361 00362 if (R.lo.x > lo.x) 00363 SubRects[Index++] = UserRect(lo.x, Ry0, R.lo.x, Ry1); // Sub-Rect B 00364 00365 if (R.hi.x < hi.x) 00366 SubRects[Index++] = UserRect(R.hi.x, Ry0, hi.x, Ry1); // Sub-Rect C 00367 00368 return Index; 00369 }
|
|
Convert a UserRect to a SpreadRect (AKA DocRect).
Definition at line 426 of file userrect.cpp.
|
|
Translate a rectangle by given offset.
Definition at line 245 of file userrect.h. 00246 { 00247 // Detect an invalid rectangle 00248 ENSURE(IsValid(), "UserRect::Translate() was called on an \ninvalid rectangle."); 00249 00250 lo.x += XOfs; 00251 lo.y += YOfs; 00252 00253 hi.x += XOfs; 00254 hi.y += YOfs; 00255 }
|
|
Compute union of two rectangles.
Definition at line 252 of file userrect.cpp. 00253 { 00254 // Special cases for invalid rectangles... 00255 if (!IsValid() || IsEmpty()) 00256 return R; 00257 if (!R.IsValid() || R.IsEmpty()) 00258 return *this; 00259 00260 // Return the result 00261 UserRect U; 00262 U.lo.x = min(lo.x, R.lo.x); 00263 U.lo.y = min(lo.y, R.lo.y); 00264 U.hi.x = max(hi.x, R.hi.x); 00265 U.hi.y = max(hi.y, R.hi.y); 00266 return U; 00267 }
|
|
To find the width of the UserRect.
Definition at line 575 of file userrect.h. 00576 { 00577 // Detect an invalid rectangle 00578 ENSURE(IsValid(), "UserRect::Width() was called on\nan invalid rectangle."); 00579 00580 return (hi.x - lo.x); 00581 }
|
|
Definition at line 168 of file userrect.h. |
|
Definition at line 168 of file userrect.h. |