MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / intersect

Function intersect

code/geometry/lines.cpp:29–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 }
28 return x; }
29bool intersect(L(a,b), L(p,q), point &res,
30 bool lseg=false, bool rseg=false) {
31 // NOTE: check parallel/collinear before
32 point r = b - a, s = q - p;
33 double c = cross(r, s),
34 t = cross(p - a, s) / c, u = cross(p - a, r) / c;
35 if (lseg && (t < 0-EPS || t > 1+EPS)) return false;
36 if (rseg && (u < 0-EPS || u > 1+EPS)) return false;
37 res = a + t * r; return true; }
38// vim: cc=60 ts=2 sts=2 sw=2:

Callers 5

testFunction · 0.70
cut_polygonFunction · 0.70
line_segment_intersectFunction · 0.70
addMethod · 0.50
get_minMethod · 0.50

Calls 1

crossFunction · 0.85

Tested by 1

testFunction · 0.56