use super::*;
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Transform2d {
pub pos: Vec2,
pub rot: Rotor2d,
pub scale: Vec2,
}
impl Transformation2d for Transform2d {
fn apply_origin(&self) -> Vec2 {
self.pos
}
fn apply(&self, point: Vec2) -> Vec2 {
self.rot * (self.scale * point) + self.pos
}
fn unapply(&self, point: Vec2) -> Vec2 {
self.rot.inverse() * (point - self.pos) / self.scale
}
}
impl Invertible for Transform2d {
fn inverse(&self) -> Self {
Self {
pos: self.unapply(Vec2::ZERO),
rot: self.rot.inverse(),
scale: 1.0 / self.scale,
}
}
}
impl Composable for Transform2d {
fn compose(&self, other: &Self) -> Self {
Self {
pos: self.apply(other.pos),
rot: self.rot * other.rot,
scale: self.scale * other.scale,
}
}
}