Sketch exp

Fri, 18 Oct 2024 14:22:45 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 18 Oct 2024 14:22:45 -0500
changeset 3
ff4656da04af
parent 2
86e0228f38f8
child 4
e09437844ad9

Sketch exp

src/cube.rs file | annotate | diff | comparison | revisions
src/manifold.rs file | annotate | diff | comparison | revisions
--- 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 {
--- 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<f64, Output=Self::Tangent> + std::fmt::Debug;
 
     /// Exponential map
     fn exp(&self, tangent : &Self::Tangent) -> Self;

mercurial