1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
macro_rules! impl_negate_self { ($type: ty, $($field:tt),+) => { impl std::ops::Neg for $type { type Output = Self; fn neg(self) -> Self { let mut result = Self::default(); $(result.$field = -self.$field;)+ result } } } } macro_rules! impl_add_self { ($type: ty, $($field:tt),+) => { impl std::ops::Add for $type { type Output = Self; fn add(self, rhs: Self) -> Self { let mut result = Self::default(); $(result.$field = self.$field + rhs.$field;)+ result } } impl std::ops::AddAssign for $type { fn add_assign(&mut self, rhs: Self) { $(self.$field += rhs.$field;)+ } } } } macro_rules! impl_sub_self { ($type: ty, $($field:tt),+) => { impl std::ops::Sub for $type { type Output = Self; fn sub(self, rhs: $type) -> Self { let mut result = Self::default(); $(result.$field = self.$field - rhs.$field;)+ result } } impl std::ops::SubAssign for $type { fn sub_assign(&mut self, rhs: $type) { $(self.$field -= rhs.$field;)+ } } } } macro_rules! impl_mul_scalar { ($type: ty, $($field:tt),+) => { impl std::ops::Mul<crate::Scalar> for $type { type Output = Self; fn mul(self, rhs: crate::Scalar) -> Self { let mut result = Self::default(); $(result.$field = self.$field * rhs;)+ result } } impl std::ops::MulAssign<crate::Scalar> for $type { fn mul_assign(&mut self, rhs: crate::Scalar) { $(self.$field *= rhs;)+ } } } } macro_rules! impl_div_scalar { ($type: ty, $($field:tt),+) => { impl std::ops::Div<crate::Scalar> for $type { type Output = Self; fn div(self, rhs: crate::Scalar) -> Self::Output { let mut result = Self::default(); $(result.$field = self.$field / rhs;)+ result } } impl std::ops::DivAssign<crate::Scalar> for $type { fn div_assign(&mut self, rhs: crate::Scalar) { $(self.$field /= rhs;)+ } } } } macro_rules! impl_approx { ($type: ty, $($field:tt),+) => { impl approx::AbsDiffEq for $type { type Epsilon = crate::Scalar; fn default_epsilon() -> Self::Epsilon { Self::Epsilon::default_epsilon() } fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { let mut result = true; $( result &= Self::Epsilon::abs_diff_eq(&self.$field, &other.$field, epsilon); )+ result } } impl approx::RelativeEq for $type { fn default_max_relative() -> Self::Epsilon { Self::Epsilon::default_max_relative() } fn relative_eq(&self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon) -> bool { let mut result = true; $( result &= Self::Epsilon::relative_eq(&self.$field, &other.$field, epsilon, max_relative); )+ result } } impl approx::UlpsEq for $type { fn default_max_ulps() -> u32 { Self::Epsilon::default_max_ulps() } fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { let mut result = true; $( result &= Self::Epsilon::ulps_eq(&self.$field, &other.$field, epsilon, max_ulps); )+ result } } }; }