btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / interface / Rect.cpp
blob3c9a0d659ac08902aedc0745a69d86ae86bb741b
1 /*
2 * Copyright 2001-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Frans van Nispen
7 * John Scipione, jscipione@gmail.com
8 */
11 #include <Rect.h>
13 #include <algorithm>
15 #include <stdio.h>
18 void
19 BRect::SetLeftTop(const BPoint point)
21 left = point.x;
22 top = point.y;
26 void
27 BRect::SetRightBottom(const BPoint point)
29 right = point.x;
30 bottom = point.y;
34 void
35 BRect::SetLeftBottom(const BPoint point)
37 left = point.x;
38 bottom = point.y;
42 void
43 BRect::SetRightTop(const BPoint point)
45 right = point.x;
46 top = point.y;
50 void
51 BRect::InsetBy(BPoint point)
53 left += point.x;
54 right -= point.x;
55 top += point.y;
56 bottom -= point.y;
60 void
61 BRect::InsetBy(float dx, float dy)
63 left += dx;
64 right -= dx;
65 top += dy;
66 bottom -= dy;
70 BRect&
71 BRect::InsetBySelf(BPoint point)
73 InsetBy(point);
74 return *this;
78 BRect&
79 BRect::InsetBySelf(float dx, float dy)
81 InsetBy(dx, dy);
82 return *this;
86 BRect
87 BRect::InsetByCopy(BPoint point) const
89 BRect copy(*this);
90 copy.InsetBy(point);
91 return copy;
95 BRect
96 BRect::InsetByCopy(float dx, float dy) const
98 BRect copy(*this);
99 copy.InsetBy(dx, dy);
100 return copy;
104 void
105 BRect::OffsetBy(BPoint point)
107 left += point.x;
108 right += point.x;
109 top += point.y;
110 bottom += point.y;
114 void
115 BRect::OffsetBy(float dx, float dy)
117 left += dx;
118 right += dx;
119 top += dy;
120 bottom += dy;
124 BRect&
125 BRect::OffsetBySelf(BPoint point)
127 OffsetBy(point);
128 return *this;
132 BRect&
133 BRect::OffsetBySelf(float dx, float dy)
135 OffsetBy(dx, dy);
136 return *this;
140 BRect
141 BRect::OffsetByCopy(BPoint point) const
143 BRect copy(*this);
144 copy.OffsetBy(point);
145 return copy;
149 BRect
150 BRect::OffsetByCopy(float dx, float dy) const
152 BRect copy(*this);
153 copy.OffsetBy(dx, dy);
154 return copy;
158 void
159 BRect::OffsetTo(BPoint point)
161 right = (right - left) + point.x;
162 left = point.x;
163 bottom = (bottom - top) + point.y;
164 top = point.y;
168 void
169 BRect::OffsetTo(float x, float y)
171 right = (right - left) + x;
172 left = x;
173 bottom = (bottom - top) + y;
174 top=y;
178 BRect&
179 BRect::OffsetToSelf(BPoint point)
181 OffsetTo(point);
182 return *this;
186 BRect&
187 BRect::OffsetToSelf(float x, float y)
189 OffsetTo(x, y);
190 return *this;
194 BRect
195 BRect::OffsetToCopy(BPoint point) const
197 BRect copy(*this);
198 copy.OffsetTo(point);
199 return copy;
203 BRect
204 BRect::OffsetToCopy(float x, float y) const
206 BRect copy(*this);
207 copy.OffsetTo(x, y);
208 return copy;
212 void
213 BRect::PrintToStream() const
215 printf("BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n", left, top, right, bottom);
219 bool
220 BRect::operator==(BRect other) const
222 return left == other.left && right == other.right &&
223 top == other.top && bottom == other.bottom;
227 bool
228 BRect::operator!=(BRect other) const
230 return !(*this == other);
234 BRect
235 BRect::operator&(BRect other) const
237 return BRect(std::max(left, other.left), std::max(top, other.top),
238 std::min(right, other.right), std::min(bottom, other.bottom));
242 BRect
243 BRect::operator|(BRect other) const
245 return BRect(std::min(left, other.left), std::min(top, other.top),
246 std::max(right, other.right), std::max(bottom, other.bottom));
250 bool
251 BRect::Intersects(BRect rect) const
253 if (!IsValid() || !rect.IsValid())
254 return false;
256 return !(rect.left > right || rect.right < left
257 || rect.top > bottom || rect.bottom < top);
261 bool
262 BRect::Contains(BPoint point) const
264 return point.x >= left && point.x <= right
265 && point.y >= top && point.y <= bottom;
269 bool
270 BRect::Contains(BRect rect) const
272 return rect.left >= left && rect.right <= right
273 && rect.top >= top && rect.bottom <= bottom;
277 // #pragma mark - BeOS compatibility only
278 #if __GNUC__ == 2
281 extern "C" BRect
282 InsetByCopy__5BRectG6BPoint(BRect* self, BPoint point)
284 BRect copy(*self);
285 copy.InsetBy(point);
286 return copy;
290 extern "C" BRect
291 InsetByCopy__5BRectff(BRect* self, float dx, float dy)
293 BRect copy(*self);
294 copy.InsetBy(dx, dy);
295 return copy;
299 extern "C" BRect
300 OffsetByCopy__5BRectG6BPoint(BRect* self, BPoint point)
302 BRect copy(*self);
303 copy.OffsetBy(point);
304 return copy;
308 extern "C" BRect
309 OffsetByCopy__5BRectff(BRect* self, float dx, float dy)
311 BRect copy(*self);
312 copy.OffsetBy(dx, dy);
313 return copy;
317 extern "C" BRect
318 OffsetToCopy__5BRectG6BPoint(BRect* self, BPoint point)
320 BRect copy(*self);
321 copy.OffsetTo(point);
322 return copy;
326 extern "C" BRect
327 OffsetToCopy__5BRectff(BRect* self, float dx, float dy)
329 BRect copy(*self);
330 copy.OffsetTo(dx, dy);
331 return copy;
335 #elif __GNUC__ >= 4
336 // TODO: remove this when new GCC 4 packages have to be built anyway
339 extern "C" BRect
340 _ZN5BRect11InsetByCopyE6BPoint(BRect* self, BPoint point)
342 BRect copy(*self);
343 copy.InsetBy(point);
344 return copy;
348 extern "C" BRect
349 _ZN5BRect11InsetByCopyEff(BRect* self, float dx, float dy)
351 BRect copy(*self);
352 copy.InsetBy(dx, dy);
353 return copy;
357 extern "C" BRect
358 _ZN5BRect12OffsetByCopyE6BPoint(BRect* self, BPoint point)
360 BRect copy(*self);
361 copy.OffsetBy(point);
362 return copy;
366 extern "C" BRect
367 _ZN5BRect12OffsetByCopyEff(BRect* self, float dx, float dy)
369 BRect copy(*self);
370 copy.OffsetBy(dx, dy);
371 return copy;
375 extern "C" BRect
376 _ZN5BRect12OffsetToCopyE6BPoint(BRect* self, BPoint point)
378 BRect copy(*self);
379 copy.OffsetTo(point);
380 return copy;
384 extern "C" BRect
385 _ZN5BRect12OffsetToCopyEff(BRect* self, float dx, float dy)
387 BRect copy(*self);
388 copy.OffsetTo(dx, dy);
389 return copy;
393 #endif // __GNUC__ >= 4