Compute total path length from waypoints.
(waypoints: &[Waypoint])
| 229 | |
| 230 | /// Compute total path length from waypoints. |
| 231 | fn compute_path_length(waypoints: &[Waypoint]) -> f64 { |
| 232 | waypoints |
| 233 | .windows(2) |
| 234 | .map(|w| { |
| 235 | let dx = w[1].x - w[0].x; |
| 236 | let dy = w[1].y - w[0].y; |
| 237 | (dx * dx + dy * dy).sqrt() |
| 238 | }) |
| 239 | .sum() |
| 240 | } |
| 241 | |
| 242 | #[cfg(test)] |
| 243 | mod tests { |