1/* 2 * Copyright 2001-2014 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Frans van Nispen 7 * John Scipione, jscipione@gmail.com 8 */ 9 10 11#include <Point.h> 12 13#include <algorithm> 14 15#include <stdio.h> 16 17#include <SupportDefs.h> 18#include <Rect.h> 19 20 21const BPoint B_ORIGIN(0, 0); 22 23 24void 25BPoint::ConstrainTo(BRect rect) 26{ 27 x = std::max(std::min(x, rect.right), rect.left); 28 y = std::max(std::min(y, rect.bottom), rect.top); 29} 30 31 32void 33BPoint::PrintToStream() const 34{ 35 printf("BPoint(x:%.0f, y:%.0f)\n", x, y); 36} 37 38 39BPoint 40BPoint::operator-() const 41{ 42 return BPoint(-x, -y); 43} 44 45 46BPoint 47BPoint::operator+(const BPoint& other) const 48{ 49 return BPoint(x + other.x, y + other.y); 50} 51 52 53BPoint 54BPoint::operator-(const BPoint& other) const 55{ 56 return BPoint(x - other.x, y - other.y); 57} 58 59 60BPoint& 61BPoint::operator+=(const BPoint& other) 62{ 63 x += other.x; 64 y += other.y; 65 66 return *this; 67} 68 69 70BPoint& 71BPoint::operator-=(const BPoint& other) 72{ 73 x -= other.x; 74 y -= other.y; 75 76 return *this; 77} 78 79 80bool 81BPoint::operator!=(const BPoint& other) const 82{ 83 return x != other.x || y != other.y; 84} 85 86 87bool 88BPoint::operator==(const BPoint& other) const 89{ 90 return x == other.x && y == other.y; 91} 92