use std::ops::{Add, Mul, Sub}; use crate::{ToVector2D, Vector2D}; /// Marker struct for a vector used as a translation or velocity. #[derive(Debug, Clone, Copy, PartialEq, Hash)] pub struct Offset; /// A two-dimensional vector representing an offset. pub type Offset2D = Vector2D; impl Add for Offset2D where Rhs: ToOffset2D, T: Add, { type Output = Offset2D; fn add(self, rhs: Rhs) -> Self::Output { self.add_components(rhs) } } impl Sub for Offset2D where Rhs: ToOffset2D, T: Sub, { type Output = Offset2D; fn sub(self, rhs: Rhs) -> Self::Output { self.sub_components(rhs) } } impl Mul for Offset2D where T: Copy + Mul, { type Output = Offset2D; fn mul(self, rhs: T) -> Self::Output { Offset2D::new(self.x * rhs, self.y * rhs) } } /// Trait alias for [ToVector2D] where `Kind` is [Offset]. pub trait ToOffset2D: ToVector2D {} impl> ToOffset2D for V {}