Skip to content

Commit 8c6bb7c

Browse files
committed
Shortened half plane through macros
1 parent d283267 commit 8c6bb7c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

content/geometry/HalfPlane.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
3232
vector<P> ans(sz(vs) + 5);
3333
deq[0] = vs[0];
3434
int ah = 0, at = 0;
35-
for (int i = 1; i < sz(vs); ++i) {
35+
#define fix(a, b) \
36+
while (ah<at && sideOf(sp(a),ans[at-1]) < 0) at--;\
37+
while (ah<at && sideOf(sp(b),ans[ah]) < 0) ah++;\
38+
ans[at++] = lineInter(sp(a), sp(deq[at])).second;
39+
rep(i,1,sz(vs)){
3640
if (angDiff(vs[i], vs[i - 1]) == 0) continue;
37-
while (ah<at && sideOf(sp(vs[i]),ans[at-1]) < 0) at--;
38-
while (ah<at && sideOf(sp(vs[i]),ans[ah]) < 0) ah++;
39-
ans[at++] = lineInter(sp(deq[at]), sp(vs[i])).second;
40-
deq[at] = vs[i];
41+
fix(vs[i], vs[i]); deq[at] = vs[i];
4142
}
42-
while (ah<at && sideOf(sp(deq[ah]),ans[at-1]) < 0) at--;
43-
while (ah<at && sideOf(sp(deq[at]),ans[ah]) < 0) ah++;
44-
ans[at++] = lineInter(sp(deq[ah]), sp(deq[at])).second;
45-
if (at - ah <= 2) return {};
43+
fix(deq[ah], deq[at]);
44+
if (at - ah <= 2) return {};
4645
return {ans.begin() + ah, ans.begin() + at};
4746
}

0 commit comments

Comments
 (0)