Browse Source

Added some more translation methods to AffineTransform, and a couple of methods to Rectangle and RectangleList

tags/2021-05-28
jules 11 years ago
parent
commit
bd3a75e726
3 changed files with 32 additions and 7 deletions
  1. +14
    -0
      modules/juce_graphics/geometry/juce_AffineTransform.h
  2. +12
    -2
      modules/juce_graphics/geometry/juce_Rectangle.h
  3. +6
    -5
      modules/juce_graphics/geometry/juce_RectangleList.h

+ 14
- 0
modules/juce_graphics/geometry/juce_AffineTransform.h View File

@@ -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 <typename PointType>
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 <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. */
AffineTransform withAbsoluteTranslation (float translationX,
float translationY) const noexcept;


+ 12
- 2
modules/juce_graphics/geometry/juce_Rectangle.h View File

@@ -711,7 +711,6 @@ public:
}
/** Casts this rectangle to a Rectangle<float>.
Obviously this is mainly useful for rectangles that use integer types.
@see getSmallestIntegerContainer
*/
Rectangle<float> toFloat() const noexcept
@@ -721,7 +720,6 @@ public:
}
/** Casts this rectangle to a Rectangle<double>.
Obviously this is mainly useful for rectangles that use integer types.
@see getSmallestIntegerContainer
*/
Rectangle<double> toDouble() const noexcept
@@ -730,6 +728,18 @@ public:
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. */
static Rectangle findAreaContainingPoints (const Point<ValueType>* const points, const int numPoints) noexcept
{


+ 6
- 5
modules/juce_graphics/geometry/juce_RectangleList.h View File

@@ -343,7 +343,8 @@ public:
@see getIntersectionWith
*/
bool clipTo (const RectangleList& other)
template <typename OtherValueType>
bool clipTo (const RectangleList<OtherValueType>& 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<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);
}
}


Loading…
Cancel
Save