clay_core/shape/
bound.rs

1use crate::{
2    prelude::*,
3    shape::*,
4};
5
6
7/// Bounding shape that contains the whole object inside.
8pub trait Bound: Pack + Instance<BoundClass> {}
9
10/// Device interface for bound.
11pub enum BoundClass {}
12impl Class for BoundClass {
13    fn name() -> String {
14        "bound".to_string()
15    }
16    fn methods() -> Vec<String> {
17        vec!["bound".to_string()]
18    }
19}
20
21/// The shape that could be put inside the specified bound.
22pub trait Bounded<B: Bound> {
23    /// Returns bounding shape instance.
24    ///
25    /// If the shape is borderless and doesn't fit into any bounding shape
26    /// then `None` should be returned.
27    fn bound(&self) -> Option<B>;
28}
29
30impl<T: Bound + Shape + Clone> Bounded<T> for T {
31    fn bound(&self) -> Option<T> {
32        Some(self.clone())
33    }
34}