btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / interface / Point.cpp
blobcf35ccdd67ce83e604d4343506667044d242dae7
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 <Point.h>
13 #include <algorithm>
15 #include <stdio.h>
17 #include <SupportDefs.h>
18 #include <Rect.h>
21 const BPoint B_ORIGIN(0, 0);
24 void
25 BPoint::ConstrainTo(BRect rect)
27 x = std::max(std::min(x, rect.right), rect.left);
28 y = std::max(std::min(y, rect.bottom), rect.top);
32 void
33 BPoint::PrintToStream() const
35 printf("BPoint(x:%.0f, y:%.0f)\n", x, y);
39 BPoint
40 BPoint::operator-() const
42 return BPoint(-x, -y);
46 BPoint
47 BPoint::operator+(const BPoint& other) const
49 return BPoint(x + other.x, y + other.y);
53 BPoint
54 BPoint::operator-(const BPoint& other) const
56 return BPoint(x - other.x, y - other.y);
60 BPoint&
61 BPoint::operator+=(const BPoint& other)
63 x += other.x;
64 y += other.y;
66 return *this;
70 BPoint&
71 BPoint::operator-=(const BPoint& other)
73 x -= other.x;
74 y -= other.y;
76 return *this;
80 bool
81 BPoint::operator!=(const BPoint& other) const
83 return x != other.x || y != other.y;
87 bool
88 BPoint::operator==(const BPoint& other) const
90 return x == other.x && y == other.y;