wrkrect.h

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

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