diff options
| -rw-r--r-- | src/common/math_util.h | 16 |
1 files changed, 14 insertions, 2 deletions
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 { | |||
| 24 | : left(left), top(top), right(right), bottom(bottom) {} | 24 | : left(left), top(top), right(right), bottom(bottom) {} |
| 25 | 25 | ||
| 26 | T GetWidth() const { | 26 | T GetWidth() const { |
| 27 | return std::abs(static_cast<std::make_signed_t<T>>(right - left)); | 27 | if constexpr (std::is_floating_point_v<T>) { |
| 28 | return std::abs(right - left); | ||
| 29 | } else { | ||
| 30 | return std::abs(static_cast<std::make_signed_t<T>>(right - left)); | ||
| 31 | } | ||
| 28 | } | 32 | } |
| 33 | |||
| 29 | T GetHeight() const { | 34 | T GetHeight() const { |
| 30 | return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); | 35 | if constexpr (std::is_floating_point_v<T>) { |
| 36 | return std::abs(bottom - top); | ||
| 37 | } else { | ||
| 38 | return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); | ||
| 39 | } | ||
| 31 | } | 40 | } |
| 41 | |||
| 32 | Rectangle<T> TranslateX(const T x) const { | 42 | Rectangle<T> TranslateX(const T x) const { |
| 33 | return Rectangle{left + x, top, right + x, bottom}; | 43 | return Rectangle{left + x, top, right + x, bottom}; |
| 34 | } | 44 | } |
| 45 | |||
| 35 | Rectangle<T> TranslateY(const T y) const { | 46 | Rectangle<T> TranslateY(const T y) const { |
| 36 | return Rectangle{left, top + y, right, bottom + y}; | 47 | return Rectangle{left, top + y, right, bottom + y}; |
| 37 | } | 48 | } |
| 49 | |||
| 38 | Rectangle<T> Scale(const float s) const { | 50 | Rectangle<T> Scale(const float s) const { |
| 39 | return Rectangle{left, top, static_cast<T>(left + GetWidth() * s), | 51 | return Rectangle{left, top, static_cast<T>(left + GetWidth() * s), |
| 40 | static_cast<T>(top + GetHeight() * s)}; | 52 | static_cast<T>(top + GetHeight() * s)}; |