#include <docrect.h>
Public Member Functions | |
DocRect () | |
To construct an empty DocRect. | |
DocRect (INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY) | |
To construct a DocRect with an inclusive lower left hand corner position of (Left, Lower) and an exclusive upper right hand corner position of (Right, Upper). | |
DocRect (const DocCoord &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. | |
DocRect (const DocCoord &Low, const DocCoord &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. | |
DocRect (const DocRect &DocRect) | |
Copy constructor. | |
DocRect & | operator= (const DocRect &DocRect) |
Equals operator. | |
INT32 | Width () const |
To find the width of the DocRect. | |
INT32 | Height () const |
To find the height of the DocRect. | |
DocCoord | LowCorner () const |
To find the lower left hand coordinates of the DocRect. | |
DocCoord | HighCorner () const |
To find the upper right hand coordinates of the DocRect. | |
DocCoord | Centre () const |
To find the centre of the DocRect It calculates DocCoord(lox+(width/2),loy+(height/2)). | |
BOOL | IsIntersectedWith (const DocRect &) const |
To check for rectangle intersection. | |
DocRect | Intersection (const DocRect &) const |
Compute intersection of two rectangles. | |
DocRect | Union (const DocRect &) const |
Compute union of two rectangles. | |
INT32 | SplitRect (const DocRect &R, DocRect *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 DocCoord &) const |
To check for coordinate containment. | |
BOOL | ContainsRectCoord (const DocCoord &) 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 DocRect &) const |
To check for rectangle containment. | |
BOOL | IsAdjacent (const DocRect &, 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 DocCoord &) |
Expand a rectangle so that it includes the given point. | |
INT32 | operator== (const DocRect &) 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 DocRect &) 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, View *pView) |
Convert a DocRect to a SpreadRect (AKA DocRect). | |
DocRect | ToDoc (Spread *pSpread, View *pView) |
Convert a SpreadRect (AKA DocRect) to a DocRect. | |
UserRect | ToUser (Spread *pSpread) |
Convert a SpreadRect (AKA DocRect) to a UserRect. | |
OilRect | ToOil (Spread *pSpread, View *pView) |
Convert a SpreadRect (AKA DocRect) to an OilRect. | |
Public Attributes | |
DocCoord | lo |
DocCoord | 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 165 of file docrect.h.
|
To construct an empty DocRect.
Definition at line 411 of file docrect.h.
|
|
To construct a DocRect 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 442 of file docrect.h. 00443 { 00444 // Defensive programming, detect an invalid rectangle 00445 ENSURE((LowX <= HighX) && (LowY <= HighY), 00446 "DocRect::DocRect(INT32, INT32, INT32, INT32) was\n passed invalid coordinates"); 00447 00448 lo.x = LowX; 00449 lo.y = LowY; 00450 00451 hi.x = HighX; 00452 hi.y = HighY; 00453 }
|
|
To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified.
Definition at line 507 of file docrect.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 477 of file docrect.h. 00478 { 00479 // Defensive programming, detect an invalid rectangle 00480 ENSURE((Low.x <= High.x) && (Low.y <= High.y), 00481 "DocRect::DocRect(DocCoord, DocCoord) was passed invalid coordinates"); 00482 00483 lo = Low; 00484 hi = High; 00485 }
|
|
Copy constructor.
Definition at line 532 of file docrect.h.
|
|
To find the centre of the DocRect It calculates DocCoord(lox+(width/2),loy+(height/2)).
Definition at line 680 of file docrect.h. 00681 { 00682 // Detect an invalid rectangle 00683 ENSURE(IsValid(), "DocRect::Centre() was called on\nan invalid rectangle."); 00684 00685 return DocCoord(lo.x + Width() / 2, lo.y + Height() / 2); 00686 }
|
|
To check for coordinate containment.
Definition at line 738 of file docrect.h. 00739 { 00740 // Check for an an empty rectangle 00741 if (IsEmpty()) 00742 return FALSE; 00743 00744 // Detect an invalid rectangle 00745 ENSURE(IsValid(), "DocRect::ContainsCoord() was called on\nan invalid rectangle."); 00746 00747 return ((Point.x >= lo.x) && (Point.x < hi.x) && 00748 (Point.y >= lo.y) && (Point.y < hi.y)); 00749 }
|
|
To check for rectangle containment.
Definition at line 808 of file docrect.h. 00809 { 00810 // Check for an an empty rectangle 00811 if (IsEmpty()) 00812 return FALSE; 00813 00814 // Detect an invalid rectangle 00815 ENSURE(IsValid(), "DocRect::ContainsRect() was called on\nan invalid rectangle."); 00816 00817 return ((Rect.lo.x >= lo.x) && (Rect.hi.x <= hi.x) && 00818 (Rect.lo.y >= lo.y) && (Rect.hi.y <= hi.y)); 00819 }
|
|
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 774 of file docrect.h. 00775 { 00776 // Check for an an empty rectangle 00777 if (IsEmpty()) 00778 return FALSE; 00779 00780 // Detect an invalid rectangle 00781 ENSURE(IsValid(), "DocRect::ContainsRectCoord() was called on\nan invalid rectangle."); 00782 00783 return ((Point.x >= lo.x) && (Point.x <= hi.x) && 00784 (Point.y >= lo.y) && (Point.y <= hi.y)); 00785 }
|
|
To find the height of the DocRect.
Definition at line 602 of file docrect.h. 00603 { 00604 // Detect an invalid rectangle 00605 ENSURE(IsValid(), "DocRect::Height() was called on\nan invalid rectangle."); 00606 00607 return(hi.y - lo.y); 00608 }
|
|
To find the upper right hand coordinates of the DocRect.
Definition at line 653 of file docrect.h. 00654 { 00655 // Detect an invalid rectangle 00656 ENSURE(IsValid(), "DocRect::HighCorner() was called on\nan invalid rectangle."); 00657 00658 return(hi); 00659 }
|
|
Expand a rectangle so that it includes the given point.
Definition at line 388 of file docrect.cpp. 00389 { 00390 // Detect an invalid rectangle 00391 ENSURE(IsValid(), "DocRect::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 380 of file docrect.h. 00381 { 00382 // Detect an invalid rectangle 00383 ENSURE(IsValid(), "DocRect::Inflate(INT32) was called on an \ninvalid rectangle."); 00384 00385 lo.x -= Inc; 00386 lo.y -= Inc; 00387 00388 hi.x += Inc; 00389 hi.y += Inc; 00390 }
|
|
Inflate a rectangle by given amounts. Negative values will deflate the rectangle.
Definition at line 348 of file docrect.h. 00349 { 00350 // Detect an invalid rectangle 00351 ENSURE(IsValid(), "DocRect::Inflate(INT32, INT32) was called on an \ninvalid rectangle."); 00352 00353 lo.x -= XInc; 00354 lo.y -= YInc; 00355 00356 hi.x += XInc; 00357 hi.y += YInc; 00358 }
|
|
Compute intersection of two rectangles.
Definition at line 293 of file docrect.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 DocRect 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 docrect.cpp. 00189 { 00190 // Check for an an empty rectangle 00191 if (IsEmpty()) 00192 return FALSE; 00193 00194 // Detect an invalid rectangle 00195 ENSURE(IsValid(), "DocRect::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 858 of file docrect.h.
|
|
To check for rectangle intersection.
Definition at line 707 of file docrect.h. 00708 { 00709 // Detect an invalid rectangle 00710 if ((!IsValid()) || (!R.IsValid())) 00711 return FALSE; 00712 00713 return ((hi.x > R.lo.x) && (lo.x < R.hi.x) && 00714 (hi.y > R.lo.y) && (lo.y < R.hi.y)); 00715 }
|
|
To check for a valid rectangle.
Definition at line 882 of file docrect.h.
|
|
To find the lower left hand coordinates of the DocRect.
Definition at line 627 of file docrect.h. 00628 { 00629 // Detect an invalid rectangle 00630 ENSURE(IsValid(), "DocRect::LowCorner() was called on\nan invalid rectangle."); 00631 00632 return(lo); 00633 }
|
|
Make the rectangle an empty one (all coordinates are set to 0).
Definition at line 834 of file docrect.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 318 of file docrect.h. 00319 { 00320 // Invalid rectangles are equal 00321 if ((!IsValid()) && (!R.IsValid())) 00322 return FALSE; 00323 00324 return ((lo.x != R.lo.x) || (lo.y != R.lo.y) || 00325 (hi.x != R.hi.x) || (hi.y != R.hi.y)); 00326 }
|
|
Equals operator.
Definition at line 554 of file docrect.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 283 of file docrect.h. 00284 { 00285 // Invalid rectangles are equal 00286 if ((!IsValid()) && (!R.IsValid())) 00287 return TRUE; 00288 00289 // Could use structure compare? Would it be portable? Probably not... 00290 00291 return ((lo.x == R.lo.x) && (lo.y == R.lo.y) && 00292 (hi.x == R.hi.x) && (hi.y == R.hi.y)); 00293 }
|
|
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 docrect.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++] = DocRect(lo.x, R.hi.y, hi.x, hi.y); // Sub-Rect A 00355 00356 if (R.lo.y > lo.y) 00357 SubRects[Index++] = DocRect(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++] = DocRect(lo.x, Ry0, R.lo.x, Ry1); // Sub-Rect B 00364 00365 if (R.hi.x < hi.x) 00366 SubRects[Index++] = DocRect(R.hi.x, Ry0, hi.x, Ry1); // Sub-Rect C 00367 00368 return Index; 00369 }
|
|
Convert a SpreadRect (AKA DocRect) to a DocRect.
Definition at line 447 of file docrect.cpp. 00448 { 00449 return DocRect( this->lo.ToDoc(pSpread,pView), this->hi.ToDoc(pSpread,pView) ); 00450 }
|
|
Convert a SpreadRect (AKA DocRect) to an OilRect.
Definition at line 480 of file docrect.cpp. 00481 { 00482 return OilRect( this->lo.ToOil(pSpread,pView), this->hi.ToOil(pSpread,pView) ); 00483 }
|
|
Convert a DocRect to a SpreadRect (AKA DocRect).
Definition at line 430 of file docrect.cpp. 00431 { 00432 return DocRect( this->lo.ToSpread(pSpread,pView), this->hi.ToSpread(pSpread,pView) ); 00433 }
|
|
Convert a SpreadRect (AKA DocRect) to a UserRect.
Definition at line 463 of file docrect.cpp.
|
|
Translate a rectangle by given offset.
Definition at line 248 of file docrect.h. 00249 { 00250 // Detect an invalid rectangle 00251 ENSURE(IsValid(), "DocRect::Translate() was called on an \ninvalid rectangle."); 00252 00253 lo.x += XOfs; 00254 lo.y += YOfs; 00255 00256 hi.x += XOfs; 00257 hi.y += YOfs; 00258 }
|
|
Compute union of two rectangles.
Definition at line 252 of file docrect.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 DocRect 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 DocRect.
Definition at line 578 of file docrect.h. 00579 { 00580 // Detect an invalid rectangle 00581 ENSURE(IsValid(), "DocRect::Width() was called on\nan invalid rectangle."); 00582 00583 return (hi.x - lo.x); 00584 }
|
|
|
|
|