Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

csrect.h

00001 /*
00002     Crystal Space Engine: rectangle class interface
00003     Copyright (C) 2001 by Jorrit Tyberghein
00004     Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the Free
00018     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #ifndef __CS_RECT_H__
00022 #define __CS_RECT_H__
00023 
00044 class csRect
00045 {
00046 public:
00048   int xmin, ymin, xmax, ymax;
00049 
00051   csRect ();
00052 
00054   csRect (int ixmin, int iymin, int ixmax, int iymax);
00055 
00057   csRect (const csRect &copy);
00058 
00060   virtual ~csRect ();
00061 
00063   void Intersect (int ixmin, int iymin, int ixmax, int iymax);
00064 
00066   inline void Intersect (const csRect &other)
00067   { Intersect (other.xmin, other.ymin, other.xmax, other.ymax); }
00068 
00070   bool Intersects (const csRect &target) const;
00071 
00076   void Union (int ixmin, int iymin, int ixmax, int iymax);
00077 
00082   inline void Union (const csRect &other)
00083   { Union (other.xmin, other.ymin, other.xmax, other.ymax); }
00084 
00090   void Exclude (int ixmin, int iymin, int ixmax, int iymax);
00091 
00093   inline void Exclude (const csRect &other)
00094   { Exclude (other.xmin, other.ymin, other.xmax, other.ymax); }
00095 
00100   void Subtract (const csRect &rect);
00101 
00103   inline bool IsEmpty () const
00104   { return (xmin >= xmax) || (ymin >= ymax); }
00105 
00107   inline void MakeEmpty ()
00108   { xmin = xmax = 0; }
00109 
00111   inline void Set (int ixmin, int iymin, int ixmax, int iymax)
00112   {
00113     xmin = ixmin; xmax = ixmax;
00114     ymin = iymin; ymax = iymax;
00115   }
00116 
00118   inline void Set (const csRect &target)
00119   {
00120     xmin = target.xmin; xmax = target.xmax;
00121     ymin = target.ymin; ymax = target.ymax;
00122   }
00123 
00125   inline void SetPos (int x, int y)
00126   { xmin = x; ymin = y; }
00127 
00129   inline void SetSize (int w, int h)
00130   { xmax = xmin + w; ymax = ymin + h; }
00131 
00133   inline void Move (int dX, int dY)
00134   { xmin += dX; xmax += dX; ymin += dY; ymax += dY; }
00135 
00137   inline int Width () const { return xmax - xmin; }
00138 
00140   inline int Height () const { return ymax - ymin; }
00141 
00143   inline bool Contains (int x, int y) const
00144   { return (x >= xmin) && (x < xmax) && (y >= ymin) && (y < ymax); }
00145 
00147   inline bool ContainsRel (int x, int y) const
00148   { return (x >= 0) && (x < Width ()) && (y >= 0) && (y < Height ()); }
00149 
00151   inline bool Equal (int ixmin, int iymin, int ixmax, int iymax) const
00152   { return (xmin == ixmin) && (ymin == iymin) &&
00153            (xmax == ixmax) && (ymax == iymax); }
00155   inline bool Equal (csRect &other) const
00156   { return Equal (other.xmin, other.ymin, other.xmax, other.ymax); }
00157 
00159   inline void Normalize ()
00160   {
00161     if (xmin > xmax) { int tmp = xmin; xmin = xmax; xmax = tmp; }
00162     if (ymin > ymax) { int tmp = ymin; ymin = ymax; ymax = tmp; }
00163   }
00164 
00166   inline int Area () const
00167   {
00168     if (IsEmpty ())
00169       return 0;
00170     else
00171       return Width () * Height ();
00172   }
00173 
00175   void AddAdjanced (const csRect &rect);
00176 
00178   inline bool operator != (const csRect &rect) const
00179   {
00180     return (xmin != rect.xmin) || (ymin != rect.ymin)
00181         || (xmax != rect.xmax) || (ymax != rect.ymax);
00182   }
00183 
00185   inline void Extend (int x, int y)
00186   {
00187     if (xmin > x) xmin = x; if (xmax < x) xmax = x;
00188     if (ymin > y) ymin = y; if (ymax < y) ymax = y;
00189   }
00190 
00192   void Join (const csRect &rect);
00193 
00195   void Outset(int n);
00196 
00198   void Inset(int n);
00199 };
00200 
00201 #endif // __CS_RECT_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000