1 /*
2 * Copyright 2001-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _POINT_H
6 #define _POINT_H
7
8
9 #include <SupportDefs.h>
10
11
12 class BRect;
13
14
15 class BPoint {
16 public:
17 float x;
18 float y;
19
20 BPoint();
21 BPoint(float x, float y);
22 BPoint(const BPoint& p);
23
24 BPoint& operator=(const BPoint& other);
25 void Set(float x, float y);
26
27 void ConstrainTo(BRect rect);
28 void PrintToStream() const;
29
30 BPoint operator-() const;
31 BPoint operator+(const BPoint& other) const;
32 BPoint operator-(const BPoint& other) const;
33 BPoint& operator+=(const BPoint& other);
34 BPoint& operator-=(const BPoint& other);
35
36 bool operator!=(const BPoint& other) const;
37 bool operator==(const BPoint& other) const;
38 };
39
40
41 extern const BPoint B_ORIGIN;
42 // returns (0, 0)
43
44
45 inline
BPoint()46 BPoint::BPoint()
47 :
48 x(0.0f),
49 y(0.0f)
50 {
51 }
52
53
54 inline
BPoint(float x,float y)55 BPoint::BPoint(float x, float y)
56 :
57 x(x),
58 y(y)
59 {
60 }
61
62
63 inline
BPoint(const BPoint & other)64 BPoint::BPoint(const BPoint& other)
65 :
66 x(other.x),
67 y(other.y)
68 {
69 }
70
71
72 inline BPoint&
73 BPoint::operator=(const BPoint& other)
74 {
75 x = other.x;
76 y = other.y;
77 return *this;
78 }
79
80
81 inline void
Set(float x,float y)82 BPoint::Set(float x, float y)
83 {
84 this->x = x;
85 this->y = y;
86 }
87
88 #endif // _POINT_H
89