|
1 /*! |
|
2 Implementation of the surface of the 3D cube as a [`ManifoldPoint`]. |
|
3 */ |
1 |
4 |
2 use serde_repr::*; |
5 use serde_repr::*; |
3 use serde::Serialize; |
6 use serde::Serialize; |
4 use alg_tools::loc::Loc; |
7 use alg_tools::loc::Loc; |
5 use alg_tools::norms::{Norm, L2}; |
8 use alg_tools::norms::{Norm, L2}; |
6 use crate::manifold::{ManifoldPoint, EmbeddedManifoldPoint}; |
9 use crate::manifold::{ManifoldPoint, EmbeddedManifoldPoint}; |
7 |
10 |
|
11 /// All the difference faces of a [`OnCube`]. |
8 #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)] |
12 #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)] |
9 #[repr(u8)] |
13 #[repr(u8)] |
10 pub enum Face {F1 = 1, F2 = 2, F3 = 3, F4 = 4, F5 = 5, F6 = 6} |
14 pub enum Face {F1 = 1, F2 = 2, F3 = 3, F4 = 4, F5 = 5, F6 = 6} |
11 use Face::*; |
15 use Face::*; |
12 |
16 |
178 } else { |
182 } else { |
179 PathIter::Direct(other) |
183 PathIter::Direct(other) |
180 } |
184 } |
181 } |
185 } |
182 |
186 |
|
187 /// Indicates whether an unfolded point `p` is on this face, i.e., |
|
188 /// has coordinates in [0,1]². |
183 pub fn is_in_face(&self, p: &Point) -> bool { |
189 pub fn is_in_face(&self, p: &Point) -> bool { |
184 p.iter().map(|t| t.abs()).all(|t| 0.0 <= t && t <= 1.0) |
190 p.iter().map(|t| t.abs()).all(|t| 0.0 <= t && t <= 1.0) |
185 } |
191 } |
186 |
192 |
|
193 /// Given an unfolded point `p`, possibly outside this face, finds |
|
194 /// the edge, presented by an adjacent face, in whose direction it is. |
|
195 /// |
|
196 /// **TODO:** this does not correctly handle corners, i.e., when the point is not in |
|
197 /// the direction of an adjacent face. |
187 pub fn find_crossing(&self, p : &Point) -> Face { |
198 pub fn find_crossing(&self, p : &Point) -> Face { |
188 let &Loc([x, y]) = p; |
199 let &Loc([x, y]) = p; |
189 use std::cmp::Ordering::*; |
200 use std::cmp::Ordering::*; |
190 let crossing = |t| match (0.0 <= t, t<=1.0) { |
201 let crossing = |t| match (0.0 <= t, t<=1.0) { |
191 (false, _) => Less, |
202 (false, _) => Less, |