1
1
#include " ../utilities/template.h"
2
+ #include " ../utilities/randGeo.h"
2
3
4
+ #include " ../../content/geometry/lineDistance.h"
3
5
#include " ../../content/geometry/CircleLine.h"
4
6
5
7
typedef Point<double > P;
6
8
int main () {
7
- cin.sync_with_stdio (0 );
8
- cin.tie (0 );
9
- cin.exceptions (cin.failbit );
10
9
{
11
10
auto res = circleLine (P (0 , 0 ), 1 , P (-1 , -1 ), P (1 , 1 ));
12
11
assert (res.size () == 2 );
@@ -21,5 +20,31 @@ int main() {
21
20
auto res = circleLine (P (4 , 4 ), 1 , P (0 , 0 ), P (5 , 0 ));
22
21
assert (res.size () == 0 );
23
22
}
23
+ rep (it,0 ,100000 ) {
24
+ P a = randIntPt (5 );
25
+ P b = randIntPt (5 );
26
+ P c = randIntPt (5 );
27
+ if (a == b) {
28
+ // Not a well defined line
29
+ continue ;
30
+ }
31
+ double r = sqrt (rand () % 49 );
32
+ vector<P> points = circleLine (c, r, a, b);
33
+
34
+ // Soundness
35
+ assert (sz (points) <= 2 );
36
+ for (P p : points) {
37
+ // Point is on circle
38
+ assert (abs ((p - c).dist () - r) < 1e-6 );
39
+ // Point is on line
40
+ assert (lineDist (a, b, p) < 1e-6 );
41
+ }
42
+
43
+ // Best-effort completeness check:
44
+ // in some easy cases we must have points in the intersection.
45
+ if ((a - c).dist () < r - 1e-6 || (b - c).dist () < r - 1e-6 || ((a + b) / 2 - c).dist () < r - 1e-6 ) {
46
+ assert (!points.empty ());
47
+ }
48
+ }
24
49
cout<<" Tests passed!" <<endl;
25
50
}
0 commit comments