CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

csrect.h

Go to the documentation of this file.
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 
00051 class csRect
00052 {
00053 public:
00055   int xmin, ymin, xmax, ymax;
00056 
00058   csRect ();
00059 
00061   csRect (int ixmin, int iymin, int ixmax, int iymax);
00062 
00064   csRect (const csRect &copy);
00065 
00067   virtual ~csRect ();
00068 
00070   void Intersect (int ixmin, int iymin, int ixmax, int iymax);
00071 
00073   inline void Intersect (const csRect &other)
00074   { Intersect (other.xmin, other.ymin, other.xmax, other.ymax); }
00075 
00077   bool Intersects (const csRect &target) const;
00078 
00083   void Union (int ixmin, int iymin, int ixmax, int iymax);
00084 
00089   inline void Union (const csRect &other)
00090   { Union (other.xmin, other.ymin, other.xmax, other.ymax); }
00091 
00097   void Exclude (int ixmin, int iymin, int ixmax, int iymax);
00098 
00100   inline void Exclude (const csRect &other)
00101   { Exclude (other.xmin, other.ymin, other.xmax, other.ymax); }
00102 
00107   void Subtract (const csRect &rect);
00108 
00110   inline bool IsEmpty () const
00111   { return (xmin >= xmax) || (ymin >= ymax); }
00112 
00114   inline void MakeEmpty ()
00115   { xmin = xmax = 0; }
00116 
00118   inline void Set (int ixmin, int iymin, int ixmax, int iymax)
00119   {
00120     xmin = ixmin; xmax = ixmax;
00121     ymin = iymin; ymax = iymax;
00122   }
00123 
00125   inline void Set (const csRect &target)
00126   {
00127     xmin = target.xmin; xmax = target.xmax;
00128     ymin = target.ymin; ymax = target.ymax;
00129   }
00130 
00132   inline void SetPos (int x, int y)
00133   { xmin = x; ymin = y; }
00134 
00136   inline void SetSize (int w, int h)
00137   { xmax = xmin + w; ymax = ymin + h; }
00138 
00140   inline void Move (int dX, int dY)
00141   { xmin += dX; xmax += dX; ymin += dY; ymax += dY; }
00142 
00144   inline int Width () const { return xmax - xmin; }
00145 
00147   inline int Height () const { return ymax - ymin; }
00148 
00150   inline bool Contains (int x, int y) const
00151   { return (x >= xmin) && (x < xmax) && (y >= ymin) && (y < ymax); }
00152 
00154   inline bool ContainsRel (int x, int y) const
00155   { return (x >= 0) && (x < Width ()) && (y >= 0) && (y < Height ()); }
00156 
00158   inline bool Equal (int ixmin, int iymin, int ixmax, int iymax) const
00159   { return (xmin == ixmin) && (ymin == iymin) &&
00160            (xmax == ixmax) && (ymax == iymax); }
00162   inline bool Equal (const csRect &other) const
00163   { return Equal (other.xmin, other.ymin, other.xmax, other.ymax); }
00164 
00166   inline void Normalize ()
00167   {
00168     if (xmin > xmax) { int tmp = xmin; xmin = xmax; xmax = tmp; }
00169     if (ymin > ymax) { int tmp = ymin; ymin = ymax; ymax = tmp; }
00170   }
00171 
00173   inline int Area () const
00174   {
00175     if (IsEmpty ())
00176       return 0;
00177     else
00178       return Width () * Height ();
00179   }
00180 
00182   void AddAdjanced (const csRect &rect);
00183 
00185   inline bool operator == (const csRect& rect) const
00186   {
00187     return Equal (rect);
00188   }
00189 
00191   inline bool operator != (const csRect &rect) const
00192   {
00193     return !Equal (rect);
00194   }
00195 
00197   inline void Extend (int x, int y)
00198   {
00199     if (xmin > x) xmin = x; if (xmax < x) xmax = x;
00200     if (ymin > y) ymin = y; if (ymax < y) ymax = y;
00201   }
00202 
00204   void Join (const csRect &rect);
00205 
00207   void Outset(int n);
00208 
00210   void Inset(int n);
00211 
00219   bool ClipLineGeneral (int& x1, int& y1, int& x2, int& y2);
00220 
00228   bool ClipLine (int& x1, int& y1, int& x2, int& y2);
00229 
00237   bool ClipLineSafe (int& x1, int& y1, int& x2, int& y2);
00238 };
00239 
00242 #endif // __CS_RECT_H__
00243 

Generated for Crystal Space by doxygen 1.2.14