Trait geo::GeoFloat [−][src]
Expand description
A common numeric trait used for geo algorithms.
Different numeric types have different tradeoffs. geo
strives to utilize generics to allow
users to choose their numeric types. If you are writing a function which you’d like to be
generic over all the numeric types supported by geo, you probably want to constraint
your function input to GeoFloat
. For methods which work for integers, and not just floating
point, see GeoNum
.
Examples
use geo::{GeoFloat, MultiPolygon, Polygon, Point};
// An admittedly silly method implementation, but the signature shows how to use the GeoFloat trait
fn farthest_from<'a, T: GeoFloat>(point: &Point<T>, polygons: &'a MultiPolygon<T>) -> Option<&'a Polygon<T>> {
polygons.iter().fold(None, |accum, next| {
match accum {
None => Some(next),
Some(farthest) => {
use geo::algorithm::{euclidean_distance::EuclideanDistance};
if next.euclidean_distance(point) > farthest.euclidean_distance(point) {
Some(next)
} else {
Some(farthest)
}
}
}
})
}