Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(847)

Unified Diff: ui/gfx/point_base.h

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RenderText fixup Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698