diff -r e09437844ad9 -r f248e1434c3b src/cube.rs --- a/src/cube.rs Fri Oct 18 19:52:06 2024 -0500 +++ b/src/cube.rs Sat Oct 19 10:46:13 2024 -0500 @@ -191,6 +191,23 @@ point : Point, } +impl OnCube { + /// Calculates both the logarithmic map and distance to another point + fn log_dist(&self, other : &Self) -> (::Tangent, f64) { + let mut best_len = f64::INFINITY; + let mut best_tan = Loc([0.0, 0.0]); + for path in self.face.paths(other.face) { + let tan = self.face.convert(&path, &other.point) - &self.point; + let len = tan.norm(L2); + if len < best_len { + best_tan = tan; + best_len = len; + } + } + (best_tan, best_len) + } +} + impl ManifoldPoint for OnCube { type Tangent = Point; @@ -209,17 +226,11 @@ } fn log(&self, other : &Self) -> Self::Tangent { - let mut best_len = f64::INFINITY; - let mut best_tan = Loc([0.0, 0.0]); - for path in self.face.paths(other.face) { - let tan = self.face.convert(&path, &other.point) - &self.point; - let len = tan.norm(L2); - if len < best_len { - best_tan = tan; - best_len = len; - } - } - best_tan + self.log_dist(other).0 + } + + fn dist_to(&self, other : &Self) -> f64 { + self.log_dist(other).1 } }