shape_core/traits/
mod.rs

1use crate::{Line, Point, Rectangle};
2use std::marker::PhantomData;
3
4mod convert;
5mod projection;
6#[cfg(feature = "rand")]
7mod random;
8#[cfg(feature = "wolfram-expr")]
9mod wolfram;
10
11/// The trait for 2D shapes.
12///
13/// # Arguments
14///
15/// * `a`:
16/// * `b`:
17/// * `c`:
18///
19/// returns: Triangle<T>
20///
21/// # Examples
22///
23/// ```
24/// # use shape_core::Triangle;
25/// ```
26pub trait Shape2D {
27    /// The value type of the shape.
28    type Value;
29    /// The value type of the shape.
30    type VertexIterator<'a>: Iterator<Item = Point<Self::Value>>
31    where
32        Self: 'a;
33    /// The value type of the shape.
34    type LineIterator<'a>: Iterator<Item = Line<Self::Value>>
35    where
36        Self: 'a;
37    /// Returns true if the shape is valid and in normal form.
38    fn is_valid(&self) -> bool;
39    /// Returns true if the shape successfully normalized.
40    fn normalize(&mut self) -> bool {
41        self.is_valid()
42    }
43    /// Returns the boundary of the shape.
44    fn boundary(&self) -> Rectangle<Self::Value>;
45    /// Returns the owned vertices of the shape.
46    ///
47    /// Notice that sample only works for non-linear shapes.
48    fn vertices<'a>(&'a self, sample: usize) -> Self::VertexIterator<'a>;
49    /// Returns the owned edges of the shape.
50    fn edges<'a>(&'a self, sample: usize) -> Self::LineIterator<'a>;
51}
52
53/// A placeholder iterator for missing trait bound
54#[derive(Debug, Clone, PartialEq, Eq, Hash)]
55#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56pub struct PlaceHolderNodeIterator<T> {
57    place_holder: PhantomData<T>,
58}
59
60/// A placeholder iterator for missing trait bound
61#[derive(Debug, Clone, PartialEq, Eq, Hash)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63pub struct PlaceHolderEdgeIterator<T> {
64    place_holder: PhantomData<T>,
65}
66impl<T> Iterator for PlaceHolderNodeIterator<T> {
67    type Item = Point<T>;
68
69    fn next(&mut self) -> Option<Self::Item> {
70        None
71    }
72}
73
74impl<T> Iterator for PlaceHolderEdgeIterator<T> {
75    type Item = Line<T>;
76
77    fn next(&mut self) -> Option<Self::Item> {
78        None
79    }
80}