1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef ANDROID_UI_POINT 17 #define ANDROID_UI_POINT 18 #include <utils/Flattenable.h> 19 #include <utils/TypeHelpers.h> 20 namespace android { 21 class Point : public LightFlattenablePod<Point> 22 { 23 public: 24 int x; 25 int y; 26 // we don't provide copy-ctor and operator= on purpose 27 // because we want the compiler generated versions 28 // Default constructor doesn't initialize the Point Point()29 inline Point() { 30 } Point(int _x,int _y)31 inline Point(int _x, int _y) : x(_x), y(_y) { 32 } 33 inline bool operator == (const Point& rhs) const { 34 return (x == rhs.x) && (y == rhs.y); 35 } 36 inline bool operator != (const Point& rhs) const { 37 return !operator == (rhs); 38 } isOrigin()39 inline bool isOrigin() const { 40 return !(x|y); 41 } 42 // operator < defines an order which allows to use points in sorted 43 // vectors. 44 bool operator < (const Point& rhs) const { 45 return y<rhs.y || (y==rhs.y && x<rhs.x); 46 } 47 inline Point& operator - () { 48 x = -x; 49 y = -y; 50 return *this; 51 } 52 53 inline Point& operator += (const Point& rhs) { 54 x += rhs.x; 55 y += rhs.y; 56 return *this; 57 } 58 inline Point& operator -= (const Point& rhs) { 59 x -= rhs.x; 60 y -= rhs.y; 61 return *this; 62 } 63 64 const Point operator + (const Point& rhs) const { 65 const Point result(x+rhs.x, y+rhs.y); 66 return result; 67 } 68 const Point operator - (const Point& rhs) const { 69 const Point result(x-rhs.x, y-rhs.y); 70 return result; 71 } 72 }; 73 ANDROID_BASIC_TYPES_TRAITS(Point) 74 }; // namespace android 75 #endif // ANDROID_UI_POINT 76