xref: /haiku/src/kits/interface/Point.cpp (revision c90684742e7361651849be4116d0e5de3a817194)
1 /*
2  * Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Frans van Nispen
7  */
8 
9 #include <Point.h>
10 
11 #include <math.h>
12 #include <stdio.h>
13 
14 #include <SupportDefs.h>
15 #include <Rect.h>
16 
17 
18 const BPoint B_ORIGIN(0, 0);
19 
20 
21 void
22 BPoint::ConstrainTo(BRect r)
23 {
24 	x = max_c(min_c(x, r.right), r.left);
25 	y = max_c(min_c(y, r.bottom), r.top);
26 }
27 
28 
29 void
30 BPoint::PrintToStream() const
31 {
32 	printf("BPoint(x:%.0f, y:%.0f)\n", x, y);
33 }
34 
35 
36 BPoint
37 BPoint::operator-() const
38 {
39 	return BPoint(-x, -y);
40 }
41 
42 
43 BPoint
44 BPoint::operator+(const BPoint& p) const
45 {
46 	return BPoint(x + p.x, y + p.y);
47 }
48 
49 
50 BPoint
51 BPoint::operator-(const BPoint& p) const
52 {
53 	return BPoint(x - p.x, y - p.y);
54 }
55 
56 
57 BPoint &
58 BPoint::operator+=(const BPoint& p)
59 {
60 	x += p.x;
61 	y += p.y;
62 
63 	return *this;
64 }
65 
66 
67 BPoint &
68 BPoint::operator-=(const BPoint& p)
69 {
70 	x -= p.x;
71 	y -= p.y;
72 
73 	return *this;
74 }
75 
76 
77 bool
78 BPoint::operator!=(const BPoint& p) const
79 {
80 	return x != p.x || y != p.y;
81 }
82 
83 
84 bool
85 BPoint::operator==(const BPoint& p) const
86 {
87 	return x == p.x && y == p.y;
88 }
89 
90