00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 ©);
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 };
00191
00192 #endif // __CS_RECT_H__