logo
pub trait LineLocatePoint<T, Rhs> {
    type Output;
    type Rhs;

    fn line_locate_point(&self, p: &Rhs) -> Self::Output;
}
Expand description

Returns a (option of the) fraction of the line’s total length representing the location of the closest point on the line to the given point.

If the line has zero length the fraction returned is zero.

If either the point’s coordinates or any coordinates of the line are not finite, returns None.

Examples

use geo::{LineString, point};
use geo::LineLocatePoint;

let linestring: LineString = vec![
    [-1.0, 0.0],
    [0.0, 0.0],
    [0.0, 1.0]
].into();

assert_eq!(linestring.line_locate_point(&point!(x: -1.0, y: 0.0)), Some(0.0));
assert_eq!(linestring.line_locate_point(&point!(x: -0.5, y: 0.0)), Some(0.25));
assert_eq!(linestring.line_locate_point(&point!(x: 0.0, y: 0.0)), Some(0.5));
assert_eq!(linestring.line_locate_point(&point!(x: 0.0, y: 0.5)), Some(0.75));
assert_eq!(linestring.line_locate_point(&point!(x: 0.0, y: 1.0)), Some(1.0));

Required Associated Types

Required Methods

Implementors