xref: /haiku/src/kits/interface/Point.cpp (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
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
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
33 BPoint::PrintToStream() const
34 {
35 	printf("BPoint(x:%.0f, y:%.0f)\n", x, y);
36 }
37 
38 
39 BPoint
40 BPoint::operator-() const
41 {
42 	return BPoint(-x, -y);
43 }
44 
45 
46 BPoint
47 BPoint::operator+(const BPoint& other) const
48 {
49 	return BPoint(x + other.x, y + other.y);
50 }
51 
52 
53 BPoint
54 BPoint::operator-(const BPoint& other) const
55 {
56 	return BPoint(x - other.x, y - other.y);
57 }
58 
59 
60 BPoint&
61 BPoint::operator+=(const BPoint& other)
62 {
63 	x += other.x;
64 	y += other.y;
65 
66 	return *this;
67 }
68 
69 
70 BPoint&
71 BPoint::operator-=(const BPoint& other)
72 {
73 	x -= other.x;
74 	y -= other.y;
75 
76 	return *this;
77 }
78 
79 
80 bool
81 BPoint::operator!=(const BPoint& other) const
82 {
83 	return x != other.x || y != other.y;
84 }
85 
86 
87 bool
88 BPoint::operator==(const BPoint& other) const
89 {
90 	return x == other.x && y == other.y;
91 }
92