diff options
Diffstat (limited to 'src/common/math_util.h')
| -rw-r--r-- | src/common/math_util.h | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/common/math_util.h b/src/common/math_util.h index d44b06e74..41d89666c 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -8,22 +8,20 @@ | |||
| 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; |
| @@ -31,10 +29,15 @@ struct Rectangle | |||
| 31 | 29 | ||
| 32 | Rectangle() {} | 30 | Rectangle() {} |
| 33 | 31 | ||
| 34 | Rectangle(T left, T top, T right, T bottom) : left(left), top(top), right(right), bottom(bottom) {} | 32 | Rectangle(T left, T top, T right, T bottom) |
| 33 | : left(left), top(top), right(right), bottom(bottom) {} | ||
| 35 | 34 | ||
| 36 | T GetWidth() const { return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); } | 35 | T GetWidth() const { |
| 37 | T GetHeight() const { return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); } | 36 | return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); |
| 37 | } | ||
| 38 | T GetHeight() const { | ||
| 39 | return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); | ||
| 40 | } | ||
| 38 | }; | 41 | }; |
| 39 | 42 | ||
| 40 | } // namespace MathUtil | 43 | } // namespace MathUtil |