diff options
Diffstat (limited to 'src/common/math_util.h')
| -rw-r--r-- | src/common/math_util.h | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/common/math_util.h b/src/common/math_util.h index d44b06e74..696bd43ea 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -8,33 +8,38 @@ | |||
| 8 | #include <cstdlib> | 8 | #include <cstdlib> |
| 9 | #include <type_traits> | 9 | #include <type_traits> |
| 10 | 10 | ||
| 11 | namespace MathUtil | 11 | namespace MathUtil { |
| 12 | { | ||
| 13 | 12 | ||
| 14 | inline bool IntervalsIntersect(unsigned start0, unsigned length0, unsigned start1, unsigned length1) { | 13 | inline bool IntervalsIntersect(unsigned start0, unsigned length0, unsigned start1, |
| 14 | unsigned length1) { | ||
| 15 | return (std::max(start0, start1) < std::min(start0 + length0, start1 + length1)); | 15 | return (std::max(start0, start1) < std::min(start0 + length0, start1 + length1)); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | template<typename T> | 18 | template <typename T> |
| 19 | inline T Clamp(const T val, const T& min, const T& max) | 19 | inline T Clamp(const T val, const T& min, const T& max) { |
| 20 | { | ||
| 21 | return std::max(min, std::min(max, val)); | 20 | return std::max(min, std::min(max, val)); |
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | template<class T> | 23 | template <class T> |
| 25 | struct Rectangle | 24 | struct Rectangle { |
| 26 | { | ||
| 27 | T left; | 25 | T left; |
| 28 | T top; | 26 | T top; |
| 29 | T right; | 27 | T right; |
| 30 | T bottom; | 28 | T bottom; |
| 31 | 29 | ||
| 32 | Rectangle() {} | 30 | Rectangle() { |
| 31 | } | ||
| 33 | 32 | ||
| 34 | Rectangle(T left, T top, T right, T bottom) : left(left), top(top), right(right), bottom(bottom) {} | 33 | Rectangle(T left, T top, T right, T bottom) |
| 34 | : left(left), top(top), right(right), bottom(bottom) { | ||
| 35 | } | ||
| 35 | 36 | ||
| 36 | T GetWidth() const { return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); } | 37 | T GetWidth() const { |
| 37 | T GetHeight() const { return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); } | 38 | return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); |
| 39 | } | ||
| 40 | T GetHeight() const { | ||
| 41 | return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); | ||
| 42 | } | ||
| 38 | }; | 43 | }; |
| 39 | 44 | ||
| 40 | } // namespace MathUtil | 45 | } // namespace MathUtil |