| 75 | _nn(p, root, bb(from, to), mn, resp, 0, allow_same); |
| 76 | return make_pair(resp, !std::isinf(mn)); } |
| 77 | void _nn(const pt &p, node *n, bb b, |
| 78 | double &mn, pt &resp, int c, bool same) { |
| 79 | if (!n || b.dist(p) > mn) return; |
| 80 | bool l1 = true, l2 = false; |
| 81 | if ((same || p.dist(n->p) > EPS) && p.dist(n->p) < mn) |
| 82 | mn = p.dist(resp = n->p); |
| 83 | node *n1 = n->l, *n2 = n->r; |
| 84 | rep(i,0,2) { |
| 85 | if (i == 1 || cmp(c)(n->p, p)) swap(n1,n2),swap(l1,l2); |
| 86 | _nn(p, n1, b.bound(n->p.coord[c], c, l1), mn, |
| 87 | resp, INC(c), same); } } }; |
| 88 | // vim: cc=60 ts=2 sts=2 sw=2: |