1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
/*
/--------------------------------------------------------------------
|
| $Id: plrect.h,v 1.11 2004/06/06 12:56:38 uzadow Exp $
|
| Copyright (c) 1996-2002 Ulrich von Zadow
|
\--------------------------------------------------------------------
*/
#ifndef INCL_PLRECT
#define INCL_PLRECT
#include "plpoint.h"
//! Simple rectangle class.
//! Contains all points from tl up to but not including br.
class PLRect
{
public:
//!
PLPoint tl;
//!
PLPoint br;
//!
PLRect
();
//!
PLRect
( int left,
int top,
int right,
int bottom
);
//!
PLRect
( const PLPoint& TL,
const PLPoint& BR
);
//!
bool operator ==
( const PLRect & rect
) const;
//!
bool operator !=
( const PLRect & rect
) const;
//!
int Width
() const;
//!
int Height
() const;
//!
void SetWidth
(int width
);
//!
void SetHeight
(int height
);
//!
bool Contains
( const PLPoint& pt
) const;
//!
bool Contains
( const PLRect& rect
) const;
//!
bool Intersects
( const PLRect& rect
) const;
//!
void Expand
( const PLRect& rect
);
//!
void Intersect
( const PLRect& rect
);
};
inline PLRect::PLRect
()
{}
inline PLRect::PLRect
( const PLPoint& TL,
const PLPoint& BR
): tl(TL), br(BR)
{}
inline PLRect::PLRect
( int left,
int top,
int right,
int bottom
) : tl(left, top),
br (right, bottom)
{}
inline bool PLRect::operator ==
( const PLRect & rect
) const
{
return (tl == rect.tl && br == rect.br);
}
inline bool PLRect::operator !=
( const PLRect & rect
) const
{
return !(rect==*this);
}
inline int PLRect::Width
() const
{
return br.x-tl.x;
}
inline int PLRect::Height
() const
{
return br.y-tl.y;
}
inline void PLRect::SetWidth
(int width
)
{
br.x = tl.x+width;
}
inline void PLRect::SetHeight
(int height
)
{
br.y = tl.y+height;
}
inline bool PLRect::Contains
( const PLPoint& pt
) const
{
return (pt.x >= tl.x && pt.x < br.x &&
pt.y >= tl.y && pt.y < br.y);
}
inline bool PLRect::Contains
( const PLRect& rect
) const
{
PLPoint brpt (rect.br.x-1, rect.br.y-1);
return Contains(rect.tl) && Contains(brpt);
}
inline bool PLRect::Intersects
( const PLRect& rect
) const
{
if (rect.br.x <= tl.x || rect.tl.x >= br.x ||
rect.br.y <= tl.y || rect.tl.y >= br.y)
return false;
else
return true;
}
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) ((a) < (b) ? (b) : (a))
#endif
inline void PLRect::Expand
( const PLRect& rect
)
{
tl.x = min(tl.x, rect.tl.x);
tl.y = min(tl.y, rect.tl.y);
br.x = max(br.x, rect.br.x);
br.y = max(br.y, rect.br.y);
}
inline void PLRect::Intersect
( const PLRect& rect
)
{
tl.x = max(tl.x, rect.tl.x);
tl.y = max(tl.y, rect.tl.y);
br.x = min(br.x, rect.br.x);
br.y = min(br.y, rect.br.y);
}
#undef min
#undef max
#endif
/*
/--------------------------------------------------------------------
|
| $Log: plrect.h,v $
| Revision 1.11 2004/06/06 12:56:38 uzadow
| Doxygenified documentation.
|
| Revision 1.10 2004/02/21 18:37:08 uzadow
| Fixed rect.Intersects() again.
|
| Revision 1.8 2004/02/21 16:48:24 uzadow
| Fixed rect.Intersects()
|
| Revision 1.7 2003/10/15 21:24:04 uzadow
| *** empty log message ***
|
| Revision 1.6 2003/08/17 18:04:38 uzadow
| Added PLRect::Intersect()
|
| Revision 1.5 2003/08/17 15:04:30 uzadow
| Added PLRect::Intersects() and Expand()
|
| Revision 1.4 2003/03/19 14:33:14 uzadow
| Added Rect.Contains
|
| Revision 1.3 2002/03/31 13:36:42 uzadow
| Updated copyright.
|
| Revision 1.2 2001/09/28 19:50:56 uzadow
| Added some 24 bpp stuff & other minor features.
|
| Revision 1.1 2001/09/24 14:24:52 uzadow
| Added PLRect.
|
| Revision 1.4 2001/09/16 19:03:22 uzadow
| Added global name prefix PL, changed most filenames.
|
| Revision 1.3 2000/11/21 20:20:36 uzadow
| Changed bool to bool.
|
| Revision 1.2 2000/01/10 23:52:59 Ulrich von Zadow
| Changed formatting & removed tabs.
|
| Revision 1.1 1999/12/09 16:35:58 Ulrich von Zadow
| Added PLRect.
|
|
\--------------------------------------------------------------------
*/
|