summaryrefslogtreecommitdiff
path: root/src/math.hpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-21 11:20:34 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-21 13:12:42 +0200
commit20b189455545db5688ed4f14d2966380137ee2db (patch)
tree7504e059147cfae54fa466b8a4c0073ecbbc582c /src/math.hpp
parent29d124b93125d7c9de762c45876f69df3acd549d (diff)
Start working on path finding.
Diffstat (limited to 'src/math.hpp')
-rw-r--r--src/math.hpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/math.hpp b/src/math.hpp
index c07b7d0..f3b049b 100644
--- a/src/math.hpp
+++ b/src/math.hpp
@@ -178,6 +178,21 @@ public:
return v;
}
+ vec_t<T, N> floor(void)
+ {
+ vec_t<T, N> r;
+
+ for (size_t i = 0; i < N; i++)
+ r[i] = std::floor(v[i]);
+
+ return r;
+ }
+
+ T len(void)
+ {
+ return std::sqrt(*this * *this);
+ }
+
// Compatibility with SFML
template <typename U>
@@ -243,6 +258,11 @@ public:
return true;
}
+ T dim(size_t i) const
+ {
+ return v[1][i] - v[0][i];
+ }
+
friend rect_t<T, N> operator+(const rect_t<T, N> &a, const rect_t<T, N> &b)
{
rect_t r;
@@ -257,7 +277,7 @@ public:
friend std::ostream& operator<<(std::ostream& stream, rect_t<T, N> r)
{
- stream << "(" << r[0] << ", " << r[1] << ")";
+ stream << "(" << r[0] << " x " << r[1] << ")";
return stream;
}
};