component-wise division is actually useful sometimes
authoralfadur
Fri, 02 Nov 2018 19:37:47 +0300
changeset 14109 f483f844da98
parent 14108 26154fe42974
child 14110 30565866db82
component-wise division is actually useful sometimes
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)::+<i32> 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
     }
 }