Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef array<double, 3> point;
- typedef array<int, 3> int_point;
- struct MegaStructure {
- unordered_map<int_point, list<point> > points_by_cube;
- double R;
- int cube_coordinate(double x) {
- return ceil(x / 2*R);
- }
- int_point ceil_point(point p) {
- return int_point({cube_coordinate(p[0]),cube_coordinate(p[1]),cube_coordinate(p[2])});
- }
- void add_point(point p) {
- points_by_cube(ceil_point(p)).insert(p);
- }
- bool check_points(point p1, point p2) {
- return sqr(p1[0] - p2[0])+sqr(p1[1]-p2[1])+sqr(p1[2]-p2[2]) > R*R;
- }
- bool check_point(point p) {
- int_point g(ceil_point(p));
- for (int i = -1; i < 2; ++i) {
- int_point c(ceil_point(p));
- c[0] += i;
- for (int j = -1; j < 2; ++j) {
- c[1] += j;
- for (int k = -1; k < 2; ++k) {
- c[2] += k;
- for (const auto &t : points_by_cube(c)) {
- if (!check_points(p, t)) {
- return false;
- }
- }
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment