use cgmath::Matrix3;
use cgmath::prelude::*;
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct AffineTransform<T>(Matrix3<T>);
impl Default for AffineTransform<f32> {
fn default() -> Self {
AffineTransform(Matrix3::identity())
}
}
impl AffineTransform<f32> {
pub fn new() -> Self {
AffineTransform::default()
}
pub fn translate(mut self, x: f32, y: f32) -> Self {
self.0.z.x += x;
self.0.z.y += y;
self
}
pub fn scale(self, x: f32, y: f32) -> Self {
AffineTransform(Matrix3::from_diagonal([x, y, 1.].into()) * self.0)
}
pub fn wgpu_mat3x3(&self) -> [[f32; 4]; 3] {
[
[self.0.x.x, self.0.x.y, self.0.x.z, 0.],
[self.0.y.x, self.0.y.y, self.0.y.z, 0.],
[self.0.z.x, self.0.z.y, self.0.z.z, 0.],
]
}
}