[][src]Trait geo::algorithm::euclidean_distance::EuclideanDistance

pub trait EuclideanDistance<T, Rhs = Self> {
    fn euclidean_distance(&self, rhs: &Rhs) -> T;
}

Returns the distance between two geometries.

Required methods

fn euclidean_distance(&self, rhs: &Rhs) -> T

Returns the distance between two geometries

If a Point is contained by a Polygon, the distance is 0.0

If a Point lies on a Polygon's exterior or interior rings, the distance is 0.0

If a Point lies on a LineString, the distance is 0.0

The distance between a Point and an empty LineString is 0.0

Examples

use geo::{COORD_PRECISION, Point, LineString, Polygon};
use geo::algorithm::euclidean_distance::EuclideanDistance;

// Point to Point example
let p = Point::new(-72.1235, 42.3521);
let dist = p.euclidean_distance(&Point::new(-72.1260, 42.45));
assert!(dist < COORD_PRECISION);

// Point to Polygon example
let points = vec![
    (5., 1.),
    (4., 2.),
    (4., 3.),
    (5., 4.),
    (6., 4.),
    (7., 3.),
    (7., 2.),
    (6., 1.),
    (5., 1.)
];
let ls: LineString<_> = points.iter().map(|e| Point::new(e.0, e.1)).collect();
let poly = Polygon::new(ls, vec![]);
// A Random point outside the polygon
let p = Point::new(2.5, 0.5);
let dist = p.euclidean_distance(&poly);
assert_eq!(dist, 2.1213203435596424);

// Point to LineString example
let points = vec![
    (5., 1.),
    (4., 2.),
    (4., 3.),
    (5., 4.),
    (6., 4.),
    (7., 3.),
    (7., 2.),
    (6., 1.),
];
let ls: LineString<_> = points.iter().map(|e| Point::new(e.0, e.1)).collect();
// A Random point outside the LineString
let p = Point::new(5.5, 2.1);
let dist = p.euclidean_distance(&ls);
assert_eq!(dist, 1.1313708498984762);
Loading content...

Implementors

impl<T> EuclideanDistance<T, Line<T>> for Line<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

Line to Line distance

impl<T> EuclideanDistance<T, Line<T>> for LineString<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

LineString to Line

impl<T> EuclideanDistance<T, Line<T>> for MultiPolygon<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

MultiPolygon to Line distance

impl<T> EuclideanDistance<T, Line<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, line: &Line<T>) -> T[src]

Minimum distance from a Line to a Point

impl<T> EuclideanDistance<T, Line<T>> for Polygon<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

impl<T> EuclideanDistance<T, LineString<T>> for Line<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

Line to LineString

impl<T> EuclideanDistance<T, LineString<T>> for LineString<T> where
    T: Float + Signed + RTreeNum
[src]

LineString-LineString distance

impl<T> EuclideanDistance<T, LineString<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, linestring: &LineString<T>) -> T[src]

Minimum distance from a Point to a LineString

impl<T> EuclideanDistance<T, LineString<T>> for Polygon<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

Polygon to LineString distance

impl<T> EuclideanDistance<T, MultiLineString<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, mls: &MultiLineString<T>) -> T[src]

Minimum distance from a Point to a MultiLineString

impl<T> EuclideanDistance<T, MultiPoint<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, points: &MultiPoint<T>) -> T[src]

Minimum distance from a Point to a MultiPoint

impl<T> EuclideanDistance<T, MultiPolygon<T>> for Line<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

Line to MultiPolygon distance

impl<T> EuclideanDistance<T, MultiPolygon<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, mpolygon: &MultiPolygon<T>) -> T[src]

Minimum distance from a Point to a MultiPolygon

impl<T> EuclideanDistance<T, Point<T>> for Line<T> where
    T: Float
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a Line to a Point

impl<T> EuclideanDistance<T, Point<T>> for LineString<T> where
    T: Float
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a LineString to a Point

impl<T> EuclideanDistance<T, Point<T>> for MultiLineString<T> where
    T: Float
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a MultiLineString to a Point

impl<T> EuclideanDistance<T, Point<T>> for MultiPoint<T> where
    T: Float
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a MultiPoint to a Point

impl<T> EuclideanDistance<T, Point<T>> for MultiPolygon<T> where
    T: Float
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a MultiPolygon to a Point

impl<T> EuclideanDistance<T, Point<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, p: &Point<T>) -> T[src]

Minimum distance between two Points

impl<T> EuclideanDistance<T, Point<T>> for Polygon<T> where
    T: Float
[src]

fn euclidean_distance(&self, point: &Point<T>) -> T[src]

Minimum distance from a Polygon to a Point

impl<T> EuclideanDistance<T, Point<T>> for Triangle<T> where
    T: Float
[src]

impl<T> EuclideanDistance<T, Polygon<T>> for Line<T> where
    T: Float + Signed + RTreeNum + FloatConst
[src]

impl<T> EuclideanDistance<T, Polygon<T>> for LineString<T> where
    T: Float + FloatConst + Signed + RTreeNum
[src]

LineString to Polygon

impl<T> EuclideanDistance<T, Polygon<T>> for Point<T> where
    T: Float
[src]

fn euclidean_distance(&self, polygon: &Polygon<T>) -> T[src]

Minimum distance from a Point to a Polygon

impl<T> EuclideanDistance<T, Polygon<T>> for Polygon<T> where
    T: Float + FloatConst + RTreeNum
[src]

fn euclidean_distance(&self, poly2: &Polygon<T>) -> T[src]

This implementation has a "fast path" in cases where both input polygons are convex: it switches to an implementation of the "rotating calipers" method described in Pirzadeh (1999), pp24—30, which is approximately an order of magnitude faster than the standard method.

Loading content...