Bug 1185636 - Part 2 - Add some utility methods to Point and Size. r=jmuizelaar
--- 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;