# HG changeset patch # User alfadur # Date 1541176667 -10800 # Node ID f483f844da988d2dc1dfff80ebbf9ea5997b89a7 # Parent 26154fe429742e1a29cf8e8b16421dc8300d8fa7 component-wise division is actually useful sometimes diff -r 26154fe42974 -r f483f844da98 rust/integral-geometry/src/lib.rs --- a/rust/integral-geometry/src/lib.rs Fri Nov 02 17:29:27 2018 +0100 +++ b/rust/integral-geometry/src/lib.rs Fri Nov 02 19:37:47 2018 +0300 @@ -170,6 +170,19 @@ }; } +macro_rules! scalar_bin_op_impl { + ($($op: tt)::+, $name: tt) => { + impl $($op)::+ for Point { + type Output = Self; + + #[inline] + fn $name(self, rhs: i32) -> Self::Output { + Self::new(self.x.$name(rhs), self.y.$name(rhs)) + } + } + }; +} + macro_rules! bin_assign_op_impl { ($op: ty, $name: tt) => { impl $op for Point { @@ -186,6 +199,8 @@ bin_op_impl!(Sub, sub); bin_op_impl!(Mul, mul); bin_op_impl!(Div, div); +scalar_bin_op_impl!(Mul, mul); +scalar_bin_op_impl!(Div, div); bin_assign_op_impl!(AddAssign, add_assign); bin_assign_op_impl!(SubAssign, sub_assign); bin_assign_op_impl!(MulAssign, mul_assign); @@ -299,7 +314,7 @@ #[inline] pub fn center(&self) -> Point { - (self.start + self.end) / Point::new(2, 2) // point div point, really? + (self.start + self.end) / 2 } }