1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use bevy_math::Vec3;
use bevy_property::Properties;
use std::{
    fmt,
    ops::{Deref, DerefMut},
};

#[derive(Debug, PartialEq, Clone, Copy, Properties)]
pub struct NonUniformScale(pub Vec3);

impl NonUniformScale {
    pub fn new(x: f32, y: f32, z: f32) -> Self {
        Self(Vec3::new(x, y, z))
    }
}

impl Default for NonUniformScale {
    fn default() -> Self {
        NonUniformScale(Vec3::new(1.0, 1.0, 1.0))
    }
}

impl From<Vec3> for NonUniformScale {
    fn from(scale: Vec3) -> Self {
        Self(scale)
    }
}

impl From<&Vec3> for NonUniformScale {
    fn from(scale: &Vec3) -> Self {
        Self(*scale)
    }
}

impl From<&mut Vec3> for NonUniformScale {
    fn from(scale: &mut Vec3) -> Self {
        Self(*scale)
    }
}

impl fmt::Display for NonUniformScale {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let (x, y, z) = self.0.into();
        write!(f, "NonUniformScale({}, {}, {})", x, y, z)
    }
}

impl Deref for NonUniformScale {
    type Target = Vec3;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl DerefMut for NonUniformScale {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}