diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index b3b74d06c9..cb1ef4b7e5 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -774,7 +774,7 @@ public: /** Returns the smallest integer-aligned rectangle that completely contains this one. This is only relevent for floating-point rectangles, of course. - @see toFloat() + @see toFloat(), toNearestInt() */ Rectangle getSmallestIntegerContainer() const noexcept { @@ -786,6 +786,17 @@ public: return Rectangle (x1, y1, x2 - x1, y2 - y1); } + /** Casts this rectangle to a Rectangle. + This uses roundToInt for rounding the bounds (if this rectangle uses floating point) + or just returns a copy (if this rectangle uses integers as well). + @see getSmallestIntegerContainer() + */ + Rectangle toNearestInt() const noexcept + { + return Rectangle (roundToInt (pos.x), roundToInt (pos.y), + roundToInt (w), roundToInt (h)); + } + /** Casts this rectangle to a Rectangle. @see getSmallestIntegerContainer */