Skip to main content

rscad_core/operations/extrude/
rotate.rs

1use crate::prelude_::*;
2
3/// Revolve a 2D profile about its local Y axis (OpenSCAD `rotate_extrude`).
4///
5/// The profile is expected to lie in the x ≥ 0 half-plane; profile-x is the
6/// radius from the revolution axis, profile-y the height along it. Regions
7/// with negative x produce undefined results, matching OpenSCAD.
8#[derive(Clone, Copy, Debug)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[cfg_attr(feature = "reflect", derive(bevy_reflect::Reflect))]
11pub struct RotateExtrude<O> {
12    pub object: O,
13    /// Sweep angle in degrees (360 = full revolution).
14    pub angle_degrees: f64,
15    pub convexity: f64,
16    pub fn_: usize,
17}
18
19impl<O: Object> RotateExtrude<O> {
20    pub fn new(object: O) -> Self {
21        Self {
22            object,
23            angle_degrees: 360.0,
24            convexity: 0.0,
25            fn_: 32,
26        }
27    }
28
29    pub fn with_angle<T: Number>(mut self, angle_degrees: T) -> Self {
30        self.angle_degrees = angle_degrees.to_f64();
31        self
32    }
33
34    pub fn with_convexity(mut self, convexity: f64) -> Self {
35        self.convexity = convexity;
36        self
37    }
38
39    pub fn with_fn(mut self, fn_: usize) -> Self {
40        self.fn_ = fn_;
41        self
42    }
43}
44
45pub trait RotateExtrudeObject: Object {
46    fn rotate_extrude(self) -> RotateExtrude<Self>
47    where
48        Self: Sized,
49    {
50        RotateExtrude::new(self)
51    }
52}
53
54impl<T: TwoDimensional> RotateExtrudeObject for T {}
55impl<T: TwoDimensional> ThreeDimensional for RotateExtrude<T> {}
56
57impl<T: TwoDimensional> Object for RotateExtrude<T> {}