summaryrefslogtreecommitdiff
path: root/src/math.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/math.hpp')
-rw-r--r--src/math.hpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/math.hpp b/src/math.hpp
index 938241f..8c93a76 100644
--- a/src/math.hpp
+++ b/src/math.hpp
@@ -265,6 +265,11 @@ public:
return v[i];
}
+ vec_t<T, N> dims(void) const
+ {
+ return v[1] - v[0];
+ }
+
T dim(size_t i) const
{
return v[1][i] - v[0][i];
@@ -282,6 +287,11 @@ public:
return r;
}
+ vec_t<T, N> center(void) const
+ {
+ return v[0] / 2 + v[1] / 2;
+ }
+
friend bool operator&&(const rect_t<T, N> &a, const rect_t<T, N> &b)
{
for (size_t i = 0; i < N; i++)
@@ -308,6 +318,18 @@ public:
stream << "(" << r[0] << " x " << r[1] << ")";
return stream;
}
+
+ // Compatibility with SFML
+
+ rect_t(sf::FloatRect b)
+ {
+ static_assert(N == 2, "conversion of sf::FloatRect to rect_t with N != 2");
+
+ v[0][0] = b.left;
+ v[0][1] = b.top;
+ v[1][0] = b.left + b.width;
+ v[1][1] = b.top + b.height;
+ }
};
// Shorthands