Skip to content

Commit 4b3e356

Browse files
committed
Win a few lines in FastDelaunay
1 parent 4c64c2e commit 4b3e356

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

content/geometry/FastDelaunay.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct Quad {
2626
P F() { return r()->p; }
2727
Q r() { return rot->rot; }
2828
Q prev() { return rot->o->rot; }
29-
Q next() { return rot->r()->o->rot; }
29+
Q next() { return r()->prev(); }
3030
};
3131

3232
bool circ(P p, P a, P b, P c) { // is p in the circumcircle?
@@ -35,13 +35,11 @@ bool circ(P p, P a, P b, P c) { // is p in the circumcircle?
3535
return p.cross(a,b)*C + p.cross(b,c)*A + p.cross(c,a)*B > 0;
3636
}
3737
Q makeEdge(P orig, P dest) {
38-
Q q0 = new Quad{0,0,0,orig}, q1 = new Quad{0,0,0,arb},
39-
q2 = new Quad{0,0,0,dest}, q3 = new Quad{0,0,0,arb};
40-
q0->o = q0; q2->o = q2; // 0-0, 2-2
41-
q1->o = q3; q3->o = q1; // 1-3, 3-1
42-
q0->rot = q1; q1->rot = q2;
43-
q2->rot = q3; q3->rot = q0;
44-
return q0;
38+
Q q[] = {new Quad{0,0,0,orig}, new Quad{0,0,0,arb},
39+
new Quad{0,0,0,dest}, new Quad{0,0,0,arb}};
40+
rep(i,0,4)
41+
q[i]->o = q[-i & 3], q[i]->rot = q[(i+1) & 3];
42+
return *q;
4543
}
4644
void splice(Q a, Q b) {
4745
swap(a->o->rot->o, b->o->rot->o); swap(a->o, b->o);
@@ -66,9 +64,9 @@ pair<Q,Q> rec(const vector<P>& s) {
6664
#define H(e) e->F(), e->p
6765
#define valid(e) (e->F().cross(H(base)) > 0)
6866
Q A, B, ra, rb;
69-
int half = (sz(s) + 1) / 2;
70-
tie(ra, A) = rec({s.begin(), s.begin() + half});
71-
tie(B, rb) = rec({s.begin() + half, s.end()});
67+
int half = sz(s) / 2;
68+
tie(ra, A) = rec({all(s) - half});
69+
tie(B, rb) = rec({sz(s) - half + all(s)});
7270
while ((B->p.cross(H(A)) < 0 && (A = A->next())) ||
7371
(A->p.cross(H(B)) > 0 && (B = B->r()->o)));
7472
Q base = connect(B->r(), A);

0 commit comments

Comments
 (0)