pub fn closest_point_in_linestring(
position: Coord<f64>,
linestring: &LineString<f64>
) -> Coord<f64>
Expand description
Returns the closest point of points in a given LineString
to a given Coord
.
Examples
use geo::{line_string, coord};
use openrailwaymap_exporter::algorithms::closest_point_in_linestring;
let linestring = line_string![
coord! { x: 0.0, y: 0.0 },
coord! { x: 0.0, y: 10.0 },
coord! { x: 50.0, y: 50.0 },
coord! { x: 100.0, y: 100.0 },
];
let position = coord! { x: 10.0, y: 20.0 };
let closest_position = closest_point_in_linestring(position, &linestring);
assert_eq!(closest_position, coord! { x: 0.0, y: 10.0 });