xref: /haiku/src/kits/interface/Point.cpp (revision e79e4e7c9e432c90415f79809b7160e864f79001)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		Point.cpp
23 //	Author:			Frans van Nispen
24 //	Description:	BPoint represents a single x,y coordinate.
25 //------------------------------------------------------------------------------
26 
27 // Standard Includes -----------------------------------------------------------
28 #include <math.h>
29 #include <stdio.h>
30 
31 // System Includes -------------------------------------------------------------
32 #include <BeBuild.h>
33 #include <SupportDefs.h>
34 #include <Point.h>
35 #include <Rect.h>
36 
37 // Project Includes ------------------------------------------------------------
38 
39 // Local Includes --------------------------------------------------------------
40 
41 // Local Defines ---------------------------------------------------------------
42 
43 // Globals ---------------------------------------------------------------------
44 
45 
46 //------------------------------------------------------------------------------
47 void BPoint::ConstrainTo(BRect r)
48 {
49 	x = max_c(min_c(x, r.right), r.left);
50 	y = max_c(min_c(y, r.bottom), r.top);
51 }
52 //------------------------------------------------------------------------------
53 void BPoint::PrintToStream() const
54 {
55 	printf("BPoint(x:%.0f, y:%.0f)\n", x, y);
56 }
57 //------------------------------------------------------------------------------
58 BPoint BPoint::operator+(const BPoint& p) const
59 {
60 	return BPoint(x + p.x, y + p.y);
61 }
62 //------------------------------------------------------------------------------
63 BPoint BPoint::operator-(const BPoint& p) const
64 {
65 	return BPoint(x - p.x, y - p.y);
66 }
67 //------------------------------------------------------------------------------
68 BPoint&	BPoint::operator+=(const BPoint& p)
69 {
70 	x += p.x;
71 	y += p.y;
72 
73 	return *this;
74 }
75 //------------------------------------------------------------------------------
76 BPoint&	BPoint::operator-=(const BPoint& p)
77 {
78 	x -= p.x;
79 	y -= p.y;
80 
81 	return *this;
82 }
83 //------------------------------------------------------------------------------
84 bool BPoint::operator!=(const BPoint& p) const
85 {
86 	return x != p.x || y != p.y;
87 }
88 //------------------------------------------------------------------------------
89 bool BPoint::operator==(const BPoint& p) const
90 {
91 	return x == p.x && y == p.y;
92 }
93 //------------------------------------------------------------------------------
94 
95 /*
96  * $Log $
97  *
98  * $Id  $
99  *
100  */
101 
102