Bug 1185636 - Part 2 - Add some utility methods to Point and Size. r=jmuizelaar
authorLee Salzman <lsalzman@mozilla.com>
Mon, 20 Jul 2015 14:53:24 -0400
changeset 282562 dfe577ec4e569e36f4f79d9c9c731ab9d717c093
parent 282561 ee7df762c1950867b6ff57be5dac80266c33882f
child 282563 09b212388126c4b24042f8a10502ff505f4558d2
push id4013
push userjbruaroey@mozilla.com
push dateMon, 03 Aug 2015 21:15:08 +0000
reviewersjmuizelaar
bugs1185636
milestone42.0a1
Bug 1185636 - Part 2 - Add some utility methods to Point and Size. r=jmuizelaar
gfx/2d/BasePoint.h
gfx/2d/BaseSize.h
--- a/gfx/2d/BasePoint.h
+++ b/gfx/2d/BasePoint.h
@@ -64,16 +64,20 @@ struct BasePoint {
   Sub operator/(T aScale) const {
     return Sub(x / aScale, y / aScale);
   }
 
   Sub operator-() const {
     return Sub(-x, -y);
   }
 
+  T DotProduct(const Sub& aPoint) const {
+      return x * aPoint.x + y * aPoint.y;
+  }
+
   T Length() const {
     return hypot(x, 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
   Sub& Round() {
--- a/gfx/2d/BaseSize.h
+++ b/gfx/2d/BaseSize.h
@@ -25,16 +25,20 @@ struct BaseSize {
   MOZ_CONSTEXPR BaseSize(T aWidth, T aHeight) : width(aWidth), height(aHeight) {}
 
   void SizeTo(T aWidth, T aHeight) { width = aWidth; height = aHeight; }
 
   bool IsEmpty() const {
     return width == 0 || height == 0;
   }
 
+  bool IsSquare() const {
+    return width == height;
+  }
+
   // Note that '=' isn't defined so we'll get the
   // compiler generated default assignment operator
 
   bool operator==(const Sub& aSize) const {
     return width == aSize.width && height == aSize.height;
   }
   bool operator!=(const Sub& aSize) const {
     return width != aSize.width || height != aSize.height;