xref: /haiku/headers/os/interface/Point.h (revision 93a78ecaa45114d68952d08c4778f073515102f2)
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 #ifndef	_POINT_H
9 #define	_POINT_H
10 
11 #include <BeBuild.h>
12 #include <SupportDefs.h>
13 
14 
15 class BRect;
16 
17 class BPoint {
18 public:
19 	float x;
20 	float y;
21 
22 	BPoint();
23 	BPoint(float X, float Y);
24 	BPoint(const BPoint &p);
25 
26 	BPoint	&operator=(const BPoint &p);
27 	void	Set(float X, float Y);
28 
29 	void	ConstrainTo(BRect r);
30 	void	PrintToStream() const;
31 
32 	BPoint	operator-() const;
33 	BPoint	operator+(const BPoint &p) const;
34 	BPoint	operator-(const BPoint &p) const;
35 	BPoint&	operator+=(const BPoint &p);
36 	BPoint&	operator-=(const BPoint &p);
37 
38 	bool	operator!=(const BPoint &p) const;
39 	bool	operator==(const BPoint &p) const;
40 };
41 
42 extern _IMPEXP_BE const BPoint B_ORIGIN;	// returns (0,0)
43 
44 
45 inline
46 BPoint::BPoint()
47 {
48 	x = y = 0;
49 }
50 
51 
52 inline
53 BPoint::BPoint(float X, float Y)
54 {
55 	x = X;
56 	y = Y;
57 }
58 
59 
60 inline
61 BPoint::BPoint(const BPoint& pt)
62 {
63 	x = pt.x;
64 	y = pt.y;
65 }
66 
67 
68 inline BPoint &
69 BPoint::operator=(const BPoint& from)
70 {
71 	x = from.x;
72 	y = from.y;
73 	return *this;
74 }
75 
76 
77 inline void
78 BPoint::Set(float X, float Y)
79 {
80 	x = X;
81 	y = Y;
82 }
83 
84 #endif	// _POINT_H
85