• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include <utils/Flattenable.h>
21 #include <utils/TypeHelpers.h>
22 
23 namespace android {
24 
25 class Point : public LightFlattenablePod<Point>
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
Point()35     inline Point() {
36     }
Point(int x,int y)37     inline Point(int x, int y) : x(x), y(y) {
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 
isOrigin()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 - () {
58         x = -x;
59         y = -y;
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 
74     const Point operator + (const Point& rhs) const {
75         const Point result(x+rhs.x, y+rhs.y);
76         return result;
77     }
78     const Point operator - (const Point& rhs) const {
79         const Point result(x-rhs.x, y-rhs.y);
80         return result;
81     }
82 };
83 
84 ANDROID_BASIC_TYPES_TRAITS(Point)
85 
86 }; // namespace android
87 
88 #endif // ANDROID_UI_POINT
89