DocRect 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 DocCoords (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 <docrect.h>

List of all members.

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


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 DocCoords (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:
DocCoord

Rect

DocRect

WorkRect

OSRect

Definition at line 165 of file docrect.h.


Constructor & Destructor Documentation

DocRect::DocRect  )  [inline]
 

To construct an empty DocRect.

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

Errors:

Definition at line 411 of file docrect.h.

00412 {
00413     // An empty rectangle
00414     hi.x = hi.y = lo.x = lo.y = 0;
00415 }

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

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

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 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 } 

DocRect::DocRect const DocCoord 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,: DocCoordinates of the inclusive lower left hand corner. [INPUTS] Width, Height : Desired dimensions of the rectangle.
- [OUTPUTS]
Returns:
-

Errors: None.

Definition at line 507 of file docrect.h.

00508 {         
00509     lo = Low;
00510     
00511     hi.x = lo.x + Width;
00512     hi.y = lo.y + Height;
00513 }       

DocRect::DocRect const DocCoord Low,
const DocCoord 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 : DocCoordinates of the lower left hand corner (inclusive) [INPUTS] High: DocCoordinates 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 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 }       

DocRect::DocRect const DocRect R  )  [inline]
 

Copy constructor.

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

Definition at line 532 of file docrect.h.

00533 {
00534     lo = R.lo;
00535     hi = R.hi;
00536 }


Member Function Documentation

DocCoord DocRect::Centre  )  const [inline]
 

To find the centre of the DocRect It calculates DocCoord(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 DocRect

Errors: Assertion failure if the rectangle is invalid.

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 }        

BOOL DocRect::ContainsCoord const DocCoord 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 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 }

BOOL DocRect::ContainsRect const DocRect 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 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 }

BOOL DocRect::ContainsRectCoord const DocCoord 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 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 }

INT32 DocRect::Height  )  const [inline]
 

To find the height of the DocRect.

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

DocCoord DocRect::HighCorner  )  const [inline]
 

To find the upper right hand coordinates of the DocRect.

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 DocRect

Errors: Assertion failure if the rectangle is invalid.

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 }                  

void DocRect::IncludePoint const DocCoord 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 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 }

void DocRect::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 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 }

void DocRect::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 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 }

DocRect DocRect::Intersection const DocRect 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 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 }

BOOL DocRect::IsAdjacent const DocRect 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 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 }

BOOL DocRect::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 858 of file docrect.h.

00859 {
00860     return ((lo.x == hi.x) || (lo.y == hi.y));
00861 }

BOOL DocRect::IsIntersectedWith const DocRect 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 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 }

BOOL DocRect::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 882 of file docrect.h.

00883 {
00884     return ((lo.x <= hi.x) && (lo.y <= hi.y));
00885 }

DocCoord DocRect::LowCorner  )  const [inline]
 

To find the lower left hand coordinates of the DocRect.

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

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 }        

void DocRect::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:
DocRect::MakeEmpty

Definition at line 834 of file docrect.h.

00835 {
00836   lo.x = lo.y = hi.x = hi.y = 0;
00837 }

INT32 DocRect::operator!= const DocRect 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: DocRect

Returns:
Errors: None.

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 }

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

Equals operator.

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

Definition at line 554 of file docrect.h.

00555 {                                                    
00556     lo = DocRect.lo; 
00557     hi = DocRect.hi;
00558     
00559     return *this; 
00560 }

INT32 DocRect::operator== const DocRect 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: DocRect

Returns:
Errors: None.

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 }

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

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 DocRect 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 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 }

DocRect DocRect::ToDoc Spread pSpread,
View pView
 

Convert a SpreadRect (AKA DocRect) to a DocRect.

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

Definition at line 447 of file docrect.cpp.

00448 {
00449     return DocRect( this->lo.ToDoc(pSpread,pView), this->hi.ToDoc(pSpread,pView) );
00450 }

OilRect DocRect::ToOil Spread pSpread,
View pView
 

Convert a SpreadRect (AKA DocRect) to an OilRect.

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

Definition at line 480 of file docrect.cpp.

00481 {
00482     return OilRect( this->lo.ToOil(pSpread,pView), this->hi.ToOil(pSpread,pView) );
00483 }

DocRect DocRect::ToSpread Spread pSpread,
View pView
 

Convert a DocRect to a SpreadRect (AKA DocRect).

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

Definition at line 430 of file docrect.cpp.

00431 {
00432     return DocRect( this->lo.ToSpread(pSpread,pView), this->hi.ToSpread(pSpread,pView) );
00433 }

UserRect DocRect::ToUser Spread pSpread  ) 
 

Convert a SpreadRect (AKA DocRect) to a UserRect.

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

Definition at line 463 of file docrect.cpp.

00464 {
00465     return UserRect( this->lo.ToUser(pSpread), this->hi.ToUser(pSpread) );
00466 }

void DocRect::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 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 }

DocRect DocRect::Union const DocRect 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 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 }

INT32 DocRect::Width  )  const [inline]
 

To find the width of the DocRect.

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


Member Data Documentation

DocCoord DocRect::hi
 

Definition at line 169 of file docrect.h.

DocCoord DocRect::lo
 

Definition at line 168 of file docrect.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:44 2007 for Camelot by  doxygen 1.4.4