use super::Empty;
#[doc(hidden)]
pub trait Translate: Sized {
fn inner_translate(self, position: (f32, f32)) -> Translation;
}
#[doc(hidden)]
pub trait TranslatePrevious: Sized {
fn inner_translate_previous(self, previous_position: (f32, f32)) -> PreviousTranslation;
}
#[doc(hidden)]
#[derive(Copy, Clone, Default)]
pub struct Translation {
pub(crate) x: f32,
pub(crate) y: f32,
}
impl Translation {
pub(crate) const fn new((x, y): (f32, f32)) -> Self {
Self { x, y }
}
}
impl Translate for Translation {
#[inline]
fn inner_translate(mut self, (x, y): (f32, f32)) -> Self {
self.x += x;
self.y += y;
self
}
}
impl Translate for Empty {
#[inline]
fn inner_translate(self, position: (f32, f32)) -> Translation {
Translation::new(position)
}
}
#[doc(hidden)]
#[derive(Copy, Clone, Default)]
pub struct PreviousTranslation {
pub(crate) previous_x: f32,
pub(crate) previous_y: f32,
}
impl PreviousTranslation {
#[inline]
pub(crate) const fn new((previous_x, previous_y): (f32, f32)) -> Self {
Self {
previous_x,
previous_y,
}
}
}
impl TranslatePrevious for PreviousTranslation {
#[inline]
fn inner_translate_previous(
mut self,
(previous_x, previous_y): (f32, f32),
) -> PreviousTranslation {
self.previous_x += previous_x;
self.previous_y += previous_y;
self
}
}
impl TranslatePrevious for Empty {
#[inline]
fn inner_translate_previous(self, previous_position: (f32, f32)) -> PreviousTranslation {
PreviousTranslation::new(previous_position)
}
}