Bug 811950 - Add scaling operators to BaseSize and gfxPoint. r=roc
authorAnthony Jones <ajones@mozilla.com>
Sun, 23 Dec 2012 10:50:30 -0500
changeset 126059 0e5744e4e2f61b25b9a6cf83deee90cd3c32a3b0
parent 126058 955a8b88d7969843d5d8cae39b0728331d98bfbb
child 126060 cb9dc5d37fac2f091ea57d2e1fd2987157395b72
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs811950
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 811950 - Add scaling operators to BaseSize and gfxPoint. r=roc
gfx/2d/BaseSize.h
gfx/thebes/gfxPoint.h
--- a/gfx/2d/BaseSize.h
+++ b/gfx/2d/BaseSize.h
@@ -58,14 +58,21 @@ struct BaseSize {
   }
 
   Sub operator*(T aScale) const {
     return Sub(width * aScale, height * aScale);
   }
   Sub operator/(T aScale) const {
     return Sub(width / aScale, height / aScale);
   }
+
+  Sub operator*(const Sub& aSize) const {
+    return Sub(width * aSize.width, height * aSize.height);
+  }
+  Sub operator/(const Sub& aSize) const {
+    return Sub(width / aSize.width, height / aSize.height);
+  }
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_BASESIZE_H_ */
--- a/gfx/thebes/gfxPoint.h
+++ b/gfx/thebes/gfxPoint.h
@@ -29,22 +29,42 @@ struct THEBES_API gfxPoint : public mozi
 
     gfxPoint() : Super() {}
     gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
     gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
 
     // Round() is *not* rounding to nearest integer if the values are negative.
     // They are always rounding as floor(n + 0.5).
     // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14
-    // And if you need similar method which is using NS_round(), you should
-    // create new |RoundAwayFromZero()| method.
     gfxPoint& Round() {
         x = floor(x + 0.5);
         y = floor(y + 0.5);
         return *this;
     }
 
+    nsIntPoint RoundedAwayFromZero() const {
+        return nsIntPoint(NS_lround(x), NS_lround(y));
+    }
+
     bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
         return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
     }
 };
 
+inline gfxPoint
+operator*(const gfxPoint& aPoint, const gfxSize& aSize)
+{
+  return gfxPoint(aPoint.x * aSize.width, aPoint.y * aSize.height);
+}
+
+inline gfxPoint
+operator/(const gfxPoint& aPoint, const gfxSize& aSize)
+{
+  return gfxPoint(aPoint.x / aSize.width, aPoint.y / aSize.height);
+}
+
+inline gfxSize
+operator/(gfxFloat aValue, const gfxSize& aSize)
+{
+  return gfxSize(aValue / aSize.width, aValue / aSize.height);
+}
+
 #endif /* GFX_POINT_H */