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.h 23 // Author: Frans van Nispen 24 // Description: BPoint represents a single x,y coordinate. 25 //------------------------------------------------------------------------------ 26 #ifndef _POINT_H 27 #define _POINT_H 28 29 // Standard Includes ----------------------------------------------------------- 30 31 // System Includes ------------------------------------------------------------- 32 #include <BeBuild.h> 33 #include <SupportDefs.h> 34 35 // Project Includes ------------------------------------------------------------ 36 37 // Local Includes -------------------------------------------------------------- 38 39 // Local Defines --------------------------------------------------------------- 40 41 // Globals --------------------------------------------------------------------- 42 43 44 class BRect; 45 46 // BPoint class ---------------------------------------------------------------- 47 class BPoint { 48 public: 49 float x; 50 float y; 51 52 BPoint(); 53 BPoint(float X, float Y); 54 BPoint(const BPoint &p); 55 56 BPoint &operator=(const BPoint &p); 57 void Set(float X, float Y); 58 59 void ConstrainTo(BRect r); 60 void PrintToStream() const; 61 62 BPoint operator+(const BPoint &p) const; 63 BPoint operator-(const BPoint &p) const; 64 BPoint& operator+=(const BPoint &p); 65 BPoint& operator-=(const BPoint &p); 66 67 bool operator!=(const BPoint &p) const; 68 bool operator==(const BPoint &p) const; 69 }; 70 //------------------------------------------------------------------------------ 71 72 extern _IMPEXP_BE const BPoint B_ORIGIN; // returns (0,0) 73 74 //------------------------------------------------------------------------------ 75 inline BPoint::BPoint() 76 { 77 x = y = 0; 78 } 79 //------------------------------------------------------------------------------ 80 inline BPoint::BPoint(float X, float Y) 81 { 82 x = X; 83 y = Y; 84 } 85 //------------------------------------------------------------------------------ 86 inline BPoint::BPoint(const BPoint& pt) 87 { 88 x = pt.x; 89 y = pt.y; 90 } 91 //------------------------------------------------------------------------------ 92 inline BPoint &BPoint::operator=(const BPoint& from) 93 { 94 x = from.x; 95 y = from.y; 96 return *this; 97 } 98 //------------------------------------------------------------------------------ 99 inline void BPoint::Set(float X, float Y) 100 { 101 x = X; 102 y = Y; 103 } 104 //------------------------------------------------------------------------------ 105 106 #endif // _POINT_H 107 108 /* 109 * $Log $ 110 * 111 * $Id $ 112 * 113 */ 114 115