diff --git a/src/coordinate_systems/kartesian/external_traits.rs b/src/coordinate_systems/kartesian/external_traits.rs index 9db8a3f..5ef24dc 100644 --- a/src/coordinate_systems/kartesian/external_traits.rs +++ b/src/coordinate_systems/kartesian/external_traits.rs @@ -149,3 +149,13 @@ impl Display for Velocity { Ok(()) } } + +impl Mul for Kartesian { + type Output = Kartesian; + fn mul(self, rhs: Self) -> Self::Output { + Kartesian { + x: self.x * rhs.x, + y: self.y * rhs.y, + } + } +} diff --git a/src/coordinate_systems/kartesian/traits.rs b/src/coordinate_systems/kartesian/traits.rs index de7b0ba..81b7a19 100644 --- a/src/coordinate_systems/kartesian/traits.rs +++ b/src/coordinate_systems/kartesian/traits.rs @@ -67,3 +67,29 @@ impl ToCoords for Kartesian { self } } + +pub trait IntMul { + type Output; + fn mul(self, rhs: T) -> Self::Output; +} + +macro_rules! impl_mul { + ($subtype:ident) => { + impl IntMul<$subtype> for Kartesian<$subtype> { + type Output = Kartesian<$subtype>; + fn mul(self, rhs: $subtype) -> Self::Output { + Kartesian { + x: self.x * rhs, + y: self.y * rhs, + } + } + } + }; +} + +impl_mul!(u8); +impl_mul!(u16); +impl_mul!(u32); +impl_mul!(u64); +impl_mul!(u128); +impl_mul!(usize);