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