Point.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef ANDROID_UI_POINT
  17. #define ANDROID_UI_POINT
  18. #include <utils/Flattenable.h>
  19. #include <utils/TypeHelpers.h>
  20. namespace android {
  21. class Point : public LightFlattenablePod<Point>
  22. {
  23. public:
  24. int x;
  25. int y;
  26. // we don't provide copy-ctor and operator= on purpose
  27. // because we want the compiler generated versions
  28. // Default constructor doesn't initialize the Point
  29. inline Point() {
  30. }
  31. inline Point(int x, int y) : x(x), y(y) {
  32. }
  33. inline bool operator == (const Point& rhs) const {
  34. return (x == rhs.x) && (y == rhs.y);
  35. }
  36. inline bool operator != (const Point& rhs) const {
  37. return !operator == (rhs);
  38. }
  39. inline bool isOrigin() const {
  40. return !(x|y);
  41. }
  42. // operator < defines an order which allows to use points in sorted
  43. // vectors.
  44. bool operator < (const Point& rhs) const {
  45. return y<rhs.y || (y==rhs.y && x<rhs.x);
  46. }
  47. inline Point& operator - () {
  48. x = -x;
  49. y = -y;
  50. return *this;
  51. }
  52. inline Point& operator += (const Point& rhs) {
  53. x += rhs.x;
  54. y += rhs.y;
  55. return *this;
  56. }
  57. inline Point& operator -= (const Point& rhs) {
  58. x -= rhs.x;
  59. y -= rhs.y;
  60. return *this;
  61. }
  62. const Point operator + (const Point& rhs) const {
  63. const Point result(x+rhs.x, y+rhs.y);
  64. return result;
  65. }
  66. const Point operator - (const Point& rhs) const {
  67. const Point result(x-rhs.x, y-rhs.y);
  68. return result;
  69. }
  70. };
  71. ANDROID_BASIC_TYPES_TRAITS(Point)
  72. }; // namespace android
  73. #endif // ANDROID_UI_POINT