[][src]Trait geo::algorithm::convexhull::ConvexHull

pub trait ConvexHull<T> {
    fn convex_hull(&self) -> Polygon<T>
    where
        T: Float
; }

Required methods

fn convex_hull(&self) -> Polygon<T> where
    T: Float

Returns the convex hull of a Polygon. The hull is always oriented counter-clockwise.

This implementation uses the QuickHull algorithm, based on Barber, C. Bradford; Dobkin, David P.; Huhdanpaa, Hannu (1 December 1996) Original paper here: http://www.cs.princeton.edu/~dpd/Papers/BarberDobkinHuhdanpaa.pdf

Examples

use geo::{Point, LineString, Polygon};
use geo::convexhull::ConvexHull;
// an L shape
let coords = vec![(0.0, 0.0), (4.0, 0.0), (4.0, 1.0), (1.0, 1.0), (1.0, 4.0), (0.0, 4.0), (0.0, 0.0)];
let ls: LineString<_> = coords.iter().map(|e| Point::new(e.0, e.1)).collect();
let poly = Polygon::new(ls, vec![]);

// The correct convex hull coordinates
let hull_coords = vec![(4.0, 0.0), (4.0, 1.0), (1.0, 4.0), (0.0, 4.0), (0.0, 0.0), (4.0, 0.0)];
let correct_hull: LineString<_> = hull_coords.iter().map(|e| Point::new(e.0, e.1)).collect();

let res = poly.convex_hull();
assert_eq!(res.exterior(), &correct_hull);
Loading content...

Implementors

impl<T> ConvexHull<T> for LineString<T> where
    T: Float
[src]

impl<T> ConvexHull<T> for MultiLineString<T> where
    T: Float
[src]

impl<T> ConvexHull<T> for MultiPoint<T> where
    T: Float
[src]

impl<T> ConvexHull<T> for MultiPolygon<T> where
    T: Float
[src]

impl<T> ConvexHull<T> for Polygon<T> where
    T: Float
[src]

Loading content...