WorkRect 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 WorkCoords (lo and hi) or as four XLONGs (lox, loy, hix, hiy). An anonymous union is used, which is a defined C++ feature and so portable. More...

#include <wrkrect.h>

List of all members.

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


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 WorkCoords (lo and hi) or as four XLONGs (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:
WorkCoord

Rect

DocRect

WorkRect

OSRect

Definition at line 160 of file wrkrect.h.


Constructor & Destructor Documentation

WorkRect::WorkRect  )  [inline]
 

To construct an empty WorkRect.

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

Errors:

Definition at line 400 of file wrkrect.h.

00401 {
00402     // An empty rectangle
00403     hi.x = hi.y = lo.x = lo.y = 0;
00404 }

WorkRect::WorkRect XLONG  LowX,
XLONG  LowY,
XLONG  HighX,
XLONG  HighY
[inline]
 

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

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

WorkRect::WorkRect const WorkCoord Low,
XLONG  Width,
XLONG  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,: WorkCoordinates of the inclusive lower left hand corner. [INPUTS] Width, Height : Desired dimensions of the rectangle.
- [OUTPUTS]
Returns:
-

Errors: None.

Definition at line 496 of file wrkrect.h.

00497 {         
00498     lo = Low;
00499     
00500     hi.x = lo.x + Width;
00501     hi.y = lo.y + Height;
00502 }       

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

WorkRect::WorkRect const WorkRect R  )  [inline]
 

Copy constructor.

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

Definition at line 521 of file wrkrect.h.

00522 {
00523     lo = R.lo;
00524     hi = R.hi;
00525 }


Member Function Documentation

WorkCoord WorkRect::Centre  )  const [inline]
 

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

Errors: Assertion failure if the rectangle is invalid.

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 }        

BOOL WorkRect::ContainsCoord const WorkCoord 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 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 }

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

BOOL WorkRect::ContainsRectCoord const WorkCoord 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 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 }

XLONG WorkRect::Height  )  const [inline]
 

To find the height of the WorkRect.

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

WorkCoord WorkRect::HighCorner  )  const [inline]
 

To find the upper right hand coordinates of the WorkRect.

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 WorkRect

Errors: Assertion failure if the rectangle is invalid.

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 }                  

void WorkRect::IncludePoint const WorkCoord  ) 
 

void WorkRect::Inflate XLONG  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 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 }

void WorkRect::Inflate XLONG  XInc,
XLONG  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 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 }

WorkRect WorkRect::Intersection const WorkRect  )  const
 

BOOL WorkRect::IsAdjacent const WorkRect ,
MILLIPOINT  Fuzzy
const
 

BOOL WorkRect::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 847 of file wrkrect.h.

00848 {
00849     return ((lo.x == hi.x) || (lo.y == hi.y));
00850 }

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

BOOL WorkRect::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 871 of file wrkrect.h.

00872 {
00873     return ((lo.x <= hi.x) && (lo.y <= hi.y));
00874 }

WorkCoord WorkRect::LowCorner  )  const [inline]
 

To find the lower left hand coordinates of the WorkRect.

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

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 }        

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

Definition at line 823 of file wrkrect.h.

00824 {
00825   lo.x = lo.y = hi.x = hi.y = 0;
00826 }

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

Returns:
Errors: None.

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 }

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

Equals operator.

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

Definition at line 543 of file wrkrect.h.

00544 {                                                    
00545     lo = WorkRect.lo; 
00546     hi = WorkRect.hi;
00547     
00548     return *this; 
00549 }

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

Returns:
Errors: None.

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 }

INT32 WorkRect::SplitRect const WorkRect R,
WorkRect SubRects
 

void WorkRect::Translate XLONG  XOfs,
XLONG  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 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 }

WorkRect WorkRect::Union const WorkRect  )  const
 

XLONG WorkRect::Width  )  const [inline]
 

To find the width of the WorkRect.

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


Member Data Documentation

WorkCoord WorkRect::hi
 

Definition at line 165 of file wrkrect.h.

WorkCoord WorkRect::lo
 

Definition at line 164 of file wrkrect.h.


The documentation for this class was generated from the following file:
Generated on Sat Nov 10 04:03:12 2007 for Camelot by  doxygen 1.4.4