Skip to content

Commit

Permalink
Updated with current version
Browse files Browse the repository at this point in the history
  • Loading branch information
Chillee committed May 6, 2019
1 parent e61acd5 commit 4cb642a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
6 changes: 1 addition & 5 deletions content/geometry/HalfPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ vector<P> halfPlaneIntersection(vector<Line> vs) {
while (i!=n && ah<at && sideOf(sp(vs[i]),ans[ah])<0) ah++;
auto res = lineInter(sp(vs[i]), sp(deq[at]));
if (res.first != 1) continue;
mxErr1 = max(mxErr1, (lineDist(sp(vs[i]), res.second)));
mxErr2 = max(mxErr2, (lineDist(sp(vs[i]), lineInter2(sp(vs[i]), sp(deq[at])))));
assert((res.second - lineInter2(sp(vs[i]), sp(deq[at]))).dist() < 1e-8);
// ans[at++] = res.second;
ans[at++] = lineInter2(sp(vs[i]), sp(deq[at]));
ans[at++] = res.second;
deq[at] = vs[i];
}
if (at - ah <= 2) return {};
Expand Down
2 changes: 1 addition & 1 deletion content/geometry/lineDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Returns the signed distance between point p and the line containing points a and
\begin{minipage}{15mm}
\includegraphics[width=\textwidth]{content/geometry/lineDistance}
\end{minipage}
* Status: tested
* Status: tested
*/
#pragma once

Expand Down
26 changes: 12 additions & 14 deletions content/geometry/lineIntersection.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* Source: https://vlecomte.github.io/cp-geo.pdf
* Description:\\
\begin{minipage}{75mm}
If a unique intersection point of the lines going through s1,e1 and s2,e2 exists {1, point} is returned. If no intersection point exists {0, (0,0)} is returned and if infinitely many exists {-1, (0,0)} is returned. The wrong position will be returned if P is Point<ll> and the intersection point does not have integer coordinates. Products of three coordinates are used in intermediate steps so watch out for overflow if using int or long long.
\end{minipage}
If a unique intersection point of the lines going through s1,e1 and s2,e2 exists {1, point} is returned. If no
intersection point exists {0, (0,0)} is returned and if infinitely many exists {-1, (0,0)} is returned. The wrong
position will be returned if P is Point<ll> and the intersection point does not have integer coordinates. Products of
three coordinates are used in intermediate steps so watch out for overflow if using int or long long. \end{minipage}
\begin{minipage}{15mm}
\includegraphics[width=\textwidth]{content/geometry/lineIntersection}
\end{minipage}
Expand All @@ -20,17 +22,13 @@ If a unique intersection point of the lines going through s1,e1 and s2,e2 exists

#include "Point.h"

template<class P>
pair<int, P> lineInter(P s1, P e1, P s2, P e2) {
auto d = (e1-s1).cross(e2-s2);
if (d == 0) //if parallel
return {-(s1.cross(e1, s2)==0 || s2==e2), P(0,0)};
else
return {1, s2-(e2-s2)*s1.cross(e1, s2)/d};
}
template <class P> pair<int, P> lineInter(P s1, P e1, P s2, P e2) {
auto d = (e1 - s1).cross(e2 - s2);
if (d == 0) // if parallel
return {-(s1.cross(e1, s2) == 0 || s2 == e2), P(0, 0)};
else {

template<class P> P lineInter2(P p1, P p2, P q1, P q2) {
double a1 = q1.cross(q2, p1), a2 = -q1.cross(q2, p2);
auto res = (p1 * a2 + p2 * a1) / (a1 + a2);
return res;
double a1 = s2.cross(e2, s1), a2 = -s2.cross(e2, e1);
return {1, (s1 * a2 + e1 * a1) / (a1 + a2)};
}
}
Binary file added fuzz-tests/geometry/HalfPlane
Binary file not shown.
11 changes: 5 additions & 6 deletions fuzz-tests/geometry/HalfPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,11 @@ void testRandom() {
}

int main() {
// test1();
// testInf();
// testLine();
// testPoint();
// testEmpty();
srand(time(0));
test1();
testInf();
testLine();
testPoint();
testEmpty();
testRandom();
// Case that messes with precision
vector<Line> t({{P(8, 9), P(8, 2)},
Expand Down

0 comments on commit 4cb642a

Please sign in to comment.