(a: [f64; 2], b: [f64; 2], meters: f64)
| 249 | type OffsetPair = (([f64; 2], [f64; 2]), ([f64; 2], [f64; 2])); |
| 250 | |
| 251 | fn offset_segment(a: [f64; 2], b: [f64; 2], meters: f64) -> OffsetPair { |
| 252 | let normal = edge_outward_normal(a, b); |
| 253 | let dlat = meters / 110_540.0; |
| 254 | let mid_lat = ((a[1] + b[1]) / 2.0).to_radians().cos().max(0.001); |
| 255 | let dlng = meters / (111_320.0 * mid_lat); |
| 256 | |
| 257 | let left = ( |
| 258 | [a[0] + normal[0] * dlng, a[1] + normal[1] * dlat], |
| 259 | [b[0] + normal[0] * dlng, b[1] + normal[1] * dlat], |
| 260 | ); |
| 261 | let right = ( |
| 262 | [a[0] - normal[0] * dlng, a[1] - normal[1] * dlat], |
| 263 | [b[0] - normal[0] * dlng, b[1] - normal[1] * dlat], |
| 264 | ); |
| 265 | (left, right) |
| 266 | } |
| 267 | |
| 268 | /// Outward-pointing unit normal for an edge (a→b). |
| 269 | /// |
no test coverage detected