From 26759d5f64ae788f66ed03689000ecae731cb0db Mon Sep 17 00:00:00 2001 From: Timur Doumler Date: Tue, 2 Feb 2016 14:38:28 +0000 Subject: [PATCH] Added helper method Rectangle::toNearestInt(). --- modules/juce_graphics/geometry/juce_Rectangle.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 */