2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_UI_POINT
18 #define ANDROID_UI_POINT
20 #include <utils/Flattenable.h>
21 #include <utils/TypeHelpers.h>
25 class Point : public LightFlattenablePod<Point>
31 // we don't provide copy-ctor and operator= on purpose
32 // because we want the compiler generated versions
34 // Default constructor doesn't initialize the Point
37 inline Point(int x, int y) : x(x), y(y) {
40 inline bool operator == (const Point& rhs) const {
41 return (x == rhs.x) && (y == rhs.y);
43 inline bool operator != (const Point& rhs) const {
44 return !operator == (rhs);
47 inline bool isOrigin() const {
51 // operator < defines an order which allows to use points in sorted
53 bool operator < (const Point& rhs) const {
54 return y<rhs.y || (y==rhs.y && x<rhs.x);
57 inline Point& operator - () {
63 inline Point& operator += (const Point& rhs) {
68 inline Point& operator -= (const Point& rhs) {
74 const Point operator + (const Point& rhs) const {
75 const Point result(x+rhs.x, y+rhs.y);
78 const Point operator - (const Point& rhs) const {
79 const Point result(x-rhs.x, y-rhs.y);
84 ANDROID_BASIC_TYPES_TRAITS(Point)
86 }; // namespace android
88 #endif // ANDROID_UI_POINT