@@ -127,10 +127,24 @@ public: | |||||
AffineTransform translated (float deltaX, | AffineTransform translated (float deltaX, | ||||
float deltaY) const noexcept; | float deltaY) const noexcept; | ||||
/** Returns a new transform which is the same as this one followed by a translation. */ | |||||
template <typename PointType> | |||||
AffineTransform translated (PointType delta) const noexcept | |||||
{ | |||||
return translated ((float) delta.x, (float) delta.y); | |||||
} | |||||
/** Returns a new transform which is a translation. */ | /** Returns a new transform which is a translation. */ | ||||
static AffineTransform translation (float deltaX, | static AffineTransform translation (float deltaX, | ||||
float deltaY) noexcept; | float deltaY) noexcept; | ||||
/** Returns a new transform which is a translation. */ | |||||
template <typename PointType> | |||||
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. */ | /** Returns a copy of this transform with the specified translation matrix values. */ | ||||
AffineTransform withAbsoluteTranslation (float translationX, | AffineTransform withAbsoluteTranslation (float translationX, | ||||
float translationY) const noexcept; | float translationY) const noexcept; | ||||
@@ -711,7 +711,6 @@ public: | |||||
} | } | ||||
/** Casts this rectangle to a Rectangle<float>. | /** Casts this rectangle to a Rectangle<float>. | ||||
Obviously this is mainly useful for rectangles that use integer types. | |||||
@see getSmallestIntegerContainer | @see getSmallestIntegerContainer | ||||
*/ | */ | ||||
Rectangle<float> toFloat() const noexcept | Rectangle<float> toFloat() const noexcept | ||||
@@ -721,7 +720,6 @@ public: | |||||
} | } | ||||
/** Casts this rectangle to a Rectangle<double>. | /** Casts this rectangle to a Rectangle<double>. | ||||
Obviously this is mainly useful for rectangles that use integer types. | |||||
@see getSmallestIntegerContainer | @see getSmallestIntegerContainer | ||||
*/ | */ | ||||
Rectangle<double> toDouble() const noexcept | Rectangle<double> toDouble() const noexcept | ||||
@@ -730,6 +728,18 @@ public: | |||||
static_cast<double> (w), static_cast<double> (h)); | static_cast<double> (w), static_cast<double> (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 <typename TargetType> | |||||
Rectangle<TargetType> toType() const noexcept | |||||
{ | |||||
Rectangle<TargetType> r; | |||||
copyWithRounding (r); | |||||
return r; | |||||
} | |||||
/** Returns the smallest Rectangle that can contain a set of points. */ | /** Returns the smallest Rectangle that can contain a set of points. */ | ||||
static Rectangle findAreaContainingPoints (const Point<ValueType>* const points, const int numPoints) noexcept | static Rectangle findAreaContainingPoints (const Point<ValueType>* const points, const int numPoints) noexcept | ||||
{ | { | ||||
@@ -343,7 +343,8 @@ public: | |||||
@see getIntersectionWith | @see getIntersectionWith | ||||
*/ | */ | ||||
bool clipTo (const RectangleList& other) | |||||
template <typename OtherValueType> | |||||
bool clipTo (const RectangleList<OtherValueType>& other) | |||||
{ | { | ||||
if (rects.size() == 0) | if (rects.size() == 0) | ||||
return false; | return false; | ||||
@@ -354,12 +355,12 @@ public: | |||||
{ | { | ||||
const RectangleType& rect = rects.getReference (j); | const RectangleType& rect = rects.getReference (j); | ||||
for (int i = other.rects.size(); --i >= 0;) | |||||
for (const Rectangle<OtherValueType>* r = other.begin(), * const e = other.end(); r != e; ++r) | |||||
{ | { | ||||
RectangleType r (other.rects.getReference (i)); | |||||
RectangleType clipped (r->template toType<ValueType>()); | |||||
if (rect.intersectRectangle (r)) | |||||
result.rects.add (r); | |||||
if (rect.intersectRectangle (clipped)) | |||||
result.rects.add (clipped); | |||||
} | } | ||||
} | } | ||||