1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4use use_point::Point2;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum HullAlgorithm {
9 MonotoneChain,
11 GiftWrapping,
13 QuickHull,
15}
16
17impl HullAlgorithm {
18 #[must_use]
20 pub const fn name(self) -> &'static str {
21 match self {
22 Self::MonotoneChain => "monotone-chain",
23 Self::GiftWrapping => "gift-wrapping",
24 Self::QuickHull => "quickhull",
25 }
26 }
27}
28
29#[derive(Debug, Clone, PartialEq)]
31pub struct ConvexHull2 {
32 points: Vec<Point2>,
33}
34
35impl ConvexHull2 {
36 #[must_use]
38 pub const fn new(points: Vec<Point2>) -> Self {
39 Self { points }
40 }
41
42 #[must_use]
44 pub fn points(&self) -> &[Point2] {
45 &self.points
46 }
47
48 #[must_use]
50 pub fn point_count(&self) -> usize {
51 self.points.len()
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::{ConvexHull2, HullAlgorithm};
58 use use_point::Point2;
59
60 #[test]
61 fn stores_hull_inputs() {
62 let hull = ConvexHull2::new(vec![Point2::origin(), Point2::new(1.0, 0.0)]);
63
64 assert_eq!(hull.point_count(), 2);
65 assert_eq!(hull.points()[1], Point2::new(1.0, 0.0));
66 assert_eq!(HullAlgorithm::MonotoneChain.name(), "monotone-chain");
67 }
68}