7
//#pragma warning(disable: 4018)
8
template <class T> static const T& Min (const T& a, const T& b){ return (a<b) ? a : b;}
9
template <class T> static const T& Max (const T& a, const T& b){ return (a>b) ? a : b;}
14
//----------------------------------------------------------------------------
24
//----------------------------------------------------------------------------
25
Rect::Rect(t_int32 x_, t_int32 y_, t_int32 width_, t_int32 height_)
29
width = Max<int>(0, int(width_));
30
height = Max<int>(0, int(height_));
33
//----------------------------------------------------------------------------
39
//----------------------------------------------------------------------------
40
Rect::Rect(const Rect& r)
48
//----------------------------------------------------------------------------
49
Rect& Rect::operator = (const Rect& r)
60
//----------------------------------------------------------------------------
61
t_bool Rect::operator == (const Rect& r) const
63
if((x == r.x) && (y == r.y) && (width == r.width) && (height == r.height))
70
//----------------------------------------------------------------------------
71
t_bool Rect::operator != (const Rect& r) const
73
if((x == r.x) && (y == r.y) && (width == r.width) && (height == r.height))
80
void Rect::Set(t_int32 px, t_int32 py, t_int32 w, t_int32 h)
82
x = px; y = py; width = w; height = h;
85
void Rect::SetPosition(t_int32 px, t_int32 py)
90
void Rect::SetSize(t_int32 w, t_int32 h)
92
width = w; height = h;
95
//----------------------------------------------------------------------------
96
t_bool Rect::IsInside(const Point& p) const
98
return ((x <= p.x) && (x + width > p.x) &&
99
(y <= p.y) && (y + height > p.y));
102
t_bool Rect::IsPointInside(int x_, int y_) const
104
return ((x <= x_) && (x + width > x_) &&
105
(y <= y_) && (y + height > y_));
108
//----------------------------------------------------------------------------
109
Rect Rect::Intersect(const Rect& r) const
111
// Get the corner points.
112
const Point& ul1 = Point(x, y);
113
const Point& ul2 = Point(r.x, r.y);
114
int x = Max<int>(ul1.x, ul2.x);
115
int y = Max<int>(ul1.y, ul2.y);
116
int w = Min<int>(ul1.x + width, ul2.x + r.width) - x;
117
int h = Min<int>(ul1.y + height, ul2.y + r.height) - y;
124
return Rect(x, y, w, h);
127
//----------------------------------------------------------------------------
128
// expand the width by factor_x and the height by factor_y
129
void Rect::Expand(t_int32 dx, t_int32 dy)
140
//----------------------------------------------------------------------------
141
// expand the width by factor_x and the height by factor_y
142
Rect Rect::GetExpand(t_int32 dx, t_int32 dy) const
144
Rect r = Rect(x - dx, y - dy, width + 2*dx, height + 2*dy);
147
return Rect(0, 0, 0, 0);