use super::scalar::lerp_scalar;
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct Transform2D {
translate_x: f32,
translate_y: f32,
scale_x: f32,
scale_y: f32,
rotation: f32,
}
impl Transform2D {
#[must_use]
pub const fn new(
translate_x: f32,
translate_y: f32,
scale_x: f32,
scale_y: f32,
rotation: f32,
) -> Self {
Self {
translate_x,
translate_y,
scale_x,
scale_y,
rotation,
}
}
#[must_use]
pub const fn translate_x(&self) -> f32 {
self.translate_x
}
#[must_use]
pub const fn translate_y(&self) -> f32 {
self.translate_y
}
#[must_use]
pub const fn scale_x(&self) -> f32 {
self.scale_x
}
#[must_use]
pub const fn scale_y(&self) -> f32 {
self.scale_y
}
#[must_use]
pub const fn rotation(&self) -> f32 {
self.rotation
}
}
#[must_use]
pub const fn interp_transform(from: Transform2D, to: Transform2D, mix: f32) -> Transform2D {
Transform2D::new(
lerp_scalar(from.translate_x, to.translate_x, mix),
lerp_scalar(from.translate_y, to.translate_y, mix),
lerp_scalar(from.scale_x, to.scale_x, mix),
lerp_scalar(from.scale_y, to.scale_y, mix),
lerp_scalar(from.rotation, to.rotation, mix),
)
}