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 <stdio.h> 12 13 #include <SupportDefs.h> 14 #include <Rect.h> 15 16 17 const BPoint B_ORIGIN(0, 0); 18 19 20 void 21 BPoint::ConstrainTo(BRect r) 22 { 23 x = max_c(min_c(x, r.right), r.left); 24 y = max_c(min_c(y, r.bottom), r.top); 25 } 26 27 28 void 29 BPoint::PrintToStream() const 30 { 31 printf("BPoint(x:%.0f, y:%.0f)\n", x, y); 32 } 33 34 35 BPoint 36 BPoint::operator-() const 37 { 38 return BPoint(-x, -y); 39 } 40 41 42 BPoint 43 BPoint::operator+(const BPoint& p) const 44 { 45 return BPoint(x + p.x, y + p.y); 46 } 47 48 49 BPoint 50 BPoint::operator-(const BPoint& p) const 51 { 52 return BPoint(x - p.x, y - p.y); 53 } 54 55 56 BPoint & 57 BPoint::operator+=(const BPoint& p) 58 { 59 x += p.x; 60 y += p.y; 61 62 return *this; 63 } 64 65 66 BPoint & 67 BPoint::operator-=(const BPoint& p) 68 { 69 x -= p.x; 70 y -= p.y; 71 72 return *this; 73 } 74 75 76 bool 77 BPoint::operator!=(const BPoint& p) const 78 { 79 return x != p.x || y != p.y; 80 } 81 82 83 bool 84 BPoint::operator==(const BPoint& p) const 85 { 86 return x == p.x && y == p.y; 87 } 88 89