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