Skip to content

Commit 9d4cddd

Browse files
committed
More fixes
1 parent f2159ee commit 9d4cddd

File tree

2 files changed

+371
-21
lines changed

2 files changed

+371
-21
lines changed

modules/yup_graphics/primitives/yup_Rectangle.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class YUP_API Rectangle
252252
*/
253253
[[nodiscard]] constexpr Rectangle withTrimmedLeft (ValueType amountToTrim) const noexcept
254254
{
255-
return withLeft (xy.getX() + amountToTrim);
255+
return { xy.withX (xy.getX() + amountToTrim), size.withWidth (jmax (static_cast<ValueType> (0), size.getWidth() - amountToTrim)) };
256256
}
257257

258258
//==============================================================================
@@ -300,7 +300,7 @@ class YUP_API Rectangle
300300
*/
301301
[[nodiscard]] constexpr Rectangle withTrimmedTop (ValueType amountToTrim) const noexcept
302302
{
303-
return withTop (xy.getY() + amountToTrim);
303+
return { xy.withY (xy.getY() + amountToTrim), size.withHeight (jmax (static_cast<ValueType> (0), size.getHeight() - amountToTrim)) };
304304
}
305305

306306
//==============================================================================
@@ -1696,8 +1696,14 @@ class YUP_API Rectangle
16961696
[[nodiscard]] constexpr auto aspectRatio() const noexcept
16971697
-> std::enable_if_t<std::is_integral_v<T>, std::tuple<int, int>>
16981698
{
1699-
auto factor = std::gcd (size.getWidth(), size.getHeight());
1700-
return std::make_tuple (size.getWidth() / factor, size.getHeight() / factor);
1699+
const T w = size.getWidth();
1700+
const T h = size.getHeight();
1701+
1702+
if (w == 0 || h == 0)
1703+
return { 0, 0 };
1704+
1705+
const T factor = std::gcd (w, h);
1706+
return { w / factor, h / factor };
17011707
}
17021708

17031709
/** Returns the ratio of the width to the height of the rectangle.

0 commit comments

Comments
 (0)