userrect.h

Go to the documentation of this file.
00001 // $Id: userrect.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_USERRECT
00101 #define INC_USERRECT
00102 
00103 #include "usercord.h"
00104 
00105 // extra headers for UserRect class
00106 
00107 class DocRect;
00108 
00109 
00110 /***********************************************************************************************
00111 
00112 >    Class UserRect
00113 
00114      Author:       Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00115      Date:         11/5/93
00116      
00117      Purpose:      This class is used to represent a rectangular region.  It uses a union to
00118                    enable the client to access the rectangle as two UserCoords (lo and hi) or as
00119                    four INT32s (lox, loy, hix, hiy).  An anonymous union is used, which is a
00120                    defined C++ feature and so portable.
00121 
00122                    The lo coordinates are inclusive, whilst the hi coordinates are exclusive.
00123                    In the document space, lo.y <= hi.y and lo.x <= hi.x (the inequalities are 
00124                    not strict because rectangles can have zero width and/or height - such
00125                    rectangles are considered perfectly valid). 
00126                    
00127                    The inclusivity can be explained as follows:
00128                    
00129                    A point at (lo.x, lo.y) is inside the rectangle
00130                    A point at (hi.x, hi.y) is outside the rectangle
00131                    
00132                    Any rectangle that does not obey the inequalites lo.y <= hi.y and 
00133                    lo.x <= hi.x is deemed to be 'invalid'.  Invalid rectangles have special
00134                    properties.  They will cause errors when used in some operations, but not
00135                    in others.  The general rule is that if the rectangle is used as an entity,
00136                    then the operation will succeed (taking account of the 'invalidity' of
00137                    the rectangle).  If, however, the actual coordinates of the invalid
00138                    rectangle must be used/changed in the operation, then an error (usually an
00139                    assertion failure) will occur.
00140                    
00141                    For example, using invalid rectangles in Unions and Intersections is ok, 
00142                    because the invalid rectangle is ignored, and the 'other' rectangle is
00143                    returned as the result.  This means that if both rectangles are invalid,
00144                    then an invalid rectangle is returned.
00145                    
00146                    Conversely, trying to use operations like Translate(), Inflate(), Width()
00147                    or Height() on invalid rectangles is considered to be an error, and will
00148                    cause an assertion failure.
00149                    
00150                    See the individual function descriptions for more details.
00151                    
00152                    
00153      Errors:       -
00154 
00155      SeeAlso:      UserCoord
00156 
00157      SeeAlso:      Rect
00158      SeeAlso:      DocRect
00159      SeeAlso:      WorkRect
00160      SeeAlso:      OSRect
00161                     
00162 ***********************************************************************************************/
00163 
00164 class CAMAPI UserRect
00165 {   
00166 public:
00167 
00168     UserCoord           lo, hi;
00169 
00170                             
00171     // UserRect constructors
00172                         
00173     UserRect();              
00174 
00175     UserRect(INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY); 
00176 
00177     UserRect(const UserCoord& Low, UINT32 Width, UINT32 Height); 
00178 
00179     UserRect(const UserCoord& Low, const UserCoord& High);   
00180                      
00181     UserRect(const UserRect& UserRect); // Copy constructor
00182 
00183     UserRect& operator=(const UserRect& UserRect);// Assignment operator
00184                      
00185     INT32 Width() const;
00186     INT32 Height() const; 
00187     
00188     UserCoord LowCorner() const;
00189     UserCoord HighCorner() const;  
00190 
00191     UserCoord Centre() const;
00192     
00193     // General operations type stuff
00194     BOOL IsIntersectedWith(const UserRect&) const;
00195     UserRect Intersection(const UserRect&) const;
00196     UserRect Union(const UserRect&) const;
00197     INT32 SplitRect(const UserRect& R, UserRect* SubRects);
00198 
00199     BOOL ContainsCoord(const UserCoord&) const;
00200     BOOL ContainsRectCoord(const UserCoord&) const;
00201     BOOL ContainsRect(const UserRect&) const;
00202     BOOL IsAdjacent(const UserRect&, MILLIPOINT Fuzzy) const;
00203 
00204     void MakeEmpty();
00205         
00206     BOOL IsEmpty() const;   
00207     BOOL IsValid() const;   
00208 
00209     void Inflate(INT32 XInc, INT32 YInc);
00210     void Inflate(INT32 XInc);
00211     void Translate(INT32 XOfs, INT32 YOfs);
00212     void IncludePoint(const UserCoord&);
00213     
00214     // Overloaded operators
00215     INT32 operator==(const UserRect&) const;
00216     INT32 operator!=(const UserRect&) const;
00217 
00218 // declarations of extra functions for the DocRct class
00219 
00220 public:
00221     DocRect ToSpread(Spread* pSpread);
00222 
00223 
00224 };                                            
00225 
00226 
00227   
00228 /*********************************************************************************************
00229 
00230 >    void UserRect::Translate(INT32 XOfs, INT32 YOfs)
00231 
00232      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00233      Created:   17/5/93
00234      Inputs:    (XOfs, YOfs) - the offset to translate the rectangle by.
00235      Outputs:   - 
00236      
00237      Returns:   N/A.
00238                 
00239      Purpose:   Translate a rectangle by given offset.
00240 
00241      Errors:    An assertion failure if the rectangle is invalid.
00242 
00243 **********************************************************************************************/  
00244 
00245 inline void UserRect::Translate(INT32 XOfs, INT32 YOfs)
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 }
00256 
00257 
00258 
00259 /*********************************************************************************************
00260 
00261 >    INT32 operator==(const UserRect& R) const
00262 
00263      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00264      Created:   17/5/93
00265      Inputs:    R - the rectangle to compare against.
00266      Outputs:   - 
00267      
00268      Returns:   TRUE if R is describes the same rectangle as the object.
00269                 
00270      Purpose:   Test for equality of two rectangles.  As all invalid rectangles have the
00271                 same results when used for Union/Intersection, any two invalid rectangles
00272                 are considered equal.
00273 
00274      Friend:    UserRect
00275      
00276      Errors:    None.
00277 
00278 **********************************************************************************************/  
00279 
00280 inline INT32 UserRect::operator==(const UserRect& R) const
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 }
00291 
00292 
00293 
00294 /*********************************************************************************************
00295 
00296 >    INT32 operator!=(const UserRect& R) const
00297 
00298      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00299      Created:   17/5/93
00300      Inputs:    R - the rectangle to compare against.
00301      Outputs:   - 
00302      
00303      Returns:   TRUE if R does not describe the same rectangle as the object.
00304                 
00305      Purpose:   Test for inequality of two rectangles.  As all invalid rectangles have the
00306                 same results when used for Union/Intersection, any two invalid rectangles
00307                 are considered equal.
00308 
00309      Friend:    UserRect
00310      
00311      Errors:    None.
00312 
00313 **********************************************************************************************/  
00314 
00315 inline INT32 UserRect::operator!=(const UserRect& R) const
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 }
00324 
00325 
00326 
00327 /*********************************************************************************************
00328 
00329 >    void UserRect::Inflate(INT32 XInc, INT32 YInc)
00330 
00331      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00332      Created:   17/5/93
00333      Inputs:    XInc, YInc - the amount to inflate (or deflate) the rectangle by.
00334      Outputs:   - 
00335      
00336      Returns:   N/A.
00337                 
00338      Purpose:   Inflate a rectangle by given amounts.  Negative values will deflate the
00339                 rectangle.
00340 
00341      Errors:    An assertion failure if the rectangle is invalid.
00342 
00343 **********************************************************************************************/  
00344 
00345 inline void UserRect::Inflate(INT32 XInc, INT32 YInc)
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 }
00356 
00357 
00358 
00359 /*********************************************************************************************
00360 
00361 >    void UserRect::Inflate(INT32 Inc)
00362 
00363      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00364      Created:   17/5/93
00365      Inputs:    Inc - the amount to inflate (or deflate) the rectangle by.
00366      Outputs:   - 
00367      
00368      Returns:   N/A.
00369                 
00370      Purpose:   Inflate a rectangle by given amount.  Negative values will deflate the
00371                 rectangle.
00372 
00373      Errors:    An assertion failure if the rectangle is invalid.
00374 
00375 **********************************************************************************************/  
00376 
00377 inline void UserRect::Inflate(INT32 Inc)
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 }
00388 
00389 
00390 
00391 /*********************************************************************************************
00392 
00393 >    UserRect::UserRect() 
00394 
00395      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00396      Created:   13/5/93
00397      Inputs:    None
00398      Outputs:   -
00399      Returns:   - 
00400                 
00401      Purpose:   To construct an empty UserRect.
00402                 
00403 
00404      Errors:    
00405 
00406 **********************************************************************************************/  
00407 
00408 inline UserRect::UserRect()
00409 {
00410     // An empty rectangle
00411     hi.x = hi.y = lo.x = lo.y = 0;
00412 }
00413      
00414                 
00415 
00416 /*********************************************************************************************
00417            
00418 >    UserRect::UserRect(INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY)
00419 
00420      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00421      Created:   13/5/93
00422      Inputs:    LowX : Lower X coord of rectangle (inclusive)
00423                 HighX: Higher X coord of rectangle (exclusive) 
00424                 LowY : Lower Y coord of rectangle (inclusive)
00425                 HighY: Higher Y coord of rectangle (exclusive)
00426                 
00427      Outputs:   -
00428      Returns:   - 
00429                 
00430      Purpose:   To construct a UserRect with an inclusive lower left hand corner 
00431                 position of (Left, Lower) and an exclusive upper right hand corner 
00432                 position of (Right, Upper).  
00433 
00434      Errors:    An assertion failure will occur if the lower left hand coordinates
00435                 are not lower than and to the left of the upper right coordinate. 
00436 
00437 **********************************************************************************************/  
00438                       
00439 inline UserRect::UserRect(INT32 LowX, INT32 LowY, INT32 HighX, INT32 HighY)
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 } 
00451 
00452 
00453 
00454 /*********************************************************************************************
00455            
00456 >    UserRect::UserRect(const UserCoord& Low, const UserCoord& High) 
00457 
00458      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00459      Created:   13/5/93
00460      Inputs:    Low : UserCoordinates of the lower left hand corner (inclusive) 
00461                 High: UserCoordinates of the upper right hand corner (exclusive)
00462      Outputs:   -
00463      Returns:   - 
00464                 
00465      Purpose:   To construct a rectangle with an inclusive lower left hand corner 
00466                 position of Low and an exclusive upper right hand corner
00467                 position of High.
00468 
00469      Errors:    An assertion failure will occur if the lower left hand coordinates
00470                 are not lower than and to the left of the upper right coordinates. 
00471 
00472 **********************************************************************************************/  
00473 
00474 inline UserRect::UserRect(const UserCoord& Low, const UserCoord& High)
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 }       
00483     
00484 
00485 
00486 /*********************************************************************************************
00487            
00488 >    UserRect::UserRect(const UserCoord& Low, UINT32 Width, UINT32 Height) 
00489 
00490      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00491      Created:   17/5/93
00492      Inputs:    Low: UserCoordinates of the inclusive lower left hand corner.
00493                 Width, Height  : Desired dimensions of the rectangle.
00494      Outputs:   -
00495      Returns:   - 
00496                 
00497      Purpose:   To construct a rectangle with an inclusive lower left hand corner 
00498                 position of Low and a width and height as specified.
00499 
00500      Errors:    None.
00501      
00502 **********************************************************************************************/  
00503 
00504 inline UserRect::UserRect(const UserCoord& Low, UINT32 Width, UINT32 Height) 
00505 {         
00506     lo = Low;
00507     
00508     hi.x = lo.x + Width;
00509     hi.y = lo.y + Height;
00510 }       
00511    
00512    
00513     
00514        
00515 /*********************************************************************************************
00516            
00517 >    UserRect::UserRect(const UserRect& R) 
00518 
00519      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00520      Created:   13/5/93
00521      Inputs:    R: The copy of the UserRect 
00522      Outputs:   -
00523      Returns:   - 
00524                 
00525      Purpose:   Copy constructor 
00526 
00527 **********************************************************************************************/  
00528 
00529 inline UserRect::UserRect(const UserRect& R)
00530 {
00531     lo = R.lo;
00532     hi = R.hi;
00533 }
00534 
00535 
00536 
00537 /*********************************************************************************************
00538            
00539 >    UserRect& UserRect::operator=(const UserRect& UserRect)
00540 
00541      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00542      Created:   13/5/93
00543      Inputs:    UserRect: UserRect to copy 
00544      Outputs:   -
00545      Returns:   Reference to this UserRect 
00546                 
00547      Purpose:   Equals operator 
00548 
00549 **********************************************************************************************/  
00550 
00551 inline UserRect& UserRect::operator=(const UserRect& UserRect)
00552 {                                                    
00553     lo = UserRect.lo; 
00554     hi = UserRect.hi;
00555     
00556     return *this; 
00557 }
00558 
00559 
00560 
00561 /*********************************************************************************************
00562            
00563 >    INT32 UserRect::Width() const
00564 
00565      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00566      Created:   13/5/93
00567      Inputs:    - 
00568      Outputs:   -
00569      Returns:   The width of the UserRect 
00570                 
00571      Purpose:   To find the width of the UserRect 
00572 
00573 **********************************************************************************************/  
00574                      
00575 inline INT32 UserRect::Width() const
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 }       
00582 
00583 
00584 
00585 /*********************************************************************************************
00586            
00587 >    INT32 UserRect::Height() const
00588 
00589      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00590      Created:   13/5/93
00591      Inputs:    - 
00592      Outputs:   -
00593      Returns:   The height of the UserRect 
00594                 
00595      Purpose:   To find the height of the UserRect 
00596 
00597 **********************************************************************************************/  
00598 
00599 inline INT32 UserRect::Height() const 
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 }
00606                      
00607 
00608 
00609 /*********************************************************************************************
00610            
00611 >    UserCoord UserRect::LowCorner() const
00612      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00613      Created:   13/5/93
00614      Inputs:    - 
00615      Outputs:   -
00616      Returns:   The inclusive lower left hand coordinates of the UserRect
00617                 
00618      Purpose:   To find the lower left hand coordinates of the UserRect
00619      
00620      Errors:    Assertion failure if the rectangle is invalid.
00621 
00622 **********************************************************************************************/  
00623                      
00624 inline UserCoord UserRect::LowCorner() const
00625 {     
00626     // Detect an invalid rectangle
00627     ENSURE(IsValid(), "UserRect::LowCorner() was called on\nan invalid rectangle.");  
00628 
00629     return(lo); 
00630 }        
00631 
00632 
00633 
00634 /*********************************************************************************************
00635            
00636 >    UserCoord UserRect::HighCorner() const  
00637 
00638      Author:    Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00639      Created:   13/5/93
00640      Inputs:    - 
00641      Outputs:   -
00642      Returns:   The exclusive upper right hand coordinates of the UserRect 
00643                 
00644      Purpose:   To find the upper right hand coordinates of the UserRect
00645 
00646      Errors:    Assertion failure if the rectangle is invalid.
00647 
00648 **********************************************************************************************/  
00649 
00650 inline UserCoord UserRect::HighCorner() const  
00651 {      
00652     // Detect an invalid rectangle
00653     ENSURE(IsValid(), "UserRect::HighCorner() was called on\nan invalid rectangle.");  
00654 
00655     return(hi); 
00656 }                  
00657 
00658 
00659 
00660 /*********************************************************************************************
00661            
00662 >    UserCoord UserRect::Centre() const
00663 
00664      Author:    Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00665      Created:   19/5/99
00666      Inputs:    - 
00667      Outputs:   -
00668      Returns:   The centre coord of this UserRect
00669                 
00670      Purpose:   To find the centre of the UserRect
00671                 It calculates UserCoord(lox+(width/2),loy+(height/2))
00672      
00673      Errors:    Assertion failure if the rectangle is invalid.
00674 
00675 **********************************************************************************************/  
00676                      
00677 inline UserCoord UserRect::Centre() const
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 }        
00684 
00685 
00686 
00687 /*********************************************************************************************
00688 
00689 >    BOOL UserRect::IsIntersectedWith(const UserRect& UserRect) const
00690 
00691      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00692      Created:   17/5/93
00693      Inputs:    -  
00694      Outputs:   - 
00695      
00696      Returns:   TRUE if the rectangles intersect, FALSE otherwise.
00697                 
00698      Purpose:   To check for rectangle intersection 
00699 
00700      Errors:    
00701 
00702 **********************************************************************************************/  
00703 
00704 inline BOOL UserRect::IsIntersectedWith(const UserRect& R) const
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 }
00713 
00714 
00715 
00716 /*********************************************************************************************
00717 
00718 >    BOOL UserRect::ContainsCoord(const UserCoord& Point)
00719 
00720      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00721      Created:   17/5/93
00722      Inputs:    -  
00723      Outputs:   - 
00724      
00725      Returns:   TRUE if the coordinate is within the rectangle, FALSE otherwise.
00726                 
00727      Purpose:   To check for coordinate containment.
00728 
00729      Errors:    Assertion failure if the rectangle is invalid.
00730 
00731      SeeAlso:   ContainsRectCoord; ContainsRect
00732 
00733 **********************************************************************************************/  
00734 
00735 inline BOOL UserRect::ContainsCoord(const UserCoord& Point) const
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 }
00747 
00748 
00749 
00750 /*********************************************************************************************
00751 
00752 >    BOOL UserRect::ContainsRectCoord(const UserCoord& Point)
00753 
00754      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00755      Created:   17/5/93
00756      Inputs:    -  
00757      Outputs:   - 
00758      
00759      Returns:   TRUE if the coordinate is within the rectangle, FALSE otherwise.
00760                 
00761      Purpose:   To check for coordinate containment.  This will work for coordinates which
00762                 have been extracted from other rectangles (i.e. the top right corner is
00763                 considered inclusive for this operation, not exclusive).
00764 
00765      Errors:    Assertion failure if the rectangle is invalid.
00766 
00767      SeeAlso:   ContainsCoord; ContainsRect
00768 
00769 **********************************************************************************************/  
00770 
00771 inline BOOL UserRect::ContainsRectCoord(const UserCoord& Point) const
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 }
00783 
00784 
00785 
00786 /*********************************************************************************************
00787 
00788 >    BOOL UserRect::ContainsRect(const UserRect& Rect)
00789 
00790      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00791      Created:   17/5/93
00792      Inputs:    -  
00793      Outputs:   - 
00794      
00795      Returns:   TRUE if the rectangle 'Rect' is within the rectangle, FALSE otherwise.
00796                 
00797      Purpose:   To check for rectangle containment.
00798 
00799      Errors:    Assertion failure if the rectangle is invalid.
00800 
00801      SeeAlso:   ContainsRectCoord; ContainsCoord
00802 
00803 **********************************************************************************************/  
00804 
00805 inline BOOL UserRect::ContainsRect(const UserRect& Rect) const
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 }
00817 
00818 
00819 
00820 /********************************************************************************************
00821 
00822 >   void UserRect::MakeEmpty()
00823 
00824     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00825     Created:    03/03/94
00826     Purpose:    Make the rectangle an empty one (all coordinates are set to 0).
00827     SeeAlso:    UserRect::MakeEmpty
00828 
00829 ********************************************************************************************/
00830 
00831 inline void UserRect::MakeEmpty()
00832 {
00833   lo.x = lo.y = hi.x = hi.y = 0;
00834 }
00835 
00836 
00837 
00838 /*********************************************************************************************
00839 
00840 >    BOOL UserRect::IsEmpty() const
00841 
00842      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00843      Created:   17/5/93
00844      Inputs:    -  
00845      Outputs:   - 
00846      
00847      Returns:   TRUE if the rectangle is empty.
00848                 
00849      Purpose:   To check for empty rectangle.
00850 
00851      Errors:    
00852 
00853 **********************************************************************************************/  
00854 
00855 inline BOOL UserRect::IsEmpty() const
00856 {
00857     return ((lo.x == hi.x) || (lo.y == hi.y));
00858 }
00859 
00860 
00861 
00862 /*********************************************************************************************
00863 
00864 >    BOOL UserRect::IsValid() const
00865 
00866      Author:    Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00867      Created:   9/6/93
00868      Inputs:    -  
00869      Outputs:   - 
00870      
00871      Returns:   TRUE if the rectangle is valid.
00872                 
00873      Purpose:   To check for a valid rectangle.
00874 
00875      Errors:    
00876 
00877 **********************************************************************************************/  
00878 
00879 inline BOOL UserRect::IsValid() const
00880 {
00881     return ((lo.x <= hi.x) && (lo.y <= hi.y));
00882 }
00883 
00884 #endif
00885 

Generated on Sat Nov 10 03:47:18 2007 for Camelot by  doxygen 1.4.4