blob: 1d7f64d30732c0cf44834d4e50358ed8054da412 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Agopian8683fca2012-08-12 19:37:16 -070020#include <utils/Flattenable.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021#include <utils/TypeHelpers.h>
22
23namespace android {
24
Mathias Agopian8683fca2012-08-12 19:37:16 -070025class Point : public LightFlattenablePod<Point>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026{
27public:
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 Agopian35801ce2009-05-26 17:44:57 -070035 inline Point() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036 }
Mathias Agopian35801ce2009-05-26 17:44:57 -070037 inline Point(int x, int y) : x(x), y(y) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038 }
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 Agopian35801ce2009-05-26 17:44:57 -070058 x = -x;
59 y = -y;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 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 Agopian35801ce2009-05-26 17:44:57 -070074 const Point operator + (const Point& rhs) const {
75 const Point result(x+rhs.x, y+rhs.y);
76 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 }
Mathias Agopian35801ce2009-05-26 17:44:57 -070078 const Point operator - (const Point& rhs) const {
79 const Point result(x-rhs.x, y-rhs.y);
80 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 }
82};
83
84ANDROID_BASIC_TYPES_TRAITS(Point)
85
86}; // namespace android
87
88#endif // ANDROID_UI_POINT