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
00031 #include "csextern.h"
00032
00053 class CS_CRYSTALSPACE_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 ~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 {
00136 int w = Width(), h=Height();
00137
00138 xmin = x; ymin = y;
00139 xmax = xmin+w;
00140 ymax = ymin+h;
00141 }
00142
00144 inline void SetSize (int w, int h)
00145 { xmax = xmin + w; ymax = ymin + h; }
00146
00148 inline void Move (int dX, int dY)
00149 { xmin += dX; xmax += dX; ymin += dY; ymax += dY; }
00150
00152 inline int Width () const { return xmax - xmin; }
00153
00155 inline int Height () const { return ymax - ymin; }
00156
00158 inline bool Contains (int x, int y) const
00159 { return (x >= xmin) && (x < xmax) && (y >= ymin) && (y < ymax); }
00160
00162 inline bool ContainsRel (int x, int y) const
00163 { return (x >= 0) && (x < Width ()) && (y >= 0) && (y < Height ()); }
00164
00166 inline bool Equal (int ixmin, int iymin, int ixmax, int iymax) const
00167 { return (xmin == ixmin) && (ymin == iymin) &&
00168 (xmax == ixmax) && (ymax == iymax); }
00170 inline bool Equal (const csRect &other) const
00171 { return Equal (other.xmin, other.ymin, other.xmax, other.ymax); }
00172
00174 inline void Normalize ()
00175 {
00176 if (xmin > xmax) { int tmp = xmin; xmin = xmax; xmax = tmp; }
00177 if (ymin > ymax) { int tmp = ymin; ymin = ymax; ymax = tmp; }
00178 }
00179
00181 inline int Area () const
00182 {
00183 if (IsEmpty ())
00184 return 0;
00185 else
00186 return Width () * Height ();
00187 }
00188
00193 void AddAdjacent (const csRect &rect);
00194
00196 inline bool operator == (const csRect& rect) const
00197 {
00198 return Equal (rect);
00199 }
00200
00202 inline bool operator != (const csRect &rect) const
00203 {
00204 return !Equal (rect);
00205 }
00206
00208 inline void Extend (int x, int y)
00209 {
00210 if (xmin > x) xmin = x; if (xmax < x+1) xmax = x+1;
00211 if (ymin > y) ymin = y; if (ymax < y+1) ymax = y+1;
00212 }
00213
00215 void Join (const csRect &rect);
00216
00218 void Outset(int n);
00219
00221 void Inset(int n);
00222
00230 bool ClipLineGeneral (int& x1, int& y1, int& x2, int& y2);
00231
00239 bool ClipLine (int& x1, int& y1, int& x2, int& y2);
00240
00248 bool ClipLineSafe (int& x1, int& y1, int& x2, int& y2);
00249 };
00250
00253 #endif // __CS_RECT_H__
00254