diff --git a/modules/juce_graphics/geometry/juce_Point.h b/modules/juce_graphics/geometry/juce_Point.h index 829f5cea50..3df567b7d8 100644 --- a/modules/juce_graphics/geometry/juce_Point.h +++ b/modules/juce_graphics/geometry/juce_Point.h @@ -99,30 +99,34 @@ public: Point& operator-= (Point other) noexcept { x -= other.x; y -= other.y; return *this; } /** Multiplies two points together */ - Point operator* (Point other) const noexcept { return Point (x * other.x, y * other.y); } + template + Point operator* (Point other) const noexcept { return Point ((ValueType) (x * other.x), (ValueType) (y * other.y)); } /** Multiplies another point's coordinates to this one */ - Point& operator*= (Point other) noexcept { x *= other.x; y *= other.y; return *this; } + template + Point& operator*= (Point other) noexcept { *this = *this * other; return *this; } - /** Divides one points from another */ - Point operator/ (Point other) const noexcept { return Point (x / other.x, y / other.y); } + /** Divides one point by another */ + template + Point operator/ (Point other) const noexcept { return Point ((ValueType) (x / other.x), (ValueType) (y / other.y)); } - /** Divides another point's coordinates to this one */ - Point& operator/= (Point other) noexcept { x /= other.x; y /= other.y; return *this; } + /** Divides this point's coordinates by another */ + template + Point& operator/= (Point other) noexcept { *this = *this / other; return *this; } - /** Returns a point whose coordinates are multiplied by a given value. */ + /** Returns a point whose coordinates are multiplied by a given scalar value. */ template Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) (x * multiplier), (ValueType) (y * multiplier)); } - /** Returns a point whose coordinates are divided by a given value. */ + /** Returns a point whose coordinates are divided by a given scalar value. */ template Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) (x / divisor), (ValueType) (y / divisor)); } - /** Multiplies the point's coordinates by a value. */ + /** Multiplies the point's coordinates by a scalar value. */ template Point& operator*= (FloatType multiplier) noexcept { x = (ValueType) (x * multiplier); y = (ValueType) (y * multiplier); return *this; } - /** Divides the point's coordinates by a value. */ + /** Divides the point's coordinates by a scalar value. */ template Point& operator/= (FloatType divisor) noexcept { x = (ValueType) (x / divisor); y = (ValueType) (y / divisor); return *this; } diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index 7604fa83a0..44f4e06ebf 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -316,6 +316,21 @@ public: return *this; } + /** Scales this rectangle by the given X and Y factors, centred around the origin. + Note that if the rectangle has int coordinates and it's scaled by a + floating-point amount, then the result will be converted back to integer + coordinates using getSmallestIntegerContainer(). + */ + template + Rectangle operator*= (Point scaleFactor) noexcept + { + Rectangle (pos.x * scaleFactor.x, + pos.y * scaleFactor.y, + w * scaleFactor.x, + h * scaleFactor.y).copyWithRounding (*this); + return *this; + } + /** Scales this rectangle by the given amount, centred around the origin. */ template Rectangle operator/ (FloatType scaleFactor) const noexcept @@ -336,6 +351,17 @@ public: return *this; } + /** Scales this rectangle by the given X and Y factors, centred around the origin. */ + template + Rectangle operator/= (Point scaleFactor) noexcept + { + Rectangle (pos.x / scaleFactor.x, + pos.y / scaleFactor.y, + w / scaleFactor.x, + h / scaleFactor.y).copyWithRounding (*this); + return *this; + } + /** Expands the rectangle by a given amount. Effectively, its new size is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2).