pub trait ConvexHull<'a, T> {
    type Scalar: GeoNum;

    // Required method
    fn convex_hull(&'a self) -> Polygon<Self::Scalar>;
}
Expand description

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::{line_string, polygon};
use geo::ConvexHull;

// an L shape
let poly = polygon![
    (x: 0.0, y: 0.0),
    (x: 4.0, y: 0.0),
    (x: 4.0, y: 1.0),
    (x: 1.0, y: 1.0),
    (x: 1.0, y: 4.0),
    (x: 0.0, y: 4.0),
    (x: 0.0, y: 0.0),
];

// The correct convex hull coordinates
let correct_hull = line_string![
    (x: 4.0, y: 0.0),
    (x: 4.0, y: 1.0),
    (x: 1.0, y: 4.0),
    (x: 0.0, y: 4.0),
    (x: 0.0, y: 0.0),
    (x: 4.0, y: 0.0),
];

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

Required Associated Types§

Required Methods§

source

fn convex_hull(&'a self) -> Polygon<Self::Scalar>

Implementors§

source§

impl<'a, T, G> ConvexHull<'a, T> for G
where T: GeoNum, G: CoordsIter<Scalar = T>,

§

type Scalar = T