Skip to content

Commit 1aa4b39

Browse files
committed
Fixed bugs/found bugs
1 parent 1c47a37 commit 1aa4b39

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

content/geometry/HalfPlane.h

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
3737
while (ah<at && sideOf(sp(vs[i]),ans[at-1]) < 0) at--;
3838
while (i!=n && ah<at && sideOf(sp(vs[i]),ans[ah])<0) ah++;
3939
auto res = lineInter(sp(vs[i]), sp(deq[at]));
40-
auto res2 = lineInter2(sp(vs[i]), sp(deq[at]));
41-
// if (isnan(res2.x) || isinf(res2.x)) continue;
42-
bool b = (isnan(res2.x) || isinf(res2.y)) == (res.first != 1);
43-
assert(b);
4440
if (res.first != 1) continue;
4541
ans[at++] = res.second;
4642
deq[at] = vs[i];

content/geometry/lineIntersection.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pair<int, P> lineInter(P s1, P e1, P s2, P e2) {
2828
else
2929
return {1, s2-(e2-s2)*s1.cross(e1, s2)/d};
3030
}
31+
3132
template<class P> P lineInter2(P p1, P p2, P q1, P q2) {
3233
double a1 = q1.cross(q2, p1), a2 = -q1.cross(q2, p2);
3334
auto res = (p1 * a2 + p2 * a1) / (a1 + a2);

fuzz-tests/geometry/HalfPlane.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ void testRandom() {
223223
for (auto i : t)
224224
cout << i[0] << "->" << i[1] << ' ';
225225
cout << endl;
226+
for (auto i : t)
227+
cout << "{P"<<i[0] << "," << "P"<<i[1] << "},";
228+
cout << endl;
226229
for (auto i : res)
227230
cout << i << ',';
228231
cout << endl;
@@ -237,7 +240,12 @@ int main() {
237240
testLine();
238241
testPoint();
239242
testEmpty();
240-
testRandom();
243+
// testRandom();
244+
// Case that messes with precision
245+
vector<Line> t({{P(8,9),P(8,2)},{P(3,9),P(5,2)},{P(8,2),P(8,3)},{P(7,2),P(1,7)},{P(1,0),P(7,1)},{P(9,2),P(5,6)},{P(10,10),P(-10,10)},{P(-10,10),P(-10,-10)},{P(-10,-10),P(10,-10)},{P(10,-10),P(10,10)}});
246+
auto res = halfPlaneIntersection(t);
247+
cout<<polygonArea2(res)<<endl;
248+
cout << sjtu::halfPlaneIntersection(t)<<endl;
241249
// Failure case for MIT's half plane cod
242250
// vector<Line> t({{P(9, 8), P(9, 1)}, {P(3, 3), P(3, 5)}, {P(7, 6), P(0, 8)}});
243251
// Failure case for old code.
@@ -246,6 +254,5 @@ int main() {
246254
// cout << polygonArea2(halfPlaneIntersection(t)) << endl;
247255
// addInf(t);
248256
// cout << polygonArea2(halfPlaneIntersection(t)) << endl;
249-
// cout << MIT::Intersection_Area(convert(t)) << endl;
250257
cout << "Tests passed!" << endl;
251258
}

0 commit comments

Comments
 (0)