docrect.h

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

Generated on Sat Nov 10 03:45:02 2007 for Camelot by  doxygen 1.4.4