1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added some Rectangle and Point scaling methods.

This commit is contained in:
jules 2013-09-17 09:38:32 +01:00
parent 9a193b55f2
commit 9b4566a2f0
2 changed files with 40 additions and 10 deletions

View file

@ -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 <typename OtherType>
Point operator* (Point<OtherType> 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 <typename OtherType>
Point& operator*= (Point<OtherType> 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 <typename OtherType>
Point operator/ (Point<OtherType> 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 <typename OtherType>
Point& operator/= (Point<OtherType> 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 <typename FloatType>
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 <typename FloatType>
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 <typename FloatType>
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 <typename FloatType>
Point& operator/= (FloatType divisor) noexcept { x = (ValueType) (x / divisor); y = (ValueType) (y / divisor); return *this; }

View file

@ -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 <typename FloatType>
Rectangle operator*= (Point<FloatType> scaleFactor) noexcept
{
Rectangle<FloatType> (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 <typename FloatType>
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 <typename FloatType>
Rectangle operator/= (Point<FloatType> scaleFactor) noexcept
{
Rectangle<FloatType> (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).