--- a/src/cube.rs Tue Oct 22 08:27:45 2024 -0500 +++ b/src/cube.rs Tue Oct 22 08:39:46 2024 -0500 @@ -1,3 +1,6 @@ +/*! +Implementation of the surface of the 3D cube as a [`ManifoldPoint`]. +*/ use serde_repr::*; use serde::Serialize; @@ -5,6 +8,7 @@ use alg_tools::norms::{Norm, L2}; use crate::manifold::{ManifoldPoint, EmbeddedManifoldPoint}; +/// All the difference faces of a [`OnCube`]. #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)] #[repr(u8)] pub enum Face {F1 = 1, F2 = 2, F3 = 3, F4 = 4, F5 = 5, F6 = 6} @@ -180,10 +184,17 @@ } } + /// Indicates whether an unfolded point `p` is on this face, i.e., + /// has coordinates in [0,1]². pub fn is_in_face(&self, p: &Point) -> bool { p.iter().map(|t| t.abs()).all(|t| 0.0 <= t && t <= 1.0) } + /// Given an unfolded point `p`, possibly outside this face, finds + /// the edge, presented by an adjacent face, in whose direction it is. + /// + /// **TODO:** this does not correctly handle corners, i.e., when the point is not in + /// the direction of an adjacent face. pub fn find_crossing(&self, p : &Point) -> Face { let &Loc([x, y]) = p; use std::cmp::Ordering::*; @@ -246,6 +257,7 @@ (best_tan, best_len) } + /// Returns the face of this point. pub fn face(&self) -> Face { self.face }