1 /*
2 * Copyright 2001-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Frans van Nispen
7 * John Scipione, jscipione@gmail.com
8 */
9
10
11 #include <Point.h>
12
13 #include <algorithm>
14
15 #include <stdio.h>
16
17 #include <SupportDefs.h>
18 #include <Rect.h>
19
20
21 const BPoint B_ORIGIN(0, 0);
22
23
24 void
ConstrainTo(BRect rect)25 BPoint::ConstrainTo(BRect rect)
26 {
27 x = std::max(std::min(x, rect.right), rect.left);
28 y = std::max(std::min(y, rect.bottom), rect.top);
29 }
30
31
32 void
PrintToStream() const33 BPoint::PrintToStream() const
34 {
35 printf("BPoint(x:%f, y:%f)\n", x, y);
36 }
37
38
39 BPoint
operator -() const40 BPoint::operator-() const
41 {
42 return BPoint(-x, -y);
43 }
44
45
46 BPoint
operator +(const BPoint & other) const47 BPoint::operator+(const BPoint& other) const
48 {
49 return BPoint(x + other.x, y + other.y);
50 }
51
52
53 BPoint
operator -(const BPoint & other) const54 BPoint::operator-(const BPoint& other) const
55 {
56 return BPoint(x - other.x, y - other.y);
57 }
58
59
60 BPoint&
operator +=(const BPoint & other)61 BPoint::operator+=(const BPoint& other)
62 {
63 x += other.x;
64 y += other.y;
65
66 return *this;
67 }
68
69
70 BPoint&
operator -=(const BPoint & other)71 BPoint::operator-=(const BPoint& other)
72 {
73 x -= other.x;
74 y -= other.y;
75
76 return *this;
77 }
78
79
80 bool
operator !=(const BPoint & other) const81 BPoint::operator!=(const BPoint& other) const
82 {
83 return x != other.x || y != other.y;
84 }
85
86
87 bool
operator ==(const BPoint & other) const88 BPoint::operator==(const BPoint& other) const
89 {
90 return x == other.x && y == other.y;
91 }
92