1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::{Line, Point, Rectangle};
use std::marker::PhantomData;

mod convert;
mod projection;
#[cfg(feature = "rand")]
mod random;
#[cfg(feature = "wolfram-expr")]
mod wolfram;

/// The trait for 2D shapes.
///
/// # Arguments
///
/// * `a`:
/// * `b`:
/// * `c`:
///
/// returns: Triangle<T>
///
/// # Examples
///
/// ```
/// # use shape_core::Triangle;
/// ```
pub trait Shape2D {
    /// The value type of the shape.
    type Value;
    /// The value type of the shape.
    type VertexIterator<'a>: Iterator<Item = Point<Self::Value>>
    where
        Self: 'a;
    /// The value type of the shape.
    type LineIterator<'a>: Iterator<Item = Line<Self::Value>>
    where
        Self: 'a;
    /// Returns true if the shape is valid and in normal form.
    fn is_valid(&self) -> bool;
    /// Returns true if the shape successfully normalized.
    fn normalize(&mut self) -> bool {
        self.is_valid()
    }
    /// Returns the boundary of the shape.
    fn boundary(&self) -> Rectangle<Self::Value>;
    /// Returns the owned vertices of the shape.
    ///
    /// Notice that sample only works for non-linear shapes.
    fn vertices<'a>(&'a self, sample: usize) -> Self::VertexIterator<'a>;
    /// Returns the owned edges of the shape.
    fn edges<'a>(&'a self, sample: usize) -> Self::LineIterator<'a>;
}

/// A placeholder iterator for missing trait bound
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PlaceHolderNodeIterator<T> {
    place_holder: PhantomData<T>,
}

/// A placeholder iterator for missing trait bound
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PlaceHolderEdgeIterator<T> {
    place_holder: PhantomData<T>,
}
impl<T> Iterator for PlaceHolderNodeIterator<T> {
    type Item = Point<T>;

    fn next(&mut self) -> Option<Self::Item> {
        None
    }
}

impl<T> Iterator for PlaceHolderEdgeIterator<T> {
    type Item = Line<T>;

    fn next(&mut self) -> Option<Self::Item> {
        None
    }
}