Minimum squared distance between two line segments.
(a1: [f64; 2], a2: [f64; 2], b1: [f64; 2], b2: [f64; 2])
| 133 | |
| 134 | /// Minimum squared distance between two line segments. |
| 135 | pub fn segment_to_segment_dist_sq(a1: [f64; 2], a2: [f64; 2], b1: [f64; 2], b2: [f64; 2]) -> f64 { |
| 136 | if segments_intersect(a1, a2, b1, b2) { |
| 137 | return 0.0; |
| 138 | } |
| 139 | // Min of all endpoint-to-segment distances. |
| 140 | let d1 = point_to_segment_dist_sq(a1, b1, b2); |
| 141 | let d2 = point_to_segment_dist_sq(a2, b1, b2); |
| 142 | let d3 = point_to_segment_dist_sq(b1, a1, a2); |
| 143 | let d4 = point_to_segment_dist_sq(b2, a1, a2); |
| 144 | d1.min(d2).min(d3).min(d4) |
| 145 | } |
| 146 | |
| 147 | /// Extract all edges from a polygon ring as segment pairs. |
| 148 | pub fn ring_edges(ring: &[[f64; 2]]) -> Vec<([f64; 2], [f64; 2])> { |