1 /* 2 * Copyright 2001-2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Frans van Nispen 7 * Stephan Aßmus <superstippi@gmx.de> 8 */ 9 10 11 #include "IntPoint.h" 12 13 #include <stdio.h> 14 15 #include "IntRect.h" 16 17 18 void 19 IntPoint::ConstrainTo(const IntRect& r) 20 { 21 x = max_c(min_c(x, r.right), r.left); 22 y = max_c(min_c(y, r.bottom), r.top); 23 } 24 25 26 void 27 IntPoint::PrintToStream() const 28 { 29 printf("IntPoint(x:%ld, y:%ld)\n", x, y); 30 } 31 32 33 IntPoint 34 IntPoint::operator+(const IntPoint& p) const 35 { 36 return IntPoint(x + p.x, y + p.y); 37 } 38 39 40 IntPoint 41 IntPoint::operator-(const IntPoint& p) const 42 { 43 return IntPoint(x - p.x, y - p.y); 44 } 45 46 47 IntPoint & 48 IntPoint::operator+=(const IntPoint& p) 49 { 50 x += p.x; 51 y += p.y; 52 53 return *this; 54 } 55 56 57 IntPoint & 58 IntPoint::operator-=(const IntPoint& p) 59 { 60 x -= p.x; 61 y -= p.y; 62 63 return *this; 64 } 65 66 67 bool 68 IntPoint::operator!=(const IntPoint& p) const 69 { 70 return x != p.x || y != p.y; 71 } 72 73 74 bool 75 IntPoint::operator==(const IntPoint& p) const 76 { 77 return x == p.x && y == p.y; 78 } 79 80