@@ -10,10 +10,11 @@ typedef long long ll;
10
10
typedef pair<int , int > pii;
11
11
typedef vector<int > vi;
12
12
13
- #include " ../../content/geometry/HalfPlane.h"
14
13
#include " ../../content/geometry/PolygonArea.h"
15
-
14
+ typedef Point< double > P;
16
15
ostream &operator <<(ostream &os, P p) { return cout << " (" << p.x << " ," << p.y << " )" ; }
16
+ #include " ../../content/geometry/HalfPlane.h"
17
+
17
18
18
19
namespace sjtu {
19
20
typedef double T;
@@ -203,7 +204,7 @@ void testEmpty() {
203
204
}
204
205
void testRandom () {
205
206
int lim = 1e1 ;
206
- for (int i = 0 ; i < 10000 ; i++) {
207
+ for (int i = 0 ; i < 10000000 ; i++) {
207
208
vector<Line> t;
208
209
for (int i = 0 ; i < 6 ; i++) {
209
210
Line cand{P (0 , 0 ), P (0 , 0 )};
@@ -214,9 +215,11 @@ void testRandom() {
214
215
addInf (t, lim);
215
216
auto res = halfPlaneIntersection (t);
216
217
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);
218
221
if (diff > EPS) {
219
- cout << diff << ' ' << area << ' ' << endl;
222
+ cout << diff << ' ' << area << ' ' <<resArea<< endl;
220
223
for (auto i : t)
221
224
cout << i[0 ] << " ->" << i[1 ] << ' ' ;
222
225
cout << endl;
@@ -237,6 +240,10 @@ int main() {
237
240
testRandom ();
238
241
// Failure case for MIT's half plane cod
239
242
// 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;
240
247
// addInf(t);
241
248
// cout << polygonArea2(halfPlaneIntersection(t)) << endl;
242
249
// cout << MIT::Intersection_Area(convert(t)) << endl;
0 commit comments