2018-01-27 14:59:17 +01:00
|
|
|
/**
|
|
|
|
* Defines a few widely used, widely spread structures. Imported pervasively.
|
|
|
|
**/
|
|
|
|
|
2018-02-06 19:07:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-01-27 16:28:36 +01:00
|
|
|
#include <functional> // Hash
|
2018-01-27 18:33:50 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
2018-01-27 16:28:36 +01:00
|
|
|
|
2018-01-27 14:59:17 +01:00
|
|
|
struct Point {
|
2018-01-27 16:28:36 +01:00
|
|
|
Point(double x, double y, double z) : x(x), y(y), z(z) {}
|
2018-01-27 14:59:17 +01:00
|
|
|
double x, y, z;
|
2018-01-27 18:33:50 +01:00
|
|
|
|
|
|
|
double operator[](unsigned i) const {
|
2018-02-06 19:09:02 +01:00
|
|
|
assert(i < 3);
|
2018-01-27 18:33:50 +01:00
|
|
|
switch(i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
2018-01-27 14:59:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Face {
|
2018-01-27 16:28:36 +01:00
|
|
|
Face(int v0, int v1, int v2) {
|
|
|
|
vert[0] = v0;
|
|
|
|
vert[1] = v1;
|
|
|
|
vert[2] = v2;
|
|
|
|
}
|
2018-01-27 14:59:17 +01:00
|
|
|
int vert[3];
|
2018-01-27 16:28:36 +01:00
|
|
|
int operator[](unsigned i) const {
|
2018-01-27 14:59:17 +01:00
|
|
|
return vert[i % 3]; // dodge errors
|
|
|
|
}
|
2018-01-27 18:33:50 +01:00
|
|
|
const Point& pt(int id, const std::vector<Point>& pts) const {
|
|
|
|
assert(0 <= id && id < 3);
|
|
|
|
return pts[vert[id]];
|
|
|
|
}
|
2018-01-27 14:59:17 +01:00
|
|
|
};
|
2018-01-27 16:28:36 +01:00
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template<> struct hash<Face>
|
|
|
|
{
|
|
|
|
typedef Face argument_type;
|
|
|
|
typedef std::size_t result_type;
|
|
|
|
result_type operator()(argument_type const& s) const noexcept
|
|
|
|
{
|
|
|
|
result_type const h1 ( std::hash<int>{}(s[0]) );
|
|
|
|
result_type const h2 ( std::hash<int>{}(s[1]) );
|
|
|
|
result_type const h3 ( std::hash<int>{}(s[2]) );
|
|
|
|
return h1 ^ h2 ^ h3;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|