@@ -10,10 +10,11 @@ typedef long long ll;
1010typedef pair<int , int > pii;
1111typedef vector<int > vi;
1212
13- #include " ../../content/geometry/HalfPlane.h"
1413#include " ../../content/geometry/PolygonArea.h"
15-
14+ typedef Point< double > P;
1615ostream &operator <<(ostream &os, P p) { return cout << " (" << p.x << " ," << p.y << " )" ; }
16+ #include " ../../content/geometry/HalfPlane.h"
17+
1718
1819namespace sjtu {
1920typedef double T;
@@ -203,7 +204,7 @@ void testEmpty() {
203204}
204205void testRandom () {
205206 int lim = 1e1 ;
206- for (int i = 0 ; i < 10000 ; i++) {
207+ for (int i = 0 ; i < 10000000 ; i++) {
207208 vector<Line> t;
208209 for (int i = 0 ; i < 6 ; i++) {
209210 Line cand{P (0 , 0 ), P (0 , 0 )};
@@ -214,9 +215,11 @@ void testRandom() {
214215 addInf (t, lim);
215216 auto res = halfPlaneIntersection (t);
216217 double area = sjtu::halfPlaneIntersection (t);
217- double diff = abs (2 * area - polygonArea2 (res));
218+ double resArea = polygonArea2 (res)/2 ;
219+ if (isnan (resArea)) resArea = 0 ;
220+ double diff = abs (area - resArea);
218221 if (diff > EPS) {
219- cout << diff << ' ' << area << ' ' << endl;
222+ cout << diff << ' ' << area << ' ' <<resArea<< endl;
220223 for (auto i : t)
221224 cout << i[0 ] << " ->" << i[1 ] << ' ' ;
222225 cout << endl;
@@ -237,6 +240,10 @@ int main() {
237240 testRandom ();
238241 // Failure case for MIT's half plane cod
239242 // vector<Line> t({{P(9, 8), P(9, 1)}, {P(3, 3), P(3, 5)}, {P(7, 6), P(0, 8)}});
243+ // Failure case for old code.
244+ // vector<Line> t({{P(3,0),P(3,3)},{P(5,3), P(5,0)}, {P(4,-2), P(0,1)}, {P(3,-1), P(0,-1)}});
245+ // addInf(t);
246+ // cout << polygonArea2(halfPlaneIntersection(t)) << endl;
240247 // addInf(t);
241248 // cout << polygonArea2(halfPlaneIntersection(t)) << endl;
242249 // cout << MIT::Intersection_Area(convert(t)) << endl;
0 commit comments