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

Function closest_point

code/geometry/lines.cpp:6–12  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4bool parallel(L(a, b), L(p, q)) {
5 return abs(cross(b - a, q - p)) < EPS; }
6point closest_point(L(a, b), P(c), bool segment = false) {
7 if (segment) {
8 if (dot(b - a, c - b) > 0) return b;
9 if (dot(a - b, c - a) > 0) return a;
10 }
11 double t = dot(c - a, b - a) / norm(b - a);
12 return a + t * (b - a); }
13double line_segment_distance(L(a,b), L(c,d)) {
14 double x = INFINITY;
15 if (abs(a - b) < EPS && abs(c - d) < EPS) x = abs(a - c);

Callers 3

distMethod · 0.85
testFunction · 0.85
line_segment_distanceFunction · 0.85

Calls 1

dotFunction · 0.85

Tested by 1

testFunction · 0.68