use Context;
use math::{
multiply,
shear,
scale,
orient,
rotate_radians,
translate,
Matrix2d,
Vec2d,
Scalar,
};
use radians::Radians;
pub trait Transformed: Sized {
fn append_transform(self, transform: Matrix2d) -> Self;
fn prepend_transform(self, transform: Matrix2d) -> Self;
fn trans(self, x: Scalar, y: Scalar) -> Self;
#[inline(always)]
fn rot_deg(self, angle: Scalar) -> Self {
let pi: Scalar = Radians::_180();
self.rot_rad(angle * pi / 180.0)
}
fn rot_rad(self, angle: Scalar) -> Self;
fn orient(self, x: Scalar, y: Scalar) -> Self;
fn scale(self, sx: Scalar, sy: Scalar) -> Self;
#[inline(always)]
fn zoom(self, s: Scalar) -> Self {
self.scale(s, s)
}
#[inline(always)]
fn flip_v(self) -> Self {
self.scale(1.0, -1.0)
}
#[inline(always)]
fn flip_h(self) -> Self {
self.scale(-1.0, 1.0)
}
#[inline(always)]
fn flip_hv(self) -> Self {
self.scale(-1.0, -1.0)
}
fn shear(self, v: Vec2d) -> Self;
}
impl Transformed for Matrix2d {
#[inline(always)]
fn append_transform(self, transform: Matrix2d) -> Self {
multiply(self, transform)
}
#[inline(always)]
fn prepend_transform(self, transform: Matrix2d) -> Self {
multiply(transform, self)
}
#[inline(always)]
fn trans(self, x: Scalar, y: Scalar) -> Self {
let trans = translate([x, y]);
multiply(self, trans)
}
#[inline(always)]
fn rot_rad(self, angle: Scalar) -> Self {
let rot = rotate_radians(angle);
multiply(self, rot)
}
#[inline(always)]
fn orient(self, x: Scalar, y: Scalar) -> Self {
let orient = orient(x, y);
multiply(self, orient)
}
#[inline(always)]
fn scale(self, sx: Scalar, sy: Scalar) -> Self {
let scale = scale(sx, sy);
multiply(self, scale)
}
#[inline(always)]
fn shear(self, v: Vec2d) -> Self {
let shear = shear(v);
multiply(self, shear)
}
}
impl Transformed for Context {
#[inline(always)]
fn append_transform(mut self, transform: Matrix2d) -> Self {
self.transform = self.transform.append_transform(transform);
self
}
#[inline(always)]
fn prepend_transform(mut self, transform: Matrix2d) -> Self {
self.transform = self.transform.prepend_transform(transform);
self
}
#[inline(always)]
fn trans(mut self, x: Scalar, y: Scalar) -> Self {
self.transform = self.transform.trans(x, y);
self
}
#[inline(always)]
fn rot_rad(mut self, angle: Scalar) -> Self {
self.transform = self.transform.rot_rad(angle);
self
}
#[inline(always)]
fn orient(mut self, x: Scalar, y: Scalar) -> Self {
self.transform = self.transform.orient(x, y);
self
}
#[inline(always)]
fn scale(mut self, sx: Scalar, sy: Scalar) -> Self {
self.transform = self.transform.scale(sx, sy);
self
}
#[inline(always)]
fn shear(mut self, v: Vec2d) -> Self {
self.transform = self.transform.shear(v);
self
}
}