rust/integral-geometry/src/lib.rs
changeset 14109 f483f844da98
parent 14102 5d42204ac35e
child 14113 32a34bf70f65
equal deleted inserted replaced
14108:26154fe42974 14109:f483f844da98
   168             }
   168             }
   169         }
   169         }
   170     };
   170     };
   171 }
   171 }
   172 
   172 
       
   173 macro_rules! scalar_bin_op_impl {
       
   174     ($($op: tt)::+, $name: tt) => {
       
   175         impl $($op)::+<i32> for Point {
       
   176             type Output = Self;
       
   177 
       
   178             #[inline]
       
   179             fn $name(self, rhs: i32) -> Self::Output {
       
   180                 Self::new(self.x.$name(rhs), self.y.$name(rhs))
       
   181             }
       
   182         }
       
   183     };
       
   184 }
       
   185 
   173 macro_rules! bin_assign_op_impl {
   186 macro_rules! bin_assign_op_impl {
   174     ($op: ty, $name: tt) => {
   187     ($op: ty, $name: tt) => {
   175         impl $op for Point {
   188         impl $op for Point {
   176             #[inline]
   189             #[inline]
   177             fn $name(&mut self, rhs: Self) {
   190             fn $name(&mut self, rhs: Self) {
   184 
   197 
   185 bin_op_impl!(Add, add);
   198 bin_op_impl!(Add, add);
   186 bin_op_impl!(Sub, sub);
   199 bin_op_impl!(Sub, sub);
   187 bin_op_impl!(Mul, mul);
   200 bin_op_impl!(Mul, mul);
   188 bin_op_impl!(Div, div);
   201 bin_op_impl!(Div, div);
       
   202 scalar_bin_op_impl!(Mul, mul);
       
   203 scalar_bin_op_impl!(Div, div);
   189 bin_assign_op_impl!(AddAssign, add_assign);
   204 bin_assign_op_impl!(AddAssign, add_assign);
   190 bin_assign_op_impl!(SubAssign, sub_assign);
   205 bin_assign_op_impl!(SubAssign, sub_assign);
   191 bin_assign_op_impl!(MulAssign, mul_assign);
   206 bin_assign_op_impl!(MulAssign, mul_assign);
   192 bin_assign_op_impl!(DivAssign, div_assign);
   207 bin_assign_op_impl!(DivAssign, div_assign);
   193 
   208 
   297         Self::new(Point::zero(), Point::zero())
   312         Self::new(Point::zero(), Point::zero())
   298     }
   313     }
   299 
   314 
   300     #[inline]
   315     #[inline]
   301     pub fn center(&self) -> Point {
   316     pub fn center(&self) -> Point {
   302         (self.start + self.end) / Point::new(2, 2) // point div point, really?
   317         (self.start + self.end) / 2
   303     }
   318     }
   304 }
   319 }
   305 
   320 
   306 impl IntoIterator for Line {
   321 impl IntoIterator for Line {
   307     type Item = Point;
   322     type Item = Point;