From e38ed26b9887f4fda723cdc42da7b61c0050d74b Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 26 Dec 2019 01:42:31 -0300 Subject: common/math_util: Support float type rectangles --- src/common/math_util.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/common/math_util.h') diff --git a/src/common/math_util.h b/src/common/math_util.h index d6c35ee89..83ef0201f 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -24,17 +24,29 @@ struct Rectangle { : left(left), top(top), right(right), bottom(bottom) {} T GetWidth() const { - return std::abs(static_cast>(right - left)); + if constexpr (std::is_floating_point_v) { + return std::abs(right - left); + } else { + return std::abs(static_cast>(right - left)); + } } + T GetHeight() const { - return std::abs(static_cast>(bottom - top)); + if constexpr (std::is_floating_point_v) { + return std::abs(bottom - top); + } else { + return std::abs(static_cast>(bottom - top)); + } } + Rectangle TranslateX(const T x) const { return Rectangle{left + x, top, right + x, bottom}; } + Rectangle TranslateY(const T y) const { return Rectangle{left, top + y, right, bottom + y}; } + Rectangle Scale(const float s) const { return Rectangle{left, top, static_cast(left + GetWidth() * s), static_cast(top + GetHeight() * s)}; -- cgit v1.2.3