| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_POINT_BASE_H_ | 5 #ifndef UI_GFX_POINT_BASE_H_ |
| 6 #define UI_GFX_POINT_BASE_H_ | 6 #define UI_GFX_POINT_BASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 void set_x(Type x) { x_ = x; } | 28 void set_x(Type x) { x_ = x; } |
| 29 void set_y(Type y) { y_ = y; } | 29 void set_y(Type y) { y_ = y; } |
| 30 | 30 |
| 31 void Offset(Type delta_x, Type delta_y) { | 31 void Offset(Type delta_x, Type delta_y) { |
| 32 x_ += delta_x; | 32 x_ += delta_x; |
| 33 y_ += delta_y; | 33 y_ += delta_y; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void operator+=(const VectorClass& vector) { | 36 void operator+=(const VectorClass& vector) { |
| 37 Offset(vector.x(), vector.y()); | 37 x_ += vector.x(); |
| 38 y_ += vector.y(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void operator-=(const VectorClass& vector) { | 41 void operator-=(const VectorClass& vector) { |
| 41 Offset(-vector.x(), -vector.y()); | 42 x_ -= vector.x(); |
| 43 y_ -= vector.y(); |
| 42 } | 44 } |
| 43 | 45 |
| 44 bool IsOrigin() const { | 46 bool IsOrigin() const { |
| 45 return x_ == 0 && y_ == 0; | 47 return x_ == 0 && y_ == 0; |
| 46 } | 48 } |
| 47 | 49 |
| 48 VectorClass OffsetFromOrigin() const { | 50 VectorClass OffsetFromOrigin() const { |
| 49 return VectorClass(x_, y_); | 51 return VectorClass(x_, y_); |
| 50 } | 52 } |
| 51 | 53 |
| 52 VectorClass OffsetFrom(const Class& other) const { | |
| 53 return VectorClass(x_ - other.x_, y_ - other.y_); | |
| 54 } | |
| 55 | |
| 56 // A point is less than another point if its y-value is closer | 54 // A point is less than another point if its y-value is closer |
| 57 // to the origin. If the y-values are the same, then point with | 55 // to the origin. If the y-values are the same, then point with |
| 58 // the x-value closer to the origin is considered less than the | 56 // the x-value closer to the origin is considered less than the |
| 59 // other. | 57 // other. |
| 60 // This comparison is required to use Point in sets, or sorted | 58 // This comparison is required to use Point in sets, or sorted |
| 61 // vectors. | 59 // vectors. |
| 62 bool operator<(const Class& rhs) const { | 60 bool operator<(const Class& rhs) const { |
| 63 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); | 61 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); |
| 64 } | 62 } |
| 65 | 63 |
| 66 protected: | 64 protected: |
| 67 PointBase(Type x, Type y) : x_(x), y_(y) {} | 65 PointBase(Type x, Type y) : x_(x), y_(y) {} |
| 68 // Destructor is intentionally made non virtual and protected. | 66 // Destructor is intentionally made non virtual and protected. |
| 69 // Do not make this public. | 67 // Do not make this public. |
| 70 ~PointBase() {} | 68 ~PointBase() {} |
| 71 | 69 |
| 72 private: | 70 private: |
| 73 Type x_; | 71 Type x_; |
| 74 Type y_; | 72 Type y_; |
| 75 }; | 73 }; |
| 76 | 74 |
| 77 } // namespace gfx | 75 } // namespace gfx |
| 78 | 76 |
| 79 #endif // UI_GFX_POINT_BASE_H_ | 77 #endif // UI_GFX_POINT_BASE_H_ |
| OLD | NEW |