diff options
Diffstat (limited to 'src/common/math_util.h')
| -rw-r--r-- | src/common/math_util.h | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/common/math_util.h b/src/common/math_util.h index 343cdd902..94b4394c5 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -4,18 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 8 | #include <cstdlib> | 7 | #include <cstdlib> |
| 9 | #include <type_traits> | 8 | #include <type_traits> |
| 10 | 9 | ||
| 11 | namespace MathUtil { | 10 | namespace MathUtil { |
| 12 | 11 | ||
| 13 | static constexpr float PI = 3.14159265f; | 12 | constexpr float PI = 3.14159265f; |
| 14 | |||
| 15 | inline bool IntervalsIntersect(unsigned start0, unsigned length0, unsigned start1, | ||
| 16 | unsigned length1) { | ||
| 17 | return (std::max(start0, start1) < std::min(start0 + length0, start1 + length1)); | ||
| 18 | } | ||
| 19 | 13 | ||
| 20 | template <class T> | 14 | template <class T> |
| 21 | struct Rectangle { | 15 | struct Rectangle { |
| @@ -24,16 +18,16 @@ struct Rectangle { | |||
| 24 | T right{}; | 18 | T right{}; |
| 25 | T bottom{}; | 19 | T bottom{}; |
| 26 | 20 | ||
| 27 | Rectangle() = default; | 21 | constexpr Rectangle() = default; |
| 28 | 22 | ||
| 29 | Rectangle(T left, T top, T right, T bottom) | 23 | constexpr Rectangle(T left, T top, T right, T bottom) |
| 30 | : left(left), top(top), right(right), bottom(bottom) {} | 24 | : left(left), top(top), right(right), bottom(bottom) {} |
| 31 | 25 | ||
| 32 | T GetWidth() const { | 26 | T GetWidth() const { |
| 33 | return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); | 27 | return std::abs(static_cast<std::make_signed_t<T>>(right - left)); |
| 34 | } | 28 | } |
| 35 | T GetHeight() const { | 29 | T GetHeight() const { |
| 36 | return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); | 30 | return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); |
| 37 | } | 31 | } |
| 38 | Rectangle<T> TranslateX(const T x) const { | 32 | Rectangle<T> TranslateX(const T x) const { |
| 39 | return Rectangle{left + x, top, right + x, bottom}; | 33 | return Rectangle{left + x, top, right + x, bottom}; |