added a custom class for bidirectional lookups

This commit is contained in:
Yggdrasil75
2025-11-13 13:09:52 -05:00
parent 9eb37f01b7
commit e32b7d9867
2 changed files with 170 additions and 56 deletions

View File

@@ -8,8 +8,10 @@
class Vec2 {
public:
float x, y;
size_t index;
Vec2() : x(0), y(0) {}
Vec2(float x, float y) : x(x), y(y) {}
Vec2(float x, float y, size_t index) : x(x), y(y), index(index) {}
Vec2& move(const Vec2 newpos) {
x = newpos.x;
@@ -277,12 +279,23 @@ class Vec2 {
std::string toString() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}
std::ostream& operator<<(std::ostream& os) {
os << toString();
return os;
}
struct Hash {
std::size_t operator()(const Vec2& v) const {
return std::hash<float>()(v.x) ^ (std::hash<float>()(v.y) << 1);
}
};
};
inline std::ostream& operator<<(std::ostream& os, const Vec2& vec) {
os << vec.toString();
return os;
}
// inline std::ostream& operator<<(std::ostream& os, const Vec2& vec) {
// os << vec.toString();
// return os;
// }
namespace std {
template<>