mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added a couple of proportional Rectangle methods
This commit is contained in:
parent
d4933111db
commit
97e058bbd2
1 changed files with 47 additions and 18 deletions
|
|
@ -538,6 +538,53 @@ public:
|
|||
return r;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the nearest point to the specified point that lies within this rectangle. */
|
||||
Point<ValueType> getConstrainedPoint (Point<ValueType> point) const noexcept
|
||||
{
|
||||
return Point<ValueType> (jlimit (pos.x, pos.x + w, point.x),
|
||||
jlimit (pos.y, pos.y + h, point.y));
|
||||
}
|
||||
|
||||
/** Returns a point within this rectangle, specified as proportional coordinates.
|
||||
The relative X and Y values should be between 0 and 1, where 0 is the left or
|
||||
top of this rectangle, and 1 is the right or bottom. (Out-of-bounds values
|
||||
will return a point outside the rectangle).
|
||||
*/
|
||||
template <typename FloatType>
|
||||
Point<ValueType> getRelativePoint (FloatType relativeX, FloatType relativeY) const noexcept
|
||||
{
|
||||
return Point<ValueType> (pos.x + static_cast<ValueType> (w * relativeX),
|
||||
pos.y + static_cast<ValueType> (h * relativeY));
|
||||
}
|
||||
|
||||
/** Returns a proportion of the width of this rectangle. */
|
||||
template <typename FloatType>
|
||||
ValueType proportionOfWidth (FloatType proportion) const noexcept
|
||||
{
|
||||
return static_cast<ValueType> (w * proportion);
|
||||
}
|
||||
|
||||
/** Returns a proportion of the height of this rectangle. */
|
||||
template <typename FloatType>
|
||||
ValueType proportionOfHeight (FloatType proportion) const noexcept
|
||||
{
|
||||
return static_cast<ValueType> (h * proportion);
|
||||
}
|
||||
|
||||
/** Returns a rectangle based on some proportional coordinates relative to this one.
|
||||
So for example getProportion ({ 0.25f, 0.25f, 0.5f, 0.5f }) would return a rectangle
|
||||
of half the original size, with the same centre.
|
||||
*/
|
||||
template <typename FloatType>
|
||||
Rectangle getProportion (Rectangle<FloatType> proportionalRect) const noexcept
|
||||
{
|
||||
return Rectangle (pos.x + static_cast<ValueType> (w * proportionalRect.pos.x),
|
||||
pos.y + static_cast<ValueType> (h * proportionalRect.pos.y),
|
||||
proportionOfWidth (proportionalRect.w),
|
||||
proportionOfWidth (proportionalRect.h));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Returns true if the two rectangles are identical. */
|
||||
bool operator== (const Rectangle& other) const noexcept { return pos == other.pos && w == other.w && h == other.h; }
|
||||
|
|
@ -564,24 +611,6 @@ public:
|
|||
&& pos.x + w >= other.pos.x + other.w && pos.y + h >= other.pos.y + other.h;
|
||||
}
|
||||
|
||||
/** Returns the nearest point to the specified point that lies within this rectangle. */
|
||||
Point<ValueType> getConstrainedPoint (Point<ValueType> point) const noexcept
|
||||
{
|
||||
return Point<ValueType> (jlimit (pos.x, pos.x + w, point.x),
|
||||
jlimit (pos.y, pos.y + h, point.y));
|
||||
}
|
||||
|
||||
/** Returns a point within this rectangle, specified as proportional coordinates.
|
||||
The relative X and Y values should be between 0 and 1, where 0 is the left or
|
||||
top of this rectangle, and 1 is the right or bottom. (Out-of-bounds values
|
||||
will return a point outside the rectangle).
|
||||
*/
|
||||
Point<ValueType> getRelativePoint (double relativeX, double relativeY) const noexcept
|
||||
{
|
||||
return Point<ValueType> (pos.x + static_cast<ValueType> (w * relativeX),
|
||||
pos.y + static_cast<ValueType> (h * relativeY));
|
||||
}
|
||||
|
||||
/** Returns true if any part of another rectangle overlaps this one. */
|
||||
bool intersects (const Rectangle& other) const noexcept
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue