# HG changeset patch # User Tuomo Valkonen # Date 1729279365 18000 # Node ID ff4656da04afc5df07a21f7e6c402564bd714c3b # Parent 86e0228f38f86c351481fc3075452a3c39598137 Sketch exp diff -r 86e0228f38f8 -r ff4656da04af src/cube.rs --- a/src/cube.rs Fri Oct 18 13:51:51 2024 -0500 +++ b/src/cube.rs Fri Oct 18 14:22:45 2024 -0500 @@ -13,6 +13,7 @@ pub type AdjacentFaces = [Face; 4]; +#[derive(Clone, Debug)] pub enum Path { Direct { destination : Face }, Indirect { destination : Face, intermediate : Face }, @@ -53,15 +54,16 @@ impl Face { - /// Returns an array of the four faces adjacent to `self`. + /// Returns an array of the four faces adjacent to `self` in the + /// order [left, right, down, up] in the `self`-relative unfolding. pub fn adjacent_faces(&self) -> AdjacentFaces { match *self { - F1 => [F2, F3, F4, F5], - F2 => [F1, F4, F5, F6], - F3 => [F1, F4, F5, F6], - F4 => [F1, F2, F3, F6], - F5 => [F1, F2, F3, F6], - F6 => [F2, F3, F4, F5], + F1 => [F3, F2, F4, F5], + F2 => [F4, F5, F1, F6], + F3 => [F5, F4, F1, F6], + F4 => [F3, F2, F1, F6], + F5 => [F2, F3, F1, F6], + F6 => [F3, F2, F4, F5], } } @@ -71,7 +73,7 @@ F1 => F6, F2 => F3, F3 => F2, - F4 => F6, + F4 => F5, F5 => F4, F6 => F1, } @@ -136,16 +138,18 @@ /// Converts a point behind a path to the coordinate system of `self`. pub fn convert(&self, path : &Path, p: &Point) -> Point { use Path::*; + //dbg!(*self, path); match path { &Direct{ destination : d} => self.convert_adjacent(d, p), &Indirect{ destination : d, intermediate : i } - => {dbg!((d,i)); dbg!(self.convert_adjacent(i, dbg!(&i.convert_adjacent(d, p).unwrap())))} + => {self.convert_adjacent(i, &i.convert_adjacent(d, p).unwrap())} }.unwrap() } /// Returns an iterator over all the paths from `self` to `other`. fn paths(&self, other : Face) -> PathIter { + //dbg!(self, other); if self.opposing_face() == other { PathIter::Indirect { intermediate : self.adjacent_faces(), @@ -156,6 +160,29 @@ PathIter::Direct(other) } } + + pub fn is_in_face(&self, p: &Point) -> bool { + p.iter().map(|t| t.abs()).all(|t| 0.0 <= t && t <= 1.0) + } + + pub fn find_crossing(&self, p : &Point) -> Face { + let &Loc([x, y]) = p; + use std::cmp::Ordering::*; + let crossing = |t| match (0.0 <= t, t<=1.0) { + (false, _) => Less, + (_, false) => Greater, + _ => Equal, + }; + + // TODO: how to properly handle corners? Just throw an error? + match (crossing(x), crossing(y)) { + (Equal, Equal) => *self, + (Less, _) => self.adjacent_faces()[0], + (Greater, _) => self.adjacent_faces()[1], + (Equal, Less) => self.adjacent_faces()[2], + (Equal, Greater) => self.adjacent_faces()[3], + } + } } #[derive(Clone, Debug, PartialEq)] @@ -168,7 +195,17 @@ type Tangent = Point; fn exp(&self, tangent : &Self::Tangent) -> Self { - unimplemented!(); + let mut face = self.face; + let mut point = self.point + tangent; + loop { + let next_face = face.find_crossing(&point); + if next_face == face { + break + } + point = next_face.convert_adjacent(face, &point).unwrap(); + face = next_face; + } + OnCube { face, point } } fn log(&self, other : &Self) -> Self::Tangent { diff -r 86e0228f38f8 -r ff4656da04af src/manifold.rs --- a/src/manifold.rs Fri Oct 18 13:51:51 2024 -0500 +++ b/src/manifold.rs Fri Oct 18 14:22:45 2024 -0500 @@ -2,7 +2,7 @@ /// A point on a manifold pub trait ManifoldPoint : Clone + PartialEq { // Type of tangent factors - type Tangent; + type Tangent : Euclidean + std::fmt::Debug; /// Exponential map fn exp(&self, tangent : &Self::Tangent) -> Self;