From 68afd10851e01872c5c7774a2c1a09039d6e61d7 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 7 Nov 2017 11:01:20 +0100 Subject: Improve path finding. The path finder will avoid paths that would intersect obstacles. --- src/math.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/math.hpp') 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 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 center(void) const + { + return v[0] / 2 + v[1] / 2; + } + friend bool operator&&(const rect_t &a, const rect_t &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 -- cgit