Skip to content

Commit bf838c6

Browse files
committed
Shortened half plane a bit
1 parent 8c6bb7c commit bf838c6

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

content/geometry/HalfPlane.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Author: chilli
43
* Date: 2019-05-05
@@ -31,16 +30,15 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
3130
vector<Line> deq(sz(vs) + 5);
3231
vector<P> ans(sz(vs) + 5);
3332
deq[0] = vs[0];
34-
int ah = 0, at = 0;
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)){
33+
int ah = 0, at = 0, n = sz(vs);
34+
rep(i,1,n+1) {
35+
if (i == n) vs.push_back(deq[ah]);
4036
if (angDiff(vs[i], vs[i - 1]) == 0) continue;
41-
fix(vs[i], vs[i]); deq[at] = vs[i];
37+
while (ah<at && sideOf(sp(vs[i]),ans[at-1]) < 0) at--;
38+
while (i!=n && ah<at && sideOf(sp(vs[i]),ans[ah])<0) ah++;
39+
ans[at++] = lineInter(sp(vs[i]), sp(deq[at])).second;
40+
deq[at] = vs[i];
4241
}
43-
fix(deq[ah], deq[at]);
4442
if (at - ah <= 2) return {};
4543
return {ans.begin() + ah, ans.begin() + at};
4644
}

0 commit comments

Comments
 (0)