shape_convex/convex2d/
mod.rs

1use shape_core::{Point, PointSet, Polygon, Real};
2use std::cmp::Ordering::Equal;
3use std::collections::BTreeSet;
4use std::fmt::Debug;
5use std::ops::AddAssign;
6
7/// A convex hull which can't delete points dynamically
8///
9/// # Notice
10///
11/// It can merge with another convex hull, but it can't delete points inside
12#[derive(Debug)]
13pub struct FastConvexHull<T> {
14    bounds: Vec<Point<T>>,
15    inners: Vec<Point<T>>,
16}
17
18
19/// A convex hull which delete points dynamically, internally with balance tree
20#[derive(Debug)]
21pub struct ConvexHull<T> {
22    bounds: BTreeSet<Point<T>>,
23    inners: BTreeSet<Point<T>>,
24}
25
26mod solver;
27
28impl<T> FastConvexHull<T> {
29    /// Clear inner points in the convex2d hull
30    pub fn clear(&mut self) {
31        self.inners.clear();
32    }
33    pub fn bound_points(&self) -> impl Iterator<Item=Point<&T>> {
34        self.bounds.iter().map(|v| v.ref_inner())
35    }
36    pub fn inner_points(&self) -> impl Iterator<Item=Point<&T>> {
37        self.inners.iter().map(|v| v.ref_inner())
38    }
39    pub fn as_polygon(&self) -> Polygon<T> where T: Clone {
40        Polygon {
41            points_set: PointSet { points: self.bounds.clone() },
42        }
43    }
44}