diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-11-07 11:01:20 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-11-07 11:01:20 +0100 |
commit | 68afd10851e01872c5c7774a2c1a09039d6e61d7 (patch) | |
tree | 382043bc62bad9751a3ef7778e799d78b4362bc3 /src/math.hpp | |
parent | 6ab51bfb002af08da74a693f386c4154d2c4108a (diff) |
Improve path finding.
The path finder will avoid paths that would intersect obstacles.
Diffstat (limited to 'src/math.hpp')
-rw-r--r-- | src/math.hpp | 22 |
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 |