Skip to main content

fey_math/
transform.rs

1use crate::{Affine2F, Angle, RadiansF, Vec2F};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct Transform {
6    pub position: Vec2F,
7    pub rotation: RadiansF,
8    pub scale: Vec2F,
9}
10
11impl Transform {
12    pub const IDENTITY: Self = Self {
13        position: Vec2F::ZERO,
14        rotation: RadiansF::ZERO,
15        scale: Vec2F::ONE,
16    };
17
18    pub fn new(
19        position: impl Into<Vec2F>,
20        rotation: impl Angle<f32>,
21        scale: impl Into<Vec2F>,
22    ) -> Self {
23        Self {
24            position: position.into(),
25            rotation: rotation.to_radians(),
26            scale: scale.into(),
27        }
28    }
29
30    #[inline]
31    pub fn matrix(&self) -> Affine2F {
32        Affine2F::trs(self.position, self.rotation, self.scale)
33    }
34}