added multiplication for Kartesians
some part of it had to be an new trait
Dieser Commit ist enthalten in:
Ursprung
5b16d269b3
Commit
b9584d5597
|
@ -149,3 +149,13 @@ impl<T: Integer + Display + Unsigned + Copy> Display for Velocity<T> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Integer + Mul> Mul for Kartesian<T> {
|
||||
type Output = Kartesian<T>;
|
||||
fn mul(self, rhs: Self) -> Self::Output {
|
||||
Kartesian {
|
||||
x: self.x * rhs.x,
|
||||
y: self.y * rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,3 +67,29 @@ impl ToCoords for Kartesian<usize> {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntMul<T: Integer> {
|
||||
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);
|
||||
|
|
Laden…
In neuem Issue referenzieren