UserRect Class Reference

This class is used to represent a rectangular region. It uses a union to enable the client to access the rectangle as two UserCoords (lo and hi) or as four INT32s (lox, loy, hix, hiy). An anonymous union is used, which is a defined C++ feature and so portable. More...

#include <userrect.h>

List of all members.

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.
UserRectoperator= (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


Detailed Description

This class is used to represent a rectangular region. It uses a union to enable the client to access the rectangle as two UserCoords (lo and hi) or as four INT32s (lox, loy, hix, hiy). An anonymous union is used, which is a defined C++ feature and so portable.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> Date: 11/5/93
The lo coordinates are inclusive, whilst the hi coordinates are exclusive. In the document space, lo.y <= hi.y and lo.x <= hi.x (the inequalities are not strict because rectangles can have zero width and/or height - such rectangles are considered perfectly valid).

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.

Returns:
Errors: -
See also:
UserCoord

Rect

DocRect

WorkRect

OSRect

Definition at line 164 of file userrect.h.


Constructor & Destructor Documentation

UserRect::UserRect  )  [inline]
 

To construct an empty UserRect.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
None [INPUTS]
- [OUTPUTS]
Returns:
-

Errors:

Definition at line 408 of file userrect.h.

00409 {
00410     // An empty rectangle
00411     hi.x = hi.y = lo.x = lo.y = 0;
00412 }

UserRect::UserRect INT32  LowX,
INT32  LowY,
INT32  HighX,
INT32  HighY
[inline]
 

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).

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
LowX : Lower X coord of rectangle (inclusive) [INPUTS] HighX: Higher X coord of rectangle (exclusive) LowY : Lower Y coord of rectangle (inclusive) HighY: Higher Y coord of rectangle (exclusive)
- [OUTPUTS]
Returns:
-

Errors: An assertion failure will occur if the lower left hand coordinates are not lower than and to the left of the upper right coordinate.

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 } 

UserRect::UserRect const UserCoord Low,
UINT32  Width,
UINT32  Height
[inline]
 

To construct a rectangle with an inclusive lower left hand corner position of Low and a width and height as specified.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
Low,: UserCoordinates of the inclusive lower left hand corner. [INPUTS] Width, Height : Desired dimensions of the rectangle.
- [OUTPUTS]
Returns:
-

Errors: None.

Definition at line 504 of file userrect.h.

00505 {         
00506     lo = Low;
00507     
00508     hi.x = lo.x + Width;
00509     hi.y = lo.y + Height;
00510 }       

UserRect::UserRect const UserCoord Low,
const UserCoord High
[inline]
 

To construct a rectangle with an inclusive lower left hand corner position of Low and an exclusive upper right hand corner position of High.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
Low : UserCoordinates of the lower left hand corner (inclusive) [INPUTS] High: UserCoordinates of the upper right hand corner (exclusive)
- [OUTPUTS]
Returns:
-

Errors: An assertion failure will occur if the lower left hand coordinates are not lower than and to the left of the upper right coordinates.

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 }       

UserRect::UserRect const UserRect R  )  [inline]
 

Copy constructor.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
R,: The copy of the UserRect [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 529 of file userrect.h.

00530 {
00531     lo = R.lo;
00532     hi = R.hi;
00533 }


Member Function Documentation

UserCoord UserRect::Centre  )  const [inline]
 

To find the centre of the UserRect It calculates UserCoord(lox+(width/2),loy+(height/2)).

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/5/99
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The centre coord of this UserRect

Errors: Assertion failure if the rectangle is invalid.

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 }        

BOOL UserRect::ContainsCoord const UserCoord Point  )  const [inline]
 

To check for coordinate containment.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the coordinate is within the rectangle, FALSE otherwise.

Errors: Assertion failure if the rectangle is invalid.

See also:
ContainsRectCoord; ContainsRect

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 }

BOOL UserRect::ContainsRect const UserRect Rect  )  const [inline]
 

To check for rectangle containment.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the rectangle 'Rect' is within the rectangle, FALSE otherwise.

Errors: Assertion failure if the rectangle is invalid.

See also:
ContainsRectCoord; ContainsCoord

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 }

BOOL UserRect::ContainsRectCoord const UserCoord Point  )  const [inline]
 

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).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the coordinate is within the rectangle, FALSE otherwise.

Errors: Assertion failure if the rectangle is invalid.

See also:
ContainsCoord; ContainsRect

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 }

INT32 UserRect::Height  )  const [inline]
 

To find the height of the UserRect.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
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 }

UserCoord UserRect::HighCorner  )  const [inline]
 

To find the upper right hand coordinates of the UserRect.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The exclusive upper right hand coordinates of the UserRect

Errors: Assertion failure if the rectangle is invalid.

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 }                  

void UserRect::IncludePoint const UserCoord Point  ) 
 

Expand a rectangle so that it includes the given point.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/5/93
Parameters:
Point - coordinate to include into this rectangle. [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: An assertion failure if the rectangle is invalid.

See also:
-

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 }

void UserRect::Inflate INT32  Inc  )  [inline]
 

Inflate a rectangle by given amount. Negative values will deflate the rectangle.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
Inc - the amount to inflate (or deflate) the rectangle by. [INPUTS]
- [OUTPUTS]
Returns:
N/A.

Errors: An assertion failure if the rectangle is invalid.

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 }

void UserRect::Inflate INT32  XInc,
INT32  YInc
[inline]
 

Inflate a rectangle by given amounts. Negative values will deflate the rectangle.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
XInc,YInc - the amount to inflate (or deflate) the rectangle by. [INPUTS]
- [OUTPUTS]
Returns:
N/A.

Errors: An assertion failure if the rectangle is invalid.

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 }

UserRect UserRect::Intersection const UserRect R  )  const
 

Compute intersection of two rectangles.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
R - the rectangle to intersect with. [INPUTS]
- [OUTPUTS]
Returns:
The intersection.
If one of the rectangles involved is invalid, the other is returned as the result. In the case of both being invalid, one of the invalid rectangles is returned as the result. It is undefined which rectangle is returned in this case.

Returns:
Errors: None.

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 }

BOOL UserRect::IsAdjacent const UserRect Rect,
MILLIPOINT  Fuzzy
const
 

To check for adjacent rectangles.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/93
Parameters:
The Fuzzy limit in MILLIPOINTS. [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the rectangles are adjacent within a Fuzzy limit.

Errors:

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 }

BOOL UserRect::IsEmpty  )  const [inline]
 

To check for empty rectangle.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the rectangle is empty.

Errors:

Definition at line 855 of file userrect.h.

00856 {
00857     return ((lo.x == hi.x) || (lo.y == hi.y));
00858 }

BOOL UserRect::IsIntersectedWith const UserRect R  )  const [inline]
 

To check for rectangle intersection.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the rectangles intersect, FALSE otherwise.

Errors:

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 }

BOOL UserRect::IsValid  )  const [inline]
 

To check for a valid rectangle.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/6/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the rectangle is valid.

Errors:

Definition at line 879 of file userrect.h.

00880 {
00881     return ((lo.x <= hi.x) && (lo.y <= hi.y));
00882 }

UserCoord UserRect::LowCorner  )  const [inline]
 

To find the lower left hand coordinates of the UserRect.

Returns:
Errors: Assertion failure if the rectangle is invalid.

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 }        

void UserRect::MakeEmpty  )  [inline]
 

Make the rectangle an empty one (all coordinates are set to 0).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
03/03/94
See also:
UserRect::MakeEmpty

Definition at line 831 of file userrect.h.

00832 {
00833   lo.x = lo.y = hi.x = hi.y = 0;
00834 }

INT32 UserRect::operator!= const UserRect R  )  const [inline]
 

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.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
R - the rectangle to compare against. [INPUTS]
- [OUTPUTS]
Returns:
TRUE if R does not describe the same rectangle as the object.
Friend: UserRect

Returns:
Errors: None.

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 }

UserRect & UserRect::operator= const UserRect UserRect  )  [inline]
 

Equals operator.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
UserRect,: UserRect to copy [INPUTS]
- [OUTPUTS]
Returns:
Reference to this UserRect

Definition at line 551 of file userrect.h.

00552 {                                                    
00553     lo = UserRect.lo; 
00554     hi = UserRect.hi;
00555     
00556     return *this; 
00557 }

INT32 UserRect::operator== const UserRect R  )  const [inline]
 

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.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
R - the rectangle to compare against. [INPUTS]
- [OUTPUTS]
Returns:
TRUE if R is describes the same rectangle as the object.
Friend: UserRect

Returns:
Errors: None.

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 }

INT32 UserRect::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 | |_______________________| |___________________|.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/93
Parameters:
R is the rectangle to intersect with, SubRects is an array of UserRect to fill. [INPUTS]
Puts any sub-rects into SubRects. [OUTPUTS]
Returns:
The number of subrectangles found. 0 for no intersection.

Errors:

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 }

DocRect UserRect::ToSpread Spread pSpread  ) 
 

Convert a UserRect to a SpreadRect (AKA DocRect).

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/95
Parameters:
pSpread - [INPUTS]
Returns:
SpreadRect

Definition at line 426 of file userrect.cpp.

00427 {
00428     return DocRect( this->lo.ToSpread(pSpread), this->hi.ToSpread(pSpread) );
00429 }

void UserRect::Translate INT32  XOfs,
INT32  YOfs
[inline]
 

Translate a rectangle by given offset.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
(XOfs,YOfs) - the offset to translate the rectangle by. [INPUTS]
- [OUTPUTS]
Returns:
N/A.

Errors: An assertion failure if the rectangle is invalid.

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 }

UserRect UserRect::Union const UserRect R  )  const
 

Compute union of two rectangles.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/5/93
Parameters:
R - the rectangle to join with the object. [INPUTS]
- [OUTPUTS]
Returns:
The simple union (bounding box).
If one of the rectangles involved is invalid, the other is returned as the result. In the case of both being invalid, one of the invalid rectangles is returned as the result. It is undefined which rectangle is returned in this case.

Returns:
Errors: None.

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 }

INT32 UserRect::Width  )  const [inline]
 

To find the width of the UserRect.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/5/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
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 }       


Member Data Documentation

UserCoord UserRect::hi
 

Definition at line 168 of file userrect.h.

UserCoord UserRect::lo
 

Definition at line 168 of file userrect.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:02:45 2007 for Camelot by  doxygen 1.4.4