00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef INCL_PLRECT
00012 #define INCL_PLRECT
00013
00014 #include "plpoint.h"
00015
00016
00017
00018 class PLRect
00019 {
00020 public:
00021
00022 PLPoint tl;
00023
00024 PLPoint br;
00025
00026
00027 PLRect
00028 ();
00029
00030
00031 PLRect
00032 ( int left,
00033 int top,
00034 int right,
00035 int bottom
00036 );
00037
00038
00039 PLRect
00040 ( const PLPoint& TL,
00041 const PLPoint& BR
00042 );
00043
00044
00045 bool operator ==
00046 ( const PLRect & rect
00047 ) const;
00048
00049
00050 bool operator !=
00051 ( const PLRect & rect
00052 ) const;
00053
00054
00055 int Width
00056 () const;
00057
00058
00059 int Height
00060 () const;
00061
00062
00063 void SetWidth
00064 (int width
00065 );
00066
00067
00068 void SetHeight
00069 (int height
00070 );
00071
00072
00073 bool Contains
00074 ( const PLPoint& pt
00075 ) const;
00076
00077
00078 bool Contains
00079 ( const PLRect& rect
00080 ) const;
00081
00082
00083 bool Intersects
00084 ( const PLRect& rect
00085 ) const;
00086
00087
00088 void Expand
00089 ( const PLRect& rect
00090 );
00091
00092
00093 void Intersect
00094 ( const PLRect& rect
00095 );
00096 };
00097
00098 inline PLRect::PLRect
00099 ()
00100 {}
00101
00102 inline PLRect::PLRect
00103 ( const PLPoint& TL,
00104 const PLPoint& BR
00105 ): tl(TL), br(BR)
00106 {}
00107
00108 inline PLRect::PLRect
00109 ( int left,
00110 int top,
00111 int right,
00112 int bottom
00113 ) : tl(left, top),
00114 br (right, bottom)
00115 {}
00116
00117 inline bool PLRect::operator ==
00118 ( const PLRect & rect
00119 ) const
00120 {
00121 return (tl == rect.tl && br == rect.br);
00122 }
00123
00124 inline bool PLRect::operator !=
00125 ( const PLRect & rect
00126 ) const
00127 {
00128 return !(rect==*this);
00129 }
00130
00131 inline int PLRect::Width
00132 () const
00133 {
00134 return br.x-tl.x;
00135 }
00136
00137 inline int PLRect::Height
00138 () const
00139 {
00140 return br.y-tl.y;
00141 }
00142
00143 inline void PLRect::SetWidth
00144 (int width
00145 )
00146 {
00147 br.x = tl.x+width;
00148 }
00149
00150 inline void PLRect::SetHeight
00151 (int height
00152 )
00153 {
00154 br.y = tl.y+height;
00155 }
00156
00157 inline bool PLRect::Contains
00158 ( const PLPoint& pt
00159 ) const
00160 {
00161 return (pt.x >= tl.x && pt.x < br.x &&
00162 pt.y >= tl.y && pt.y < br.y);
00163 }
00164
00165 inline bool PLRect::Contains
00166 ( const PLRect& rect
00167 ) const
00168 {
00169 PLPoint brpt (rect.br.x-1, rect.br.y-1);
00170 return Contains(rect.tl) && Contains(brpt);
00171 }
00172
00173 inline bool PLRect::Intersects
00174 ( const PLRect& rect
00175 ) const
00176 {
00177 if (rect.br.x <= tl.x || rect.tl.x >= br.x ||
00178 rect.br.y <= tl.y || rect.tl.y >= br.y)
00179 return false;
00180 else
00181 return true;
00182 }
00183
00184 #ifndef min
00185 #define min(a, b) ((a) < (b) ? (a) : (b))
00186 #endif
00187
00188 #ifndef max
00189 #define max(a, b) ((a) < (b) ? (b) : (a))
00190 #endif
00191
00192 inline void PLRect::Expand
00193 ( const PLRect& rect
00194 )
00195 {
00196 tl.x = min(tl.x, rect.tl.x);
00197 tl.y = min(tl.y, rect.tl.y);
00198 br.x = max(br.x, rect.br.x);
00199 br.y = max(br.y, rect.br.y);
00200 }
00201
00202 inline void PLRect::Intersect
00203 ( const PLRect& rect
00204 )
00205 {
00206 tl.x = max(tl.x, rect.tl.x);
00207 tl.y = max(tl.y, rect.tl.y);
00208 br.x = min(br.x, rect.br.x);
00209 br.y = min(br.y, rect.br.y);
00210 }
00211
00212 #undef min
00213 #undef max
00214
00215 #endif
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262