diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.h b/modules/juce_graphics/geometry/juce_AffineTransform.h index 70937aeb81..dfc3a29c17 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.h +++ b/modules/juce_graphics/geometry/juce_AffineTransform.h @@ -127,10 +127,24 @@ public: AffineTransform translated (float deltaX, float deltaY) const noexcept; + /** Returns a new transform which is the same as this one followed by a translation. */ + template + AffineTransform translated (PointType delta) const noexcept + { + return translated ((float) delta.x, (float) delta.y); + } + /** Returns a new transform which is a translation. */ static AffineTransform translation (float deltaX, float deltaY) noexcept; + /** Returns a new transform which is a translation. */ + template + static AffineTransform translation (PointType delta) noexcept + { + return translation ((float) delta.x, (float) delta.y); + } + /** Returns a copy of this transform with the specified translation matrix values. */ AffineTransform withAbsoluteTranslation (float translationX, float translationY) const noexcept; diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index 04adce4e17..640a50cdfd 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -711,7 +711,6 @@ public: } /** Casts this rectangle to a Rectangle. - Obviously this is mainly useful for rectangles that use integer types. @see getSmallestIntegerContainer */ Rectangle toFloat() const noexcept @@ -721,7 +720,6 @@ public: } /** Casts this rectangle to a Rectangle. - Obviously this is mainly useful for rectangles that use integer types. @see getSmallestIntegerContainer */ Rectangle toDouble() const noexcept @@ -730,6 +728,18 @@ public: static_cast (w), static_cast (h)); } + /** Casts this rectangle to a Rectangle with the given type. + If the target type is a conversion from float to int, then the conversion + will be done using getSmallestIntegerContainer(). + */ + template + Rectangle toType() const noexcept + { + Rectangle r; + copyWithRounding (r); + return r; + } + /** Returns the smallest Rectangle that can contain a set of points. */ static Rectangle findAreaContainingPoints (const Point* const points, const int numPoints) noexcept { diff --git a/modules/juce_graphics/geometry/juce_RectangleList.h b/modules/juce_graphics/geometry/juce_RectangleList.h index 9bcb2056ee..92c183cf64 100644 --- a/modules/juce_graphics/geometry/juce_RectangleList.h +++ b/modules/juce_graphics/geometry/juce_RectangleList.h @@ -343,7 +343,8 @@ public: @see getIntersectionWith */ - bool clipTo (const RectangleList& other) + template + bool clipTo (const RectangleList& other) { if (rects.size() == 0) return false; @@ -354,12 +355,12 @@ public: { const RectangleType& rect = rects.getReference (j); - for (int i = other.rects.size(); --i >= 0;) + for (const Rectangle* r = other.begin(), * const e = other.end(); r != e; ++r) { - RectangleType r (other.rects.getReference (i)); + RectangleType clipped (r->template toType()); - if (rect.intersectRectangle (r)) - result.rects.add (r); + if (rect.intersectRectangle (clipped)) + result.rects.add (clipped); } }