]> Dogcows Code - chaz/openbox/blob - otk/rect.cc
initial commit
[chaz/openbox] / otk / rect.cc
1 #include "rect.hh"
2
3 namespace otk {
4
5 void Rect::setX(int x)
6 {
7 _x2 += x - _x1;
8 _x1 = x;
9 }
10
11
12 void Rect::setY(int y)
13 {
14 _y2 += y - _y1;
15 _y1 = y;
16 }
17
18
19 void Rect::setPos(const Point &location)
20 {
21 _x2 += location.x() - _x1;
22 _x1 = location.x();
23 _y2 += location.y() - _y1;
24 _y1 = location.y();
25 }
26
27
28 void Rect::setPos(int x, int y)
29 {
30 _x2 += x - _x1;
31 _x1 = x;
32 _y2 += y - _y1;
33 _y1 = y;
34 }
35
36
37 void Rect::setWidth(int w)
38 {
39 _x2 = w + _x1 - 1;
40 }
41
42
43 void Rect::setHeight(int h)
44 {
45 _y2 = h + _y1 - 1;
46 }
47
48
49 void Rect::setSize(int w, int h)
50 {
51 _x2 = w + _x1 - 1;
52 _y2 = h + _y1 - 1;
53 }
54
55
56 void Rect::setSize(const Point &size)
57 {
58 _x2 = size.x() + _x1 - 1;
59 _y2 = size.y() + _y1 - 1;
60 }
61
62
63 void Rect::setRect(int x, int y, int w, int h)
64 {
65 *this = Rect(x, y, w, h);
66 }
67
68
69 void Rect::setRect(const Point &location, const Point &size)
70 {
71 *this = Rect(location, size);
72 }
73
74
75 void Rect::setCoords(int l, int t, int r, int b)
76 {
77 _x1 = l;
78 _y1 = t;
79 _x2 = r;
80 _y2 = b;
81 }
82
83
84 void Rect::setCoords(const Point &tl, const Point &br)
85 {
86 _x1 = tl.x();
87 _y1 = tl.y();
88 _x2 = br.x();
89 _y2 = br.y();
90 }
91
92
93 Rect Rect::operator|(const Rect &a) const
94 {
95 Rect b;
96
97 b._x1 = std::min(_x1, a._x1);
98 b._y1 = std::min(_y1, a._y1);
99 b._x2 = std::max(_x2, a._x2);
100 b._y2 = std::max(_y2, a._y2);
101
102 return b;
103 }
104
105
106 Rect Rect::operator&(const Rect &a) const
107 {
108 Rect b;
109
110 b._x1 = std::max(_x1, a._x1);
111 b._y1 = std::max(_y1, a._y1);
112 b._x2 = std::min(_x2, a._x2);
113 b._y2 = std::min(_y2, a._y2);
114
115 return b;
116 }
117
118
119 bool Rect::intersects(const Rect &a) const
120 {
121 return std::max(_x1, a._x1) <= std::min(_x2, a._x2) &&
122 std::max(_y1, a._y1) <= std::min(_y2, a._y2);
123 }
124
125
126 bool Rect::contains(int x, int y) const
127 {
128 return x >= _x1 && x <= _x2 &&
129 y >= _y1 && y <= _y2;
130 }
131
132
133 bool Rect::contains(const Rect& a) const
134 {
135 return a._x1 >= _x1 && a._x2 <= _x2 &&
136 a._y1 >= _y1 && a._y2 <= _y2;
137 }
138
139 }
This page took 0.041689 seconds and 4 git commands to generate.