Skip to content

Commit 494904d

Browse files
committed
Add lineIntersection test
1 parent 2771e3e commit 494904d

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

content/geometry/lineIntersection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Products of three coordinates are used in intermediate steps so watch out for ov
1313
\begin{minipage}{15mm}
1414
\includegraphics[width=\textwidth]{content/geometry/lineIntersection}
1515
\end{minipage}
16-
* Status: tested through half-plane tests
16+
* Status: fuzz-tested, and tested through half-plane tests
1717
* Usage:
1818
* auto res = lineInter(s1,e1,s2,e2);
1919
* if (res.first == 1)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define rep(i, a, b) for(int i = a; i < int(b); ++i)
5+
#define trav(a, v) for(auto& a : v)
6+
#define all(x) x.begin(), x.end()
7+
#define sz(x) (int)(x).size()
8+
9+
typedef long long ll;
10+
typedef pair<int, int> pii;
11+
typedef vector<int> vi;
12+
13+
#include "../../content/geometry/lineIntersection.h"
14+
#include "../../content/geometry/lineDistance.h"
15+
16+
int main() {
17+
rep(t,0,1000000) {
18+
const int GRID=10;
19+
Point<double>
20+
a(rand()%GRID, rand()%GRID),
21+
b(rand()%GRID, rand()%GRID),
22+
c(rand()%GRID, rand()%GRID),
23+
d(rand()%GRID, rand()%GRID);
24+
auto pa = lineInter(a,b,c,d);
25+
if (pa.first == 1) {
26+
assert(lineDist(a, b, pa.second) < 1e-8);
27+
assert(lineDist(c, d, pa.second) < 1e-8);
28+
}
29+
}
30+
cout<<"Tests passed!"<<endl;
31+
}

0 commit comments

Comments
 (0)