diff options
| author | 2019-12-26 01:42:31 -0300 | |
|---|---|---|
| committer | 2020-02-28 16:22:11 -0300 | |
| commit | e38ed26b9887f4fda723cdc42da7b61c0050d74b (patch) | |
| tree | 725fa5547267cf1e3856a341483b5a6b38a70bd7 /src/common/math_util.h | |
| parent | Merge pull request #3470 from bunnei/fix-smash-srgb (diff) | |
| download | yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.gz yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.xz yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.zip | |
common/math_util: Support float type rectangles
Diffstat (limited to '')
| -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)}; |