summaryrefslogtreecommitdiffstats
path: root/src/model/Position.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/Position.hpp')
-rw-r--r--src/model/Position.hpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/model/Position.hpp b/src/model/Position.hpp
index a88c151..c8fc477 100644
--- a/src/model/Position.hpp
+++ b/src/model/Position.hpp
@@ -28,6 +28,8 @@
#include "Direction.hpp"
+#include <functional>
+
namespace RPGEdit {
@@ -41,19 +43,19 @@ struct Position {
Position p = *this;
switch (dir) {
- case NORTH:
+ case Direction::NORTH:
p.y -= amount;
break;
- case EAST:
+ case Direction::EAST:
p.x += amount;
break;
- case SOUTH:
+ case Direction::SOUTH:
p.y += amount;
break;
- case WEST:
+ case Direction::WEST:
p.x -= amount;
}
@@ -64,6 +66,10 @@ struct Position {
return translate(dir, 1);
}
+ bool operator==(const Position<T> &p) const {
+ return (x == p.x) && (y == p.y);
+ }
+
template<typename T2>
explicit operator Position<T2>() const {
return Position<T2>{T2(x), T2(y)};
@@ -73,3 +79,20 @@ struct Position {
}
}
+
+namespace std {
+template<typename T> struct hash<RPGEdit::Model::Position<T>> {
+ typedef size_t result_type;
+ typedef RPGEdit::Model::Position<T> argument_type;
+
+ size_t operator()(const RPGEdit::Model::Position<T> &pos) const noexcept {
+ const int shift = 4*sizeof(size_t); // half the bit count of size_t
+
+ std::hash<T> hash;
+ size_t hash1 = hash(pos.x), hash2 = hash(pos.y);
+
+ return hash1 ^ ((hash2 << shift) | (hash2 >> shift));
+ }
+};
+
+}