--- a/src/loc.rs Mon May 12 19:30:41 2025 -0500 +++ b/src/loc.rs Mon May 12 20:40:14 2025 -0500 @@ -437,10 +437,12 @@ /// Use [`nalgebra`] for larger vectors. #[inline] fn dot<I: Instance<Self>>(&self, other: I) -> F { - self.0 - .iter() - .zip(other.ref_instance().0.iter()) - .fold(F::ZERO, |m, (&v, &w)| m + v * w) + other.eval_ref_decompose(|r| { + self.0 + .iter() + .zip(r.0.iter()) + .fold(F::ZERO, |m, (&v, &w)| m + v * w) + }) } /// This implementation is not stabilised as it's meant to be used for very small vectors. @@ -451,12 +453,12 @@ } fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F { - self.iter() - .zip(other.ref_instance().iter()) - .fold(F::ZERO, |m, (&v, &w)| { + other.eval_ref_decompose(|r| { + self.iter().zip(r.iter()).fold(F::ZERO, |m, (&v, &w)| { let d = v - w; m + d * d }) + }) } #[inline] @@ -472,9 +474,10 @@ #[inline] fn dist2<I: Instance<Self>>(&self, other: I) -> F { // Optimisation for N==1 that avoids squaring and square rooting. - let otherr = other.ref_instance(); if N == 1 { - unsafe { *self.0.get_unchecked(0) - *otherr.0.get_unchecked(0) }.abs() + other.eval_ref_decompose(|r| { + unsafe { *self.0.get_unchecked(0) - *r.0.get_unchecked(0) }.abs() + }) } else { self.dist2_squared(other).sqrt() } @@ -631,9 +634,11 @@ impl<F: Float, const N: usize> Dist<F, L1> for Loc<N, F> { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: L1) -> F { - self.iter() - .zip(other.ref_instance().iter()) - .fold(F::ZERO, |m, (&v, &w)| m + (v - w).abs()) + other.eval_ref_decompose(|r| { + self.iter() + .zip(r.iter()) + .fold(F::ZERO, |m, (&v, &w)| m + (v - w).abs()) + }) } } @@ -657,9 +662,11 @@ impl<F: Float, const N: usize> Dist<F, Linfinity> for Loc<N, F> { #[inline] fn dist<I: Instance<Self>>(&self, other: I, _: Linfinity) -> F { - self.iter() - .zip(other.ref_instance().iter()) - .fold(F::ZERO, |m, (&v, &w)| m.max((v - w).abs())) + other.eval_ref_decompose(|r| { + self.iter() + .zip(r.iter()) + .fold(F::ZERO, |m, (&v, &w)| m.max((v - w).abs())) + }) } } @@ -702,7 +709,7 @@ type Codomain = F; fn apply<I: Instance<Loc<N, F>>>(&self, x: I) -> Self::Codomain { - x.eval(|x̃| self.dot(x̃)) + x.eval_decompose(|x̃| self.dot(x̃)) } }