use super::Fixed;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Transform {
pub m00: Fixed,
pub m01: Fixed,
pub tx: Fixed,
pub m10: Fixed,
pub m11: Fixed,
pub ty: Fixed,
}
impl Transform {
pub const IDENTITY: Self = Self {
m00: Fixed::ONE,
m01: Fixed::ZERO,
tx: Fixed::ZERO,
m10: Fixed::ZERO,
m11: Fixed::ONE,
ty: Fixed::ZERO,
};
pub const fn translate(tx: Fixed, ty: Fixed) -> Self {
Self {
m00: Fixed::ONE,
m01: Fixed::ZERO,
tx,
m10: Fixed::ZERO,
m11: Fixed::ONE,
ty,
}
}
#[inline]
pub fn is_identity(&self) -> bool {
*self == Self::IDENTITY
}
}
impl Default for Transform {
fn default() -> Self {
Self::IDENTITY
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn identity_is_default() {
assert_eq!(Transform::default(), Transform::IDENTITY);
}
#[test]
fn translate_preserves_identity_classification() {
let t = Transform::translate(Fixed::ZERO, Fixed::ZERO);
assert!(t.is_identity());
}
#[test]
fn non_zero_translate_breaks_identity() {
let t = Transform::translate(Fixed::from_int(1), Fixed::ZERO);
assert!(!t.is_identity());
}
}