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

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

Required Methods

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

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);

Implementors