diff options
Diffstat (limited to 'src/math.hpp')
-rw-r--r-- | src/math.hpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/math.hpp b/src/math.hpp index 55bf438..938241f 100644 --- a/src/math.hpp +++ b/src/math.hpp @@ -188,6 +188,16 @@ public: return r; } + vec_t<T, N> ceil(void) + { + vec_t<T, N> r; + + for (size_t i = 0; i < N; i++) + r[i] = std::ceil(v[i]); + + return r; + } + T len(void) { return std::sqrt(*this * *this); @@ -255,21 +265,33 @@ public: return v[i]; } - bool intersects(const rect_t<T, N> &b) const + T dim(size_t i) const { - for (size_t i = 0; i < N; i++) - if (v[1][i] < b[0][i] || v[0][i] > b[1][i]) - return false; + return v[1][i] - v[0][i]; + } - return true; + rect_t<T, N> norm(void) const + { + rect_t<T, N> r; + + for (size_t i = 0; i < N; i++) { + r[0][i] = std::min(v[0][i], v[1][i]); + r[1][i] = std::max(v[0][i], v[1][i]); + } + + return r; } - T dim(size_t i) const + friend bool operator&&(const rect_t<T, N> &a, const rect_t<T, N> &b) { - return v[1][i] - v[0][i]; + for (size_t i = 0; i < N; i++) + if (a[1][i] < b[0][i] || a[0][i] > b[1][i]) + return false; + + return true; } - friend rect_t<T, N> operator+(const rect_t<T, N> &a, const rect_t<T, N> &b) + friend rect_t<T, N> operator|(const rect_t<T, N> &a, const rect_t<T, N> &b) { rect_t r; |