Compute the intersection point of two line segments (as infinite lines).
(a1: [f64; 2], a2: [f64; 2], b1: [f64; 2], b2: [f64; 2])
| 172 | |
| 173 | /// Compute the intersection point of two line segments (as infinite lines). |
| 174 | fn 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. |
| 190 | fn strip_closing(ring: &[[f64; 2]]) -> Vec<[f64; 2]> { |
no outgoing calls
no test coverage detected