Index: ui/gfx/point_base.h |
diff --git a/ui/gfx/point_base.h b/ui/gfx/point_base.h |
index 34e32f58035010a3312dd692b4df7ad0436a28f6..acaefe17805df6bbc2aa241805175eedea6c6656 100644 |
--- a/ui/gfx/point_base.h |
+++ b/ui/gfx/point_base.h |
@@ -14,7 +14,7 @@ |
namespace gfx { |
// A point has an x and y coordinate. |
-template<typename Class, typename Type> |
+template<typename Class, typename Type, typename VectorClass> |
class UI_EXPORT PointBase { |
public: |
Type x() const { return x_; } |
@@ -33,17 +33,25 @@ class UI_EXPORT PointBase { |
y_ += delta_y; |
} |
- Class Add(const Class& other) const WARN_UNUSED_RESULT { |
+ void operator+=(const VectorClass& other) { |
+ Offset(other.x(), other.y()); |
+ } |
+ |
+ void operator-=(const VectorClass& other) { |
+ Offset(-other.x(), -other.y()); |
+ } |
+ |
+ Class Add(const VectorClass& other) const WARN_UNUSED_RESULT { |
const Class* orig = static_cast<const Class*>(this); |
Class copy = *orig; |
- copy.Offset(other.x_, other.y_); |
+ copy.Offset(other.x(), other.y()); |
return copy; |
} |
- Class Subtract(const Class& other) const WARN_UNUSED_RESULT { |
+ Class Subtract(const VectorClass& other) const WARN_UNUSED_RESULT { |
const Class* orig = static_cast<const Class*>(this); |
Class copy = *orig; |
- copy.Offset(-other.x_, -other.y_); |
+ copy.Offset(-other.x(), -other.y()); |
return copy; |
} |
@@ -55,6 +63,14 @@ class UI_EXPORT PointBase { |
return x_ == 0 && y_ == 0; |
} |
+ VectorClass OffsetFromOrigin() const { |
+ return VectorClass(x_, y_); |
+ } |
+ |
+ VectorClass OffsetFrom(const Class& other) const { |
+ return VectorClass(x_ - other.x_, y_ - other.y_); |
+ } |
+ |
// A point is less than another point if its y-value is closer |
// to the origin. If the y-values are the same, then point with |
// the x-value closer to the origin is considered less than the |