rscad_core/transformations/
rotate.rs1use crate::prelude_::*;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[cfg_attr(feature = "reflect", derive(bevy_reflect::Reflect))]
6pub struct Rotate<T: Object> {
7 pub object: T,
8 pub rotation: DVec3,
9}
10
11impl<O: Object> Rotate<O> {
12 pub fn new<X: Number, Y: Number, Z: Number>(object: O, x: X, y: Y, z: Z) -> Self {
13 Self {
14 object,
15 rotation: DVec3::new(x.to_f64(), y.to_f64(), z.to_f64()),
16 }
17 }
18}
19
20pub trait RotateObject: Object {
21 fn rotate<T: Number>(self, x: T, y: T, z: T) -> Rotate<Self>
22 where
23 Self: Sized,
24 {
25 Rotate::new(self, x, y, z)
26 }
27 fn rotate_x<T: Number>(self, x: T) -> Rotate<Self>
28 where
29 Self: Sized,
30 {
31 Rotate::new(self, x, 0, 0)
32 }
33 fn rotate_y<T: Number>(self, y: T) -> Rotate<Self>
34 where
35 Self: Sized,
36 {
37 Rotate::new(self, 0, y, 0)
38 }
39 fn rotate_z<T: Number>(self, z: T) -> Rotate<Self>
40 where
41 Self: Sized,
42 {
43 Rotate::new(self, 0, 0, z)
44 }
45 fn rotate_xy<T: Number>(self, x: T, y: T) -> Rotate<Self>
46 where
47 Self: Sized,
48 {
49 Rotate::new(self, x, y, 0)
50 }
51 fn rotate_yz<T: Number>(self, y: T, z: T) -> Rotate<Self>
52 where
53 Self: Sized,
54 {
55 Rotate::new(self, 0, y, z)
56 }
57 fn rotate_xz<T: Number>(self, x: T, z: T) -> Rotate<Self>
58 where
59 Self: Sized,
60 {
61 Rotate::new(self, x, 0, z)
62 }
63}
64
65impl<T: Object> RotateObject for T {}
66
67impl<T: Object> Object for Rotate<T> {}