usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / servers / app / IntRect.cpp
blob7c9a53d4c0c1830052a975ac7cfec2f42fb7f423
1 /*
2 * Copyright 2001-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Frans van Nispen
7 * Stephan Aßmus <superstippi@gmx.de>
8 */
10 #include "IntRect.h"
12 #include <stdio.h>
15 void
16 IntRect::SetLeftTop(const IntPoint& p)
18 left = p.x;
19 top = p.y;
23 void
24 IntRect::SetRightBottom(const IntPoint& p)
26 right = p.x;
27 bottom = p.y;
31 void
32 IntRect::SetLeftBottom(const IntPoint& p)
34 left = p.x;
35 bottom = p.y;
39 void
40 IntRect::SetRightTop(const IntPoint& p)
42 right = p.x;
43 top = p.y;
47 void
48 IntRect::InsetBy(const IntPoint& point)
50 left += point.x;
51 right -= point.x;
52 top += point.y;
53 bottom -= point.y;
57 void
58 IntRect::InsetBy(int32 dx, int32 dy)
60 left += dx;
61 right -= dx;
62 top += dy;
63 bottom -= dy;
67 IntRect&
68 IntRect::InsetBySelf(const IntPoint& point)
70 InsetBy(point);
71 return *this;
75 IntRect&
76 IntRect::InsetBySelf(int32 dx, int32 dy)
78 InsetBy(dx, dy);
79 return *this;
83 IntRect
84 IntRect::InsetByCopy(const IntPoint& point)
86 IntRect copy(*this);
87 copy.InsetBy(point);
88 return copy;
92 IntRect
93 IntRect::InsetByCopy(int32 dx, int32 dy)
95 IntRect copy(*this);
96 copy.InsetBy(dx, dy);
97 return copy;
101 void
102 IntRect::OffsetBy(const IntPoint& point)
104 left += point.x;
105 right += point.x;
106 top += point.y;
107 bottom += point.y;
111 void
112 IntRect::OffsetBy(int32 dx, int32 dy)
114 left += dx;
115 right += dx;
116 top += dy;
117 bottom += dy;
121 IntRect&
122 IntRect::OffsetBySelf(const IntPoint& point)
124 OffsetBy(point);
125 return *this;
129 IntRect&
130 IntRect::OffsetBySelf(int32 dx, int32 dy)
132 OffsetBy(dx, dy);
133 return *this;
137 IntRect
138 IntRect::OffsetByCopy(const IntPoint& point)
140 IntRect copy(*this);
141 copy.OffsetBy(point);
142 return copy;
146 IntRect
147 IntRect::OffsetByCopy(int32 dx, int32 dy)
149 IntRect copy(*this);
150 copy.OffsetBy(dx, dy);
151 return copy;
155 void
156 IntRect::OffsetTo(const IntPoint& point)
158 right = (right - left) + point.x;
159 left = point.x;
160 bottom = (bottom - top) + point.y;
161 top = point.y;
165 void
166 IntRect::OffsetTo(int32 x, int32 y)
168 right = (right - left) + x;
169 left = x;
170 bottom = (bottom - top) + y;
171 top=y;
175 IntRect&
176 IntRect::OffsetToSelf(const IntPoint& point)
178 OffsetTo(point);
179 return *this;
183 IntRect&
184 IntRect::OffsetToSelf(int32 dx, int32 dy)
186 OffsetTo(dx, dy);
187 return *this;
191 IntRect
192 IntRect::OffsetToCopy(const IntPoint& point)
194 IntRect copy(*this);
195 copy.OffsetTo(point);
196 return copy;
200 IntRect
201 IntRect::OffsetToCopy(int32 dx, int32 dy)
203 IntRect copy(*this);
204 copy.OffsetTo(dx, dy);
205 return copy;
209 void
210 IntRect::PrintToStream() const
212 printf("IntRect(l:%" B_PRId32 ", t:%" B_PRId32 ", r:%" B_PRId32 ", b:%"
213 B_PRId32 ")\n", left, top, right, bottom);
217 bool
218 IntRect::operator==(const IntRect& rect) const
220 return left == rect.left && right == rect.right &&
221 top == rect.top && bottom == rect.bottom;
225 bool
226 IntRect::operator!=(const IntRect& rect) const
228 return !(*this == rect);
232 IntRect
233 IntRect::operator&(const IntRect& rect) const
235 return IntRect(max_c(left, rect.left), max_c(top, rect.top),
236 min_c(right, rect.right), min_c(bottom, rect.bottom));
240 IntRect
241 IntRect::operator|(const IntRect& rect) const
243 return IntRect(min_c(left, rect.left), min_c(top, rect.top),
244 max_c(right, rect.right), max_c(bottom, rect.bottom));
248 bool
249 IntRect::Intersects(const IntRect& rect) const
251 if (!IsValid() || !rect.IsValid())
252 return false;
254 return !(rect.left > right || rect.right < left
255 || rect.top > bottom || rect.bottom < top);
259 bool
260 IntRect::Contains(const IntPoint& point) const
262 return point.x >= left && point.x <= right
263 && point.y >= top && point.y <= bottom;
267 bool
268 IntRect::Contains(const IntRect& rect) const
270 return rect.left >= left && rect.right <= right
271 && rect.top >= top && rect.bottom <= bottom;