MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / line_intersection

Function line_intersection

nodedb-spatial/src/predicates/intersection.rs:174–187  ·  view source on GitHub ↗

Compute the intersection point of two line segments (as infinite lines).

(a1: [f64; 2], a2: [f64; 2], b1: [f64; 2], b2: [f64; 2])

Source from the content-addressed store, hash-verified

172
173/// Compute the intersection point of two line segments (as infinite lines).
174fn line_intersection(a1: [f64; 2], a2: [f64; 2], b1: [f64; 2], b2: [f64; 2]) -> Option<[f64; 2]> {
175 let dx_a = a2[0] - a1[0];
176 let dy_a = a2[1] - a1[1];
177 let dx_b = b2[0] - b1[0];
178 let dy_b = b2[1] - b1[1];
179
180 let denom = dx_a * dy_b - dy_a * dx_b;
181 if denom.abs() < 1e-15 {
182 return None; // Parallel lines.
183 }
184
185 let t = ((b1[0] - a1[0]) * dy_b - (b1[1] - a1[1]) * dx_b) / denom;
186 Some([a1[0] + t * dx_a, a1[1] + t * dy_a])
187}
188
189/// Strip the closing vertex from a ring if present.
190fn strip_closing(ring: &[[f64; 2]]) -> Vec<[f64; 2]> {

Callers 1

sutherland_hodgmanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected