Skip to main content

rscad_core/operations/extrude/
linear.rs

1use crate::prelude_::*;
2#[derive(Clone, Copy, Debug)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[cfg_attr(feature = "reflect", derive(bevy_reflect::Reflect))]
5pub struct LinearExtrude<O> {
6    pub object: O,
7    pub height: f64,
8    pub convexity: f64,
9    pub twist: f64,
10    pub slices: usize,
11    pub scale: f64,
12    pub fn_: f64,
13}
14
15impl<O: Object> LinearExtrude<O> {
16    pub fn new(object: O) -> Self {
17        Self {
18            object,
19            height: 0.0,
20            convexity: 0.0,
21            twist: 0.0,
22            slices: 0,
23            scale: 1.0,
24            fn_: 0.0,
25        }
26    }
27
28    pub fn with_height<T: Number>(mut self, height: T) -> Self {
29        self.height = height.to_f64();
30        self
31    }
32
33    pub fn with_convexity(mut self, convexity: f64) -> Self {
34        self.convexity = convexity;
35        self
36    }
37
38    pub fn with_twist(mut self, twist: impl Number) -> Self {
39        self.twist = twist.to_f64();
40        self
41    }
42
43    pub fn with_slices(mut self, slices: usize) -> Self {
44        self.slices = slices;
45        self
46    }
47
48    pub fn with_scale(mut self, scale: impl Number) -> Self {
49        self.scale = scale.to_f64();
50        self
51    }
52
53    pub fn with_fn(mut self, fn_: f64) -> Self {
54        self.fn_ = fn_;
55        self
56    }
57}
58
59pub trait LinearExtrudeObject: Object {
60    fn linear_extrude<T: Number>(self, height: T) -> LinearExtrude<Self>
61    where
62        Self: Sized,
63    {
64        LinearExtrude::new(self).with_height(height)
65    }
66}
67
68impl<T: TwoDimensional> LinearExtrudeObject for T {}
69impl<T: TwoDimensional> ThreeDimensional for LinearExtrude<T> {}
70
71impl<T: TwoDimensional> Object for LinearExtrude<T> {}