InterpolatePoint

Trait InterpolatePoint 

Source
pub trait InterpolatePoint<F: CoordFloat> {
    // Required methods
    fn point_at_distance_between(
        &self,
        start: Point<F>,
        end: Point<F>,
        distance_from_start: F,
    ) -> Point<F>;
    fn point_at_ratio_between(
        &self,
        start: Point<F>,
        end: Point<F>,
        ratio_from_start: F,
    ) -> Point<F>;
    fn points_along_line(
        &self,
        start: Point<F>,
        end: Point<F>,
        max_distance: F,
        include_ends: bool,
    ) -> impl Iterator<Item = Point<F>>;
}
Expand description

Interpolate a Point along a line between two existing points

Required Methods§

Source

fn point_at_distance_between( &self, start: Point<F>, end: Point<F>, distance_from_start: F, ) -> Point<F>

Returns a new Point along a line between two existing points.

See specific implementations for details.

§Examples
use geo::{Haversine, Euclidean, InterpolatePoint, Point};

let p1: Point = Point::new(0.0, 0.0);
let p2: Point = Point::new(0.0, 2.0);

assert_relative_eq!(Euclidean.point_at_distance_between(p1, p2, 0.5), Point::new(0.0, 0.5));

// The units of the argument depend on the metric space.
// In the case of [`Haversine`], it's meters.
// See the documentation for each metric space for details.
assert_relative_eq!(Haversine.point_at_distance_between(p1, p2, 111_111.0), Point::new(0.0, 0.9992438493379715));
Source

fn point_at_ratio_between( &self, start: Point<F>, end: Point<F>, ratio_from_start: F, ) -> Point<F>

Returns a new Point along a line between two existing points.

See specific implementations for details.

§Examples
use geo::{Haversine, Euclidean, InterpolatePoint, Point};
let p1: Point = Point::new(0.0, 0.0);
let p2: Point = Point::new(20.0, 20.0);

assert_relative_eq!(Euclidean.point_at_ratio_between(p1, p2, 0.5), Point::new(10.0, 10.0));
assert_relative_eq!(Haversine.point_at_ratio_between(p1, p2, 0.5), Point::new(9.685895184381804, 10.150932342575631));
Source

fn points_along_line( &self, start: Point<F>, end: Point<F>, max_distance: F, include_ends: bool, ) -> impl Iterator<Item = Point<F>>

Interpolates Points along a line between start and end.

See specific implementations for details.

As many points as necessary will be added such that the distance between points never exceeds max_distance. If the distance between start and end is less than max_distance, no additional points will be included in the output.

include_ends: Should the start and end points be included in the output?

§Examples
use geo::{Haversine, Euclidean, InterpolatePoint, Point, MultiPoint, LineString, wkt};
let p1: Point = Point::new(0.0, 0.0);
let p2: Point = Point::new(0.0, 2.0);

let intermediate_points: Vec<Point> = Euclidean.points_along_line(p1, p2, 0.5, false).collect();
let multi_point = MultiPoint(intermediate_points);
assert_relative_eq!(multi_point, wkt!(MULTIPOINT(0. 0.5,0. 1.,0. 1.5)));

// The units of the argument depend on the metric space.
// In the case of [`Haversine`], it's meters.
// See the documentation for each metric space for details.
let intermediate_points: Vec<Point> = Haversine.points_along_line(p1, p2, 55_555.0, false).collect();
let multi_point = MultiPoint(intermediate_points);
assert_relative_eq!(multi_point, wkt!(MULTIPOINT(0. 0.4,0. 0.8,0. 1.2,0. 1.6)));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F> InterpolatePoint<f64> for GeodesicMeasure<F>
where F: FnOnce() -> Geodesic,

Interpolate Point(s) along a geodesic line.

Source§

impl<F: CoordFloat + FromPrimitive> InterpolatePoint<F> for Euclidean

Interpolate Point(s) along a line on the Euclidean plane.

Source§

impl<F: CoordFloat + FromPrimitive> InterpolatePoint<F> for HaversineMeasure

Interpolate Point(s) along a great circle.

Source§

impl<F: CoordFloat + FromPrimitive> InterpolatePoint<F> for Rhumb

Interpolate Point(s) along a rhumb line.