diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-12-26 05:42:31 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-02-28 20:22:11 +0100 |
commit | e38ed26b9887f4fda723cdc42da7b61c0050d74b (patch) | |
tree | 725fa5547267cf1e3856a341483b5a6b38a70bd7 | |
parent | Merge pull request #3470 from bunnei/fix-smash-srgb (diff) | |
download | yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.gz yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.bz2 yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.lz yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.xz yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.tar.zst yuzu-e38ed26b9887f4fda723cdc42da7b61c0050d74b.zip |
-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 { : left(left), top(top), right(right), bottom(bottom) {} T GetWidth() const { - return std::abs(static_cast<std::make_signed_t<T>>(right - left)); + if constexpr (std::is_floating_point_v<T>) { + return std::abs(right - left); + } else { + return std::abs(static_cast<std::make_signed_t<T>>(right - left)); + } } + T GetHeight() const { - return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); + if constexpr (std::is_floating_point_v<T>) { + return std::abs(bottom - top); + } else { + return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); + } } + Rectangle<T> TranslateX(const T x) const { return Rectangle{left + x, top, right + x, bottom}; } + Rectangle<T> TranslateY(const T y) const { return Rectangle{left, top + y, right, bottom + y}; } + Rectangle<T> Scale(const float s) const { return Rectangle{left, top, static_cast<T>(left + GetWidth() * s), static_cast<T>(top + GetHeight() * s)}; |