rect.h

Go to the documentation of this file.
00001 // $Id: rect.h 751 2006-03-31 15:43:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099       
00100 #ifndef INC_RECT
00101 #define INC_RECT
00102 
00103 #include "coord.h"
00104 
00105 /***********************************************************************************************
00106 
00107 >    Class Rect
00108 
00109      Author:       Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00110      Date:         11/5/93
00111      
00112      Purpose:      This class is used to represent a rectangular region.  It uses a union to
00113                    enable the client to access the rectangle as two Coords (lo and hi) or as
00114                    four INT32s (lox, loy, hix, hiy).  An anonymous union is used, which is a
00115                    defined C++ feature and so portable.
00116 
00117                    The lo coordinates are inclusive, whilst the hi coordinates are exclusive.
00118                    In the document space, lo.y <= hi.y and lo.x <= hi.x (the inequalities are 
00119                    not strict because rectangles can have zero width and/or height - such
00120                    rectangles are considered perfectly valid). 
00121                    
00122                    The inclusivity can be explained as follows:
00123                    
00124                    A point at (lo.x, lo.y) is inside the rectangle
00125                    A point at (hi.x, hi.y) is outside the rectangle
00126                    
00127                    Any rectangle that does not obey the inequalites lo.y <= hi.y and 
00128                    lo.x <= hi.x is deemed to be 'invalid'.  Invalid rectangles have special
00129                    properties.  They will cause errors when used in some operations, but not
00130                    in others.  The general rule is that if the rectangle is used as an entity,
00131                    then the operation will succeed (taking account of the 'invalidity' of
00132                    the rectangle).  If, however, the actual coordinates of the invalid
00133                    rectangle must be used/changed in the operation, then an error (usually an
00134                    assertion failure) will occur.
00135                    
00136                    For example, using invalid rectangles in Unions and Intersections is ok, 
00137                    because the invalid rectangle is ignored, and the 'other' rectangle is
00138                    returned as the result.  This means that if both rectangles are invalid,
00139                    then an invalid rectangle is returned.
00140                    
00141                    Conversely, trying to use operations like Translate(), Inflate(), Width()
00142                    or Height() on invalid rectangles is considered to be an error, and will
00143                    cause an assertion failure.
00144                    
00145                    See the individual function descriptions for more details.
00146                    
00147                    
00148      Errors:       -
00149 
00150      SeeAlso:      Coord
00151 
00152      SeeAlso:      Rect
00153      SeeAlso:      DocRect
00154      SeeAlso:      WorkRect
00155      SeeAlso:      OSRect
00156                     
00157 ***********************************************************************************************/
00158 
00159 class CAMAPI Rect
00160 {   
00161 public:
00162 
00163     Coord               lo;
00164     Coord               hi;
00165                             
00166     // Rect constructors
00167                         
00168     Rect();              
00169 
00170     Rect(INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY); 
00171 
00172     Rect(const Coord& Low, UINT32 Width, UINT32 Height); 
00173 
00174     Rect(const Coord& Low, const Coord& High);   
00175                      
00176     Rect(const Rect& Rect); // Copy constructor
00177 
00178     Rect& operator=(const Rect& Rect);// Assignment operator
00179                      
00180     INT32 Width() const;
00181     INT32 Height() const; 
00182     
00183     Coord LowCorner() const;
00184     Coord HighCorner() const;  
00185 
00186     Coord Centre() const;
00187     
00188     // General operations type stuff
00189     BOOL IsIntersectedWith(const Rect&) const;
00190     Rect Intersection(const Rect&) const;
00191     Rect Union(const Rect&) const;
00192     INT32 SplitRect(const Rect& R, Rect* SubRects);
00193 
00194     BOOL ContainsCoord(const Coord&) const;
00195     BOOL ContainsRectCoord(const Coord&) const;
00196     BOOL ContainsRect(const Rect&) const;
00197     BOOL IsAdjacent(const Rect&, MILLIPOINT Fuzzy) const;
00198 
00199     void MakeEmpty();
00200         
00201     BOOL IsEmpty() const;   
00202     BOOL IsValid() const;   
00203 
00204     void Inflate(INT32 XInc, INT32 YInc);
00205     void Inflate(INT32 XInc);
00206     void Translate(INT32 XOfs, INT32 YOfs);
00207     void IncludePoint(const Coord&);
00208     
00209     // Overloaded operators
00210     INT32 operator==(const Rect&) const;
00211     INT32 operator!=(const Rect&) const;
00212 
00213 
00214 };                                            
00215 
00216 
00217   
00218 /*********************************************************************************************
00219 
00220 >    void Rect::Translate(INT32 XOfs, INT32 YOfs)
00221 
00222      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00223      Created:   17/5/93
00224      Inputs:    (XOfs, YOfs) - the offset to translate the rectangle by.
00225      Outputs:   - 
00226      
00227      Returns:   N/A.
00228                 
00229      Purpose:   Translate a rectangle by given offset.
00230 
00231      Errors:    An assertion failure if the rectangle is invalid.
00232 
00233 **********************************************************************************************/  
00234 
00235 inline void Rect::Translate(INT32 XOfs, INT32 YOfs)
00236 {
00237     // Detect an invalid rectangle
00238     ENSURE(IsValid(), "Rect::Translate() was called on an \ninvalid rectangle.");  
00239 
00240     lo.x += XOfs;
00241     lo.y += YOfs;
00242     
00243     hi.x += XOfs;
00244     hi.y += YOfs;
00245 }
00246 
00247 
00248 
00249 /*********************************************************************************************
00250 
00251 >    INT32 operator==(const Rect& R) const
00252 
00253      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00254      Created:   17/5/93
00255      Inputs:    R - the rectangle to compare against.
00256      Outputs:   - 
00257      
00258      Returns:   TRUE if R is describes the same rectangle as the object.
00259                 
00260      Purpose:   Test for equality of two rectangles.  As all invalid rectangles have the
00261                 same results when used for Union/Intersection, any two invalid rectangles
00262                 are considered equal.
00263 
00264      Friend:    Rect
00265      
00266      Errors:    None.
00267 
00268 **********************************************************************************************/  
00269 
00270 inline INT32 Rect::operator==(const Rect& R) const
00271 {
00272     // Invalid rectangles are equal
00273     if ((!IsValid()) && (!R.IsValid()))
00274         return TRUE;
00275         
00276     // Could use structure compare? Would it be portable? Probably not...
00277     
00278     return ((lo.x == R.lo.x) && (lo.y == R.lo.y) &&
00279             (hi.x == R.hi.x) && (hi.y == R.hi.y));
00280 }
00281 
00282 
00283 
00284 /*********************************************************************************************
00285 
00286 >    INT32 operator!=(const Rect& R) const
00287 
00288      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00289      Created:   17/5/93
00290      Inputs:    R - the rectangle to compare against.
00291      Outputs:   - 
00292      
00293      Returns:   TRUE if R does not describe the same rectangle as the object.
00294                 
00295      Purpose:   Test for inequality of two rectangles.  As all invalid rectangles have the
00296                 same results when used for Union/Intersection, any two invalid rectangles
00297                 are considered equal.
00298 
00299      Friend:    Rect
00300      
00301      Errors:    None.
00302 
00303 **********************************************************************************************/  
00304 
00305 inline INT32 Rect::operator!=(const Rect& R) const
00306 {
00307     // Invalid rectangles are equal
00308     if ((!IsValid()) && (!R.IsValid()))
00309         return FALSE;
00310         
00311     return ((lo.x != R.lo.x) || (lo.y != R.lo.y) ||
00312             (hi.x != R.hi.x) || (hi.y != R.hi.y));
00313 }
00314 
00315 
00316 
00317 /*********************************************************************************************
00318 
00319 >    void Rect::Inflate(INT32 XInc, INT32 YInc)
00320 
00321      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00322      Created:   17/5/93
00323      Inputs:    XInc, YInc - the amount to inflate (or deflate) the rectangle by.
00324      Outputs:   - 
00325      
00326      Returns:   N/A.
00327                 
00328      Purpose:   Inflate a rectangle by given amounts.  Negative values will deflate the
00329                 rectangle.
00330 
00331      Errors:    An assertion failure if the rectangle is invalid.
00332 
00333 **********************************************************************************************/  
00334 
00335 inline void Rect::Inflate(INT32 XInc, INT32 YInc)
00336 {
00337     // Detect an invalid rectangle
00338     ENSURE(IsValid(), "Rect::Inflate(INT32, INT32) was called on an \ninvalid rectangle.");  
00339 
00340     lo.x -= XInc;
00341     lo.y -= YInc;
00342     
00343     hi.x += XInc;
00344     hi.y += YInc;
00345 }
00346 
00347 
00348 
00349 /*********************************************************************************************
00350 
00351 >    void Rect::Inflate(INT32 Inc)
00352 
00353      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00354      Created:   17/5/93
00355      Inputs:    Inc - the amount to inflate (or deflate) the rectangle by.
00356      Outputs:   - 
00357      
00358      Returns:   N/A.
00359                 
00360      Purpose:   Inflate a rectangle by given amount.  Negative values will deflate the
00361                 rectangle.
00362 
00363      Errors:    An assertion failure if the rectangle is invalid.
00364 
00365 **********************************************************************************************/  
00366 
00367 inline void Rect::Inflate(INT32 Inc)
00368 {
00369     // Detect an invalid rectangle
00370     ENSURE(IsValid(), "Rect::Inflate(INT32) was called on an \ninvalid rectangle.");  
00371 
00372     lo.x -= Inc;
00373     lo.y -= Inc;
00374     
00375     hi.x += Inc;
00376     hi.y += Inc;
00377 }
00378 
00379 
00380 
00381 /*********************************************************************************************
00382 
00383 >    Rect::Rect() 
00384 
00385      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00386      Created:   13/5/93
00387      Inputs:    None
00388      Outputs:   -
00389      Returns:   - 
00390                 
00391      Purpose:   To construct an empty Rect.
00392                 
00393 
00394      Errors:    
00395 
00396 **********************************************************************************************/  
00397 
00398 inline Rect::Rect()
00399 {
00400     // An empty rectangle
00401     hi.x = hi.y = lo.x = lo.y = 0;
00402 }
00403      
00404                 
00405 
00406 /*********************************************************************************************
00407            
00408 >    Rect::Rect(INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY)
00409 
00410      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00411      Created:   13/5/93
00412      Inputs:    LowX : Lower X coord of rectangle (inclusive)
00413                 HighX: Higher X coord of rectangle (exclusive) 
00414                 LowY : Lower Y coord of rectangle (inclusive)
00415                 HighY: Higher Y coord of rectangle (exclusive)
00416                 
00417      Outputs:   -
00418      Returns:   - 
00419                 
00420      Purpose:   To construct a Rect with an inclusive lower left hand corner 
00421                 position of (Left, Lower) and an exclusive upper right hand corner 
00422                 position of (Right, Upper).  
00423 
00424      Errors:    An assertion failure will occur if the lower left hand coordinates
00425                 are not lower than and to the left of the upper right coordinate. 
00426 
00427 **********************************************************************************************/  
00428                       
00429 inline Rect::Rect(INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY)
00430 {                               
00431     // Defensive programming, detect an invalid rectangle
00432     ENSURE((LowX <= HighX) && (LowY <= HighY),
00433            "Rect::Rect(INT32, INT32, INT32, INT32) was\n passed invalid coordinates");  
00434     
00435     lo.x = LowX;
00436     lo.y = LowY; 
00437     
00438     hi.x = HighX; 
00439     hi.y = HighY;   
00440 } 
00441 
00442 
00443 
00444 /*********************************************************************************************
00445            
00446 >    Rect::Rect(const Coord& Low, const Coord& High) 
00447 
00448      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00449      Created:   13/5/93
00450      Inputs:    Low : Coordinates of the lower left hand corner (inclusive) 
00451                 High: Coordinates of the upper right hand corner (exclusive)
00452      Outputs:   -
00453      Returns:   - 
00454                 
00455      Purpose:   To construct a rectangle with an inclusive lower left hand corner 
00456                 position of Low and an exclusive upper right hand corner
00457                 position of High.
00458 
00459      Errors:    An assertion failure will occur if the lower left hand coordinates
00460                 are not lower than and to the left of the upper right coordinates. 
00461 
00462 **********************************************************************************************/  
00463 
00464 inline Rect::Rect(const Coord& Low, const Coord& High)
00465 {         
00466     // Defensive programming, detect an invalid rectangle
00467     ENSURE((Low.x <= High.x) && (Low.y <= High.y),
00468            "Rect::Rect(Coord, Coord) was\n passed invalid coordinates");  
00469     
00470     lo = Low;
00471     hi = High;
00472 }       
00473     
00474 
00475 
00476 /*********************************************************************************************
00477            
00478 >    Rect::Rect(const Coord& Low, UINT32 Width, UINT32 Height) 
00479 
00480      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00481      Created:   17/5/93
00482      Inputs:    Low: Coordinates of the inclusive lower left hand corner.
00483                 Width, Height  : Desired dimensions of the rectangle.
00484      Outputs:   -
00485      Returns:   - 
00486                 
00487      Purpose:   To construct a rectangle with an inclusive lower left hand corner 
00488                 position of Low and a width and height as specified.
00489 
00490      Errors:    None.
00491      
00492 **********************************************************************************************/  
00493 
00494 inline Rect::Rect(const Coord& Low, UINT32 Width, UINT32 Height) 
00495 {         
00496     lo = Low;
00497     
00498     hi.x = lo.x + Width;
00499     hi.y = lo.y + Height;
00500 }       
00501    
00502    
00503     
00504        
00505 /*********************************************************************************************
00506            
00507 >    Rect::Rect(const Rect& R) 
00508 
00509      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00510      Created:   13/5/93
00511      Inputs:    R: The copy of the Rect 
00512      Outputs:   -
00513      Returns:   - 
00514                 
00515      Purpose:   Copy constructor 
00516 
00517 **********************************************************************************************/  
00518 
00519 inline Rect::Rect(const Rect& R)
00520 {
00521     lo = R.lo;
00522     hi = R.hi;
00523 }
00524 
00525 
00526 
00527 /*********************************************************************************************
00528            
00529 >    Rect& Rect::operator=(const Rect& Rect)
00530 
00531      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00532      Created:   13/5/93
00533      Inputs:    Rect: Rect to copy 
00534      Outputs:   -
00535      Returns:   Reference to this Rect 
00536                 
00537      Purpose:   Equals operator 
00538 
00539 **********************************************************************************************/  
00540 
00541 inline Rect& Rect::operator=(const Rect& Rect)
00542 {                                                    
00543     lo = Rect.lo; 
00544     hi = Rect.hi;
00545     
00546     return *this; 
00547 }
00548 
00549 
00550 
00551 /*********************************************************************************************
00552            
00553 >    INT32 Rect::Width() const
00554 
00555      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00556      Created:   13/5/93
00557      Inputs:    - 
00558      Outputs:   -
00559      Returns:   The width of the Rect 
00560                 
00561      Purpose:   To find the width of the Rect 
00562 
00563 **********************************************************************************************/  
00564                      
00565 inline INT32 Rect::Width() const
00566 {
00567     // Detect an invalid rectangle
00568     ENSURE(IsValid(), "Rect::Width() was called on\nan invalid rectangle.");  
00569 
00570     return (hi.x - lo.x);   
00571 }       
00572 
00573 
00574 
00575 /*********************************************************************************************
00576            
00577 >    INT32 Rect::Height() const
00578 
00579      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00580      Created:   13/5/93
00581      Inputs:    - 
00582      Outputs:   -
00583      Returns:   The height of the Rect 
00584                 
00585      Purpose:   To find the height of the Rect 
00586 
00587 **********************************************************************************************/  
00588 
00589 inline INT32 Rect::Height() const 
00590 {                      
00591     // Detect an invalid rectangle
00592     ENSURE(IsValid(), "Rect::Height() was called on\nan invalid rectangle.");  
00593 
00594     return(hi.y - lo.y); 
00595 }
00596                      
00597 
00598 
00599 /*********************************************************************************************
00600            
00601 >    Coord Rect::LowCorner() const
00602      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00603      Created:   13/5/93
00604      Inputs:    - 
00605      Outputs:   -
00606      Returns:   The inclusive lower left hand coordinates of the Rect
00607                 
00608      Purpose:   To find the lower left hand coordinates of the Rect
00609      
00610      Errors:    Assertion failure if the rectangle is invalid.
00611 
00612 **********************************************************************************************/  
00613                      
00614 inline Coord Rect::LowCorner() const
00615 {     
00616     // Detect an invalid rectangle
00617     ENSURE(IsValid(), "Rect::LowCorner() was called on\nan invalid rectangle.");  
00618 
00619     return(lo); 
00620 }        
00621 
00622 
00623 
00624 /*********************************************************************************************
00625            
00626 >    Coord Rect::HighCorner() const  
00627 
00628      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00629      Created:   13/5/93
00630      Inputs:    - 
00631      Outputs:   -
00632      Returns:   The exclusive upper right hand coordinates of the Rect 
00633                 
00634      Purpose:   To find the upper right hand coordinates of the Rect
00635 
00636      Errors:    Assertion failure if the rectangle is invalid.
00637 
00638 **********************************************************************************************/  
00639 
00640 inline Coord Rect::HighCorner() const  
00641 {      
00642     // Detect an invalid rectangle
00643     ENSURE(IsValid(), "Rect::HighCorner() was called on\nan invalid rectangle.");  
00644 
00645     return(hi); 
00646 }                  
00647 
00648 
00649 
00650 /*********************************************************************************************
00651            
00652 >    Coord Rect::Centre() const
00653 
00654      Author:    Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00655      Created:   19/5/99
00656      Inputs:    - 
00657      Outputs:   -
00658      Returns:   The centre coord of this Rect
00659                 
00660      Purpose:   To find the centre of the Rect
00661                 It calculates Coord(lox+(width/2),loy+(height/2))
00662      
00663      Errors:    Assertion failure if the rectangle is invalid.
00664 
00665 **********************************************************************************************/  
00666                      
00667 inline Coord Rect::Centre() const
00668 {     
00669     // Detect an invalid rectangle
00670     ENSURE(IsValid(), "Rect::Centre() was called on\nan invalid rectangle.");  
00671 
00672     return Coord(lo.x + Width() / 2, lo.y + Height() / 2); 
00673 }        
00674 
00675 
00676 
00677 /*********************************************************************************************
00678 
00679 >    BOOL Rect::IsIntersectedWith(const Rect& Rect) const
00680 
00681      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00682      Created:   17/5/93
00683      Inputs:    -  
00684      Outputs:   - 
00685      
00686      Returns:   TRUE if the rectangles intersect, FALSE otherwise.
00687                 
00688      Purpose:   To check for rectangle intersection 
00689 
00690      Errors:    
00691 
00692 **********************************************************************************************/  
00693 
00694 inline BOOL Rect::IsIntersectedWith(const Rect& R) const
00695 {
00696     // Detect an invalid rectangle
00697     if ((!IsValid()) || (!R.IsValid()))
00698         return FALSE;
00699         
00700     return ((hi.x > R.lo.x) && (lo.x < R.hi.x) &&
00701             (hi.y > R.lo.y) && (lo.y < R.hi.y));
00702 }
00703 
00704 
00705 
00706 /*********************************************************************************************
00707 
00708 >    BOOL Rect::ContainsCoord(const Coord& Point)
00709 
00710      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00711      Created:   17/5/93
00712      Inputs:    -  
00713      Outputs:   - 
00714      
00715      Returns:   TRUE if the coordinate is within the rectangle, FALSE otherwise.
00716                 
00717      Purpose:   To check for coordinate containment.
00718 
00719      Errors:    Assertion failure if the rectangle is invalid.
00720 
00721      SeeAlso:   ContainsRectCoord; ContainsRect
00722 
00723 **********************************************************************************************/  
00724 
00725 inline BOOL Rect::ContainsCoord(const Coord& Point) const
00726 {
00727     // Check for an an empty rectangle
00728     if (IsEmpty())
00729         return FALSE;
00730 
00731     // Detect an invalid rectangle
00732     ENSURE(IsValid(), "Rect::ContainsCoord() was called on\nan invalid rectangle.");  
00733 
00734     return ((Point.x >= lo.x) && (Point.x < hi.x) &&
00735             (Point.y >= lo.y) && (Point.y < hi.y));
00736 }
00737 
00738 
00739 
00740 /*********************************************************************************************
00741 
00742 >    BOOL Rect::ContainsRectCoord(const Coord& Point)
00743 
00744      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00745      Created:   17/5/93
00746      Inputs:    -  
00747      Outputs:   - 
00748      
00749      Returns:   TRUE if the coordinate is within the rectangle, FALSE otherwise.
00750                 
00751      Purpose:   To check for coordinate containment.  This will work for coordinates which
00752                 have been extracted from other rectangles (i.e. the top right corner is
00753                 considered inclusive for this operation, not exclusive).
00754 
00755      Errors:    Assertion failure if the rectangle is invalid.
00756 
00757      SeeAlso:   ContainsCoord; ContainsRect
00758 
00759 **********************************************************************************************/  
00760 
00761 inline BOOL Rect::ContainsRectCoord(const Coord& Point) const
00762 {
00763     // Check for an an empty rectangle
00764     if (IsEmpty())
00765         return FALSE;
00766 
00767     // Detect an invalid rectangle
00768     ENSURE(IsValid(), "Rect::ContainsRectCoord() was called on\nan invalid rectangle.");  
00769 
00770     return ((Point.x >= lo.x) && (Point.x <= hi.x) &&
00771             (Point.y >= lo.y) && (Point.y <= hi.y));
00772 }
00773 
00774 
00775 
00776 /*********************************************************************************************
00777 
00778 >    BOOL Rect::ContainsRect(const Rect& Rect)
00779 
00780      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00781      Created:   17/5/93
00782      Inputs:    -  
00783      Outputs:   - 
00784      
00785      Returns:   TRUE if the rectangle 'Rect' is within the rectangle, FALSE otherwise.
00786                 
00787      Purpose:   To check for rectangle containment.
00788 
00789      Errors:    Assertion failure if the rectangle is invalid.
00790 
00791      SeeAlso:   ContainsRectCoord; ContainsCoord
00792 
00793 **********************************************************************************************/  
00794 
00795 inline BOOL Rect::ContainsRect(const Rect& Rect) const
00796 {
00797     // Check for an an empty rectangle
00798     if (IsEmpty())
00799         return FALSE;
00800 
00801     // Detect an invalid rectangle
00802     ENSURE(IsValid(), "Rect::ContainsRect() was called on\nan invalid rectangle.");  
00803 
00804     return ((Rect.lo.x >= lo.x) && (Rect.hi.x <= hi.x) &&
00805             (Rect.lo.y >= lo.y) && (Rect.hi.y <= hi.y));
00806 }
00807 
00808 
00809 
00810 /********************************************************************************************
00811 
00812 >   void Rect::MakeEmpty()
00813 
00814     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00815     Created:    03/03/94
00816     Purpose:    Make the rectangle an empty one (all coordinates are set to 0).
00817     SeeAlso:    Rect::MakeEmpty
00818 
00819 ********************************************************************************************/
00820 
00821 inline void Rect::MakeEmpty()
00822 {
00823   lo.x = lo.y = hi.x = hi.y = 0;
00824 }
00825 
00826 
00827 
00828 /*********************************************************************************************
00829 
00830 >    BOOL Rect::IsEmpty() const
00831 
00832      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00833      Created:   17/5/93
00834      Inputs:    -  
00835      Outputs:   - 
00836      
00837      Returns:   TRUE if the rectangle is empty.
00838                 
00839      Purpose:   To check for empty rectangle.
00840 
00841      Errors:    
00842 
00843 **********************************************************************************************/  
00844 
00845 inline BOOL Rect::IsEmpty() const
00846 {
00847     return ((lo.x == hi.x) || (lo.y == hi.y));
00848 }
00849 
00850 
00851 
00852 /*********************************************************************************************
00853 
00854 >    BOOL Rect::IsValid() const
00855 
00856      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00857      Created:   9/6/93
00858      Inputs:    -  
00859      Outputs:   - 
00860      
00861      Returns:   TRUE if the rectangle is valid.
00862                 
00863      Purpose:   To check for a valid rectangle.
00864 
00865      Errors:    
00866 
00867 **********************************************************************************************/  
00868 
00869 inline BOOL Rect::IsValid() const
00870 {
00871     return ((lo.x <= hi.x) && (lo.y <= hi.y));
00872 }
00873 
00874 #endif
00875 

Generated on Sat Nov 10 03:46:43 2007 for Camelot by  doxygen 1.4.4