Skip to content

Commit ed75bf9

Browse files
committed
Fixed some issues
1 parent 888dd17 commit ed75bf9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

content/geometry/halfPlane.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ typedef Point<double> P;
1818
typedef array<P, 2> Line;
1919
#define sp(a) a[0], a[1]
2020
#define ang(a) atan2((a[1] - a[0]).y, (a[1] - a[0]).x)
21-
21+
bool cmp(Line a, Line b) {
22+
auto s = ang(a) - ang(b);
23+
return s == 0 ? sideOf(sp(b), a[0]) >=0 : s < 0;
24+
}
2225
vector<P> halfPlaneIntersection(vector<Line> vs) {
23-
sort(all(vs), [](auto a, auto b) { return ang(a) < ang(b);});
24-
vs.resize(unique(all(vs), [](auto a, auto b){ return ang(a) == ang(b);}) - vs.begin());
26+
sort(all(vs), cmp);
2527
vector<Line> deq(sz(vs)+5);
2628
vector<P> ans(sz(vs)+5);
2729
int dh = 0, dt = 1, ah=0, at=0;
@@ -37,5 +39,7 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
3739
while (ah < at && sideOf(sp(deq[dt]), ans[ah]) < 0) ah++, dh++;
3840
if (dt-dh <= 2) return {};
3941
ans[at++] = lineInter(sp(deq[dh]), sp(deq[dt-1])).second;
40-
return {ans.begin()+ah, ans.begin()+at};
42+
vector<P> res = {ans.begin()+ah, ans.begin()+at};
43+
res.erase(unique(all(res)), res.end());
44+
return res;
4145
}

0 commit comments

Comments
 (0)