--- a/src/cube.rs Mon Oct 21 08:44:23 2024 -0500 +++ b/src/cube.rs Mon Oct 21 10:02:57 2024 -0500 @@ -3,7 +3,7 @@ use alg_tools::loc::Loc; use alg_tools::norms::{Norm, L2}; -use crate::manifold::ManifoldPoint; +use crate::manifold::{ManifoldPoint, EmbeddedManifoldPoint}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Face {F1, F2, F3, F4, F5, F6} @@ -183,6 +183,19 @@ (Equal, Greater) => self.adjacent_faces()[3], } } + + /// Get embedded 3D coordinates + pub fn embedded_coords(&self, p : &Point) -> Loc<f64, 3> { + let &Loc([x, y]) = p; + Loc(match *self { + F1 => [x, y, 0.0], + F2 => [1.0, x, y], + F3 => [0.0, 1.0-x, y], + F4 => [x, 0.0, y], + F5 => [1.0 - x, 1.0, y], + F6 => [x, y, 1.0], + }) + } } #[derive(Clone, Debug, PartialEq)] @@ -192,6 +205,13 @@ } impl OnCube { + /// Creates a new point on the cube, given a face and face-relative coordinates + /// in [0, 1]^2 + pub fn new(face : Face, point : Point) -> Self { + assert!(face.is_in_face(&point)); + OnCube { face, point } + } + /// Calculates both the logarithmic map and distance to another point fn log_dist(&self, other : &Self) -> (<Self as ManifoldPoint>::Tangent, f64) { let mut best_len = f64::INFINITY; @@ -208,6 +228,16 @@ } } + +impl EmbeddedManifoldPoint for OnCube { + type EmbeddedCoords = Loc<f64, 3>; + + /// Get embedded 3D coordinates + fn embedded_coords(&self) -> Loc<f64, 3> { + self.face.embedded_coords(&self.point) + } +} + impl ManifoldPoint for OnCube { type Tangent = Point;