mihaild

Untitled

Apr 26th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. typedef array<double, 3> point;
  2. typedef array<int, 3> int_point;
  3. struct MegaStructure {
  4. unordered_map<int_point, list<point> > points_by_cube;
  5. double R;
  6. int cube_coordinate(double x) {
  7.   return ceil(x / 2*R);
  8. }
  9. int_point ceil_point(point p) {
  10.   return int_point({cube_coordinate(p[0]),cube_coordinate(p[1]),cube_coordinate(p[2])});
  11. }
  12. void add_point(point p) {
  13.   points_by_cube(ceil_point(p)).insert(p);
  14. }
  15. bool check_points(point p1, point p2) {
  16.   return sqr(p1[0] - p2[0])+sqr(p1[1]-p2[1])+sqr(p1[2]-p2[2]) > R*R;
  17. }
  18. bool check_point(point p) {
  19.   int_point g(ceil_point(p));
  20.   for (int i = -1; i < 2; ++i) {
  21.     int_point c(ceil_point(p));
  22.     c[0] += i;
  23.     for (int j = -1; j < 2; ++j) {
  24.       c[1] += j;
  25.       for (int k = -1; k < 2; ++k) {
  26.         c[2] += k;
  27.         for (const auto &t : points_by_cube(c)) {
  28.          if (!check_points(p, t)) {
  29.            return false;
  30.          }
  31.         }
  32.       }
  33.     }
  34.   }
  35.   return true;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment