pub trait InterpolatableLine<F: CoordFloat> {
type Output;
// Required methods
fn point_at_ratio_from_start<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
ratio: F,
) -> Self::Output;
fn point_at_ratio_from_end<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
ratio: F,
) -> Self::Output;
fn point_at_distance_from_start<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
distance: F,
) -> Self::Output;
fn point_at_distance_from_end<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
distance: F,
) -> Self::Output;
}
Expand description
A linear geometry (1-D) which can have a point interpolated partially into it.
Related: See Densify
if you’d like to interpolate potentially many points into a geometry.
Required Associated Types§
Required Methods§
Sourcefn point_at_ratio_from_start<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
ratio: F,
) -> Self::Output
fn point_at_ratio_from_start<MetricSpace: InterpolatePoint<F> + Length<F>>( &self, metric_space: &MetricSpace, ratio: F, ) -> Self::Output
Returns a new point part way down the line.
§Params
metric_space
: e.g.Euclidean
,Haversine
, orGeodesic
. Seemetric_spaces
ratio
: the ratio of the total line length. It will be bounded between 0..1.0.0
will return the start of the line.1.0
will return the end of the line.
§Example
use geo::algorithm::line_measures::{Haversine, Euclidean, InterpolatableLine};
use geo::wkt;
let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));
let quarter_distance = line_string.point_at_ratio_from_start(&Euclidean, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(0. 5.)));
let quarter_distance = line_string.point_at_ratio_from_start(&Haversine, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(0. 4.961924877405399)), epsilon=1e-14);
Sourcefn point_at_ratio_from_end<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
ratio: F,
) -> Self::Output
fn point_at_ratio_from_end<MetricSpace: InterpolatePoint<F> + Length<F>>( &self, metric_space: &MetricSpace, ratio: F, ) -> Self::Output
Returns a new point part way down the line, starting from the end of the line.
§Params
metric_space
: e.g.Euclidean
,Haversine
, orGeodesic
. Seemetric_spaces
ratio
: the ratio of the total line length. It will be bounded between 0..1.0.0
will return the end of the line.1.0
will return the start of the line.
§Example
use geo::algorithm::line_measures::{Haversine, Euclidean, InterpolatableLine};
use geo::wkt;
let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));
let quarter_distance = line_string.point_at_ratio_from_end(&Euclidean, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(5. 10.0)));
let quarter_distance = line_string.point_at_ratio_from_end(&Haversine, 0.25).unwrap();
assert_relative_eq!(quarter_distance, wkt!(POINT(4.961333045966285 10.037420806650719)), epsilon=1e-14);
Sourcefn point_at_distance_from_start<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
distance: F,
) -> Self::Output
fn point_at_distance_from_start<MetricSpace: InterpolatePoint<F> + Length<F>>( &self, metric_space: &MetricSpace, distance: F, ) -> Self::Output
Returns a new point distance
from the start of the line.
§Params
metric_space
: e.g.Euclidean
,Haversine
, orGeodesic
. Seemetric_spaces
distance
: How far down the line. The units of distance depend on the metric space. Distance will be clamped so that the returned point will not be outside ofline
.
§Example
use geo::algorithm::line_measures::{Haversine, Euclidean, InterpolatableLine};
use geo::wkt;
let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));
// For Euclidean calculations, distance is in the same units as your points
let near_start = line_string.point_at_distance_from_start(&Euclidean, 0.5).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(0. 0.5)));
// For Haversine calculations, distance is in meters
let near_start = line_string.point_at_distance_from_start(&Haversine, 100_000.0).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(0. 0.899320363724538)), epsilon=1e-14);
Sourcefn point_at_distance_from_end<MetricSpace: InterpolatePoint<F> + Length<F>>(
&self,
metric_space: &MetricSpace,
distance: F,
) -> Self::Output
fn point_at_distance_from_end<MetricSpace: InterpolatePoint<F> + Length<F>>( &self, metric_space: &MetricSpace, distance: F, ) -> Self::Output
Returns a new point distance
from the end of the line.
§Params
metric_space
: e.g.Euclidean
,Haversine
, orGeodesic
. Seemetric_spaces
distance
: How far down the line. The units of distance depend on the metric space. Distance will be clamped so that the returned point will not be outside ofline
.
§Example
use geo::algorithm::line_measures::{Haversine, Euclidean, InterpolatableLine};
use geo::wkt;
let line_string = wkt!(LINESTRING(0. 0., 0. 10.,10. 10.));
// For Euclidean calculations, distance is in the same units as your points
let near_start = line_string.point_at_distance_from_end(&Euclidean, 0.5).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(9.5 10.)));
// For Haversine calculations, distance is in meters
let near_start = line_string.point_at_distance_from_end(&Haversine, 100_000.0).unwrap();
assert_relative_eq!(near_start, wkt!(POINT(9.086875463645015 10.012416322308656)), epsilon=1e-14);
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.