Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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 00031 #include "csextern.h" 00032 00053 class CS_CSGEOM_EXPORT csRect 00054 { 00055 public: 00057 int xmin, ymin, xmax, ymax; 00058 00060 csRect (); 00061 00063 csRect (int ixmin, int iymin, int ixmax, int iymax); 00064 00066 csRect (const csRect ©); 00067 00069 virtual ~csRect (); 00070 00072 void Intersect (int ixmin, int iymin, int ixmax, int iymax); 00073 00075 inline void Intersect (const csRect &other) 00076 { Intersect (other.xmin, other.ymin, other.xmax, other.ymax); } 00077 00079 bool Intersects (const csRect &target) const; 00080 00085 void Union (int ixmin, int iymin, int ixmax, int iymax); 00086 00091 inline void Union (const csRect &other) 00092 { Union (other.xmin, other.ymin, other.xmax, other.ymax); } 00093 00099 void Exclude (int ixmin, int iymin, int ixmax, int iymax); 00100 00102 inline void Exclude (const csRect &other) 00103 { Exclude (other.xmin, other.ymin, other.xmax, other.ymax); } 00104 00109 void Subtract (const csRect &rect); 00110 00112 inline bool IsEmpty () const 00113 { return (xmin >= xmax) || (ymin >= ymax); } 00114 00116 inline void MakeEmpty () 00117 { xmin = xmax = 0; } 00118 00120 inline void Set (int ixmin, int iymin, int ixmax, int iymax) 00121 { 00122 xmin = ixmin; xmax = ixmax; 00123 ymin = iymin; ymax = iymax; 00124 } 00125 00127 inline void Set (const csRect &target) 00128 { 00129 xmin = target.xmin; xmax = target.xmax; 00130 ymin = target.ymin; ymax = target.ymax; 00131 } 00132 00134 inline void SetPos (int x, int y) 00135 { xmin = x; ymin = y; } 00136 00138 inline void SetSize (int w, int h) 00139 { xmax = xmin + w; ymax = ymin + h; } 00140 00142 inline void Move (int dX, int dY) 00143 { xmin += dX; xmax += dX; ymin += dY; ymax += dY; } 00144 00146 inline int Width () const { return xmax - xmin; } 00147 00149 inline int Height () const { return ymax - ymin; } 00150 00152 inline bool Contains (int x, int y) const 00153 { return (x >= xmin) && (x < xmax) && (y >= ymin) && (y < ymax); } 00154 00156 inline bool ContainsRel (int x, int y) const 00157 { return (x >= 0) && (x < Width ()) && (y >= 0) && (y < Height ()); } 00158 00160 inline bool Equal (int ixmin, int iymin, int ixmax, int iymax) const 00161 { return (xmin == ixmin) && (ymin == iymin) && 00162 (xmax == ixmax) && (ymax == iymax); } 00164 inline bool Equal (const csRect &other) const 00165 { return Equal (other.xmin, other.ymin, other.xmax, other.ymax); } 00166 00168 inline void Normalize () 00169 { 00170 if (xmin > xmax) { int tmp = xmin; xmin = xmax; xmax = tmp; } 00171 if (ymin > ymax) { int tmp = ymin; ymin = ymax; ymax = tmp; } 00172 } 00173 00175 inline int Area () const 00176 { 00177 if (IsEmpty ()) 00178 return 0; 00179 else 00180 return Width () * Height (); 00181 } 00182 00184 void AddAdjanced (const csRect &rect); 00185 00187 inline bool operator == (const csRect& rect) const 00188 { 00189 return Equal (rect); 00190 } 00191 00193 inline bool operator != (const csRect &rect) const 00194 { 00195 return !Equal (rect); 00196 } 00197 00199 inline void Extend (int x, int y) 00200 { 00201 if (xmin > x) xmin = x; if (xmax < x) xmax = x; 00202 if (ymin > y) ymin = y; if (ymax < y) ymax = y; 00203 } 00204 00206 void Join (const csRect &rect); 00207 00209 void Outset(int n); 00210 00212 void Inset(int n); 00213 00221 bool ClipLineGeneral (int& x1, int& y1, int& x2, int& y2); 00222 00230 bool ClipLine (int& x1, int& y1, int& x2, int& y2); 00231 00239 bool ClipLineSafe (int& x1, int& y1, int& x2, int& y2); 00240 }; 00241 00244 #endif // __CS_RECT_H__ 00245
Generated for Crystal Space by doxygen 1.3.9.1