| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |  | 
|  | 17 | #ifndef ANDROID_UI_POINT | 
|  | 18 | #define ANDROID_UI_POINT | 
|  | 19 |  | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 20 | #include <utils/Flattenable.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/TypeHelpers.h> | 
|  | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 |  | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 25 | class Point : public LightFlattenablePod<Point> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | { | 
|  | 27 | public: | 
|  | 28 | int x; | 
|  | 29 | int y; | 
|  | 30 |  | 
|  | 31 | // we don't provide copy-ctor and operator= on purpose | 
|  | 32 | // because we want the compiler generated versions | 
|  | 33 |  | 
|  | 34 | // Default constructor doesn't initialize the Point | 
| Mathias Agopian | 35801ce | 2009-05-26 17:44:57 -0700 | [diff] [blame] | 35 | inline Point() { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | } | 
| Colin Cross | 382ecd3 | 2016-09-26 13:33:59 -0700 | [diff] [blame] | 37 | inline Point(int _x, int _y) : x(_x), y(_y) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | } | 
|  | 39 |  | 
|  | 40 | inline bool operator == (const Point& rhs) const { | 
|  | 41 | return (x == rhs.x) && (y == rhs.y); | 
|  | 42 | } | 
|  | 43 | inline bool operator != (const Point& rhs) const { | 
|  | 44 | return !operator == (rhs); | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | inline bool isOrigin() const { | 
|  | 48 | return !(x|y); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | // operator < defines an order which allows to use points in sorted | 
|  | 52 | // vectors. | 
|  | 53 | bool operator < (const Point& rhs) const { | 
|  | 54 | return y<rhs.y || (y==rhs.y && x<rhs.x); | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | inline Point& operator - () { | 
| Mathias Agopian | 35801ce | 2009-05-26 17:44:57 -0700 | [diff] [blame] | 58 | x = -x; | 
|  | 59 | y = -y; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | return *this; | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | inline Point& operator += (const Point& rhs) { | 
|  | 64 | x += rhs.x; | 
|  | 65 | y += rhs.y; | 
|  | 66 | return *this; | 
|  | 67 | } | 
|  | 68 | inline Point& operator -= (const Point& rhs) { | 
|  | 69 | x -= rhs.x; | 
|  | 70 | y -= rhs.y; | 
|  | 71 | return *this; | 
|  | 72 | } | 
|  | 73 |  | 
| Mathias Agopian | 35801ce | 2009-05-26 17:44:57 -0700 | [diff] [blame] | 74 | const Point operator + (const Point& rhs) const { | 
|  | 75 | const Point result(x+rhs.x, y+rhs.y); | 
|  | 76 | return result; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | } | 
| Mathias Agopian | 35801ce | 2009-05-26 17:44:57 -0700 | [diff] [blame] | 78 | const Point operator - (const Point& rhs) const { | 
|  | 79 | const Point result(x-rhs.x, y-rhs.y); | 
|  | 80 | return result; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | } | 
|  | 82 | }; | 
|  | 83 |  | 
|  | 84 | ANDROID_BASIC_TYPES_TRAITS(Point) | 
|  | 85 |  | 
|  | 86 | }; // namespace android | 
|  | 87 |  | 
|  | 88 | #endif // ANDROID_UI_POINT |