use vecmath::{mat2x3_id, Matrix2x3, row_mat2x3_mul};
pub type Matrix2d = Matrix2x3<f64>;
#[derive(Clone, Debug)]
pub struct Transform2D(pub Matrix2d);
impl Transform2D {
#[inline]
pub fn multiply(self, other: Transform2D) -> Transform2D {
let (Transform2D(m), Transform2D(n)) = (self, other);
Transform2D(row_mat2x3_mul(m, n))
}
}
#[inline]
pub fn identity() -> Transform2D {
Transform2D(mat2x3_id())
}
#[inline]
pub fn matrix(a: f64, b: f64, c: f64, d: f64, x: f64, y: f64) -> Transform2D {
Transform2D([ [a, b, x], [c, d, y] ])
}
#[inline]
pub fn rotation(t: f64) -> Transform2D {
Transform2D([ [t.cos(), -t.sin(), 0.0], [t.sin(), t.cos(), 0.0] ])
}
#[inline]
pub fn translation(x: f64, y: f64) -> Transform2D {
matrix(1.0, 0.0, 0.0, 1.0, x, y)
}
#[inline]
pub fn scale(s: f64) -> Transform2D {
matrix(s, 0.0, 0.0, s, 0.0, 0.0)
}
#[inline]
pub fn scale_x(s: f64) -> Transform2D {
matrix(s, 0.0, 0.0, 1.0, 0.0, 0.0)
}
#[inline]
pub fn scale_y(s: f64) -> Transform2D {
matrix(1.0, 0.0, 0.0, s, 0.0, 0.0)
}