Tue, 22 Oct 2024 09:34:12 -0500
Fixes to find_crossing and exp
13 | 1 | /*! |
2 | Implementation of the surface of the 3D cube as a [`ManifoldPoint`]. | |
3 | */ | |
0 | 4 | |
12 | 5 | use serde_repr::*; |
6 | use serde::Serialize; | |
0 | 7 | use alg_tools::loc::Loc; |
8 | use alg_tools::norms::{Norm, L2}; | |
7 | 9 | use crate::manifold::{ManifoldPoint, EmbeddedManifoldPoint}; |
0 | 10 | |
13 | 11 | /// All the difference faces of a [`OnCube`]. |
12 | 12 | #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)] |
13 | #[repr(u8)] | |
14 | pub enum Face {F1 = 1, F2 = 2, F3 = 3, F4 = 4, F5 = 5, F6 = 6} | |
0 | 15 | use Face::*; |
16 | ||
17 | pub type Point = Loc<f64, 2>; | |
18 | ||
19 | pub type AdjacentFaces = [Face; 4]; | |
20 | ||
12 | 21 | #[derive(Clone, Debug, Serialize)] |
0 | 22 | pub enum Path { |
23 | Direct { destination : Face }, | |
24 | Indirect { destination : Face, intermediate : Face }, | |
25 | } | |
26 | ||
27 | /// An iterator over paths on a cube, from a source face to a destination face. | |
28 | #[derive(Clone, Debug)] | |
29 | pub enum PathIter { | |
30 | Direct(Face), | |
31 | Indirect{ destination : Face, intermediate : AdjacentFaces, current : usize}, | |
32 | Exhausted, | |
33 | } | |
34 | ||
35 | impl std::iter::Iterator for PathIter { | |
36 | type Item = Path; | |
37 | ||
38 | fn next(&mut self) -> Option<Self::Item> { | |
39 | use PathIter::*; | |
40 | match self { | |
41 | &mut Exhausted => None, | |
42 | &mut Direct(destination) => { | |
43 | *self = Exhausted; | |
44 | Some(Path::Direct { destination }) | |
45 | }, | |
46 | &mut Indirect{destination, intermediate : ref i, ref mut current} => { | |
47 | if *current < i.len() { | |
48 | let intermediate = i[*current]; | |
49 | *current += 1; | |
50 | Some(Path::Indirect{ destination, intermediate }) | |
51 | } else { | |
52 | *self = Exhausted; | |
53 | None | |
54 | } | |
55 | } | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
11 | 60 | impl std::fmt::Display for Face { |
61 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
62 | let s = match *self { | |
63 | F1 => "F1", | |
64 | F2 => "F2", | |
65 | F3 => "F3", | |
66 | F4 => "F4", | |
67 | F5 => "F5", | |
68 | F6 => "F6", | |
69 | }; | |
70 | write!(f, "{}", s) | |
71 | } | |
72 | } | |
0 | 73 | |
74 | impl Face { | |
11 | 75 | /// Return an aray of all faces |
76 | pub fn all() -> [Face; 6] { | |
77 | [F1, F2, F3, F4, F5, F6] | |
78 | } | |
79 | ||
3 | 80 | /// Returns an array of the four faces adjacent to `self` in the |
81 | /// order [left, right, down, up] in the `self`-relative unfolding. | |
0 | 82 | pub fn adjacent_faces(&self) -> AdjacentFaces { |
83 | match *self { | |
3 | 84 | F1 => [F3, F2, F4, F5], |
85 | F2 => [F4, F5, F1, F6], | |
86 | F3 => [F5, F4, F1, F6], | |
87 | F4 => [F3, F2, F1, F6], | |
88 | F5 => [F2, F3, F1, F6], | |
89 | F6 => [F3, F2, F4, F5], | |
0 | 90 | } |
91 | } | |
92 | ||
93 | /// Returns the face opposing `self`. | |
94 | pub fn opposing_face(&self) -> Face { | |
95 | match *self { | |
96 | F1 => F6, | |
97 | F2 => F3, | |
98 | F3 => F2, | |
3 | 99 | F4 => F5, |
0 | 100 | F5 => F4, |
101 | F6 => F1, | |
102 | } | |
103 | } | |
104 | ||
105 | /// Converts a point on an adjacent face to the coordinate system of `self`. | |
106 | pub fn convert_adjacent(&self, adjacent : Face, p: &Point) -> Option<Point> { | |
107 | let Loc([x, y]) = *p; | |
108 | let mk = |x, y| Some(Loc([x, y])); | |
109 | match adjacent { | |
110 | F1 => match *self { | |
111 | F2 => mk(y, x - 1.0), | |
112 | F3 => mk(1.0 - y, -x), | |
113 | F4 => mk(x, -y), | |
114 | F5 => mk(1.0 - x, y - 1.0), | |
115 | F1 => mk(x, y), | |
116 | F6 => None, | |
117 | }, | |
118 | F2 => match *self { | |
119 | F1 => mk(y + 1.0, x), | |
120 | F4 => mk(x + 1.0, y), | |
121 | F5 => mk(x - 1.0, y), | |
122 | F6 => mk(2.0 - y, x), | |
123 | F2 => mk(x, y), | |
124 | F3 => None, | |
125 | }, | |
126 | F3 => match *self { | |
127 | F1 => mk(-y, 1.0 - x), | |
128 | F4 => mk(x - 1.0, y), | |
129 | F5 => mk(x + 1.0, y), | |
130 | F6 => mk(y - 1.0, 1.0 - x), | |
131 | F3 => mk(x, y), | |
132 | F2 => None, | |
133 | }, | |
134 | F4 => match *self { | |
135 | F1 => mk(x, -y), | |
136 | F2 => mk(x - 1.0, y), | |
137 | F3 => mk(x + 1.0, y), | |
138 | F6 => mk(x, y - 1.0), | |
139 | F4 => mk(x, y), | |
140 | F5 => None, | |
141 | }, | |
142 | F5 => match *self { | |
143 | F1 => mk(1.0 -x, y + 1.0), | |
144 | F2 => mk(x + 1.0, y), | |
145 | F3 => mk(x - 1.0, y), | |
146 | F6 => mk(1.0 -x, 2.0 - y), | |
147 | F5 => mk(x, y), | |
148 | F4 => None, | |
149 | }, | |
150 | F6 => match *self { | |
151 | F2 => mk(y, 2.0 - x), | |
152 | F3 => mk(1.0 - y, x + 1.0), | |
153 | F4 => mk(x, y + 1.0), | |
154 | F5 => mk(1.0 - x, 2.0 - y), | |
155 | F6 => mk(x, y), | |
156 | F1 => None, | |
157 | } | |
158 | } | |
159 | } | |
160 | ||
161 | /// Converts a point behind a path to the coordinate system of `self`. | |
162 | pub fn convert(&self, path : &Path, p: &Point) -> Point { | |
163 | use Path::*; | |
3 | 164 | //dbg!(*self, path); |
0 | 165 | match path { |
166 | &Direct{ destination : d} => self.convert_adjacent(d, p), | |
167 | &Indirect{ destination : d, intermediate : i } | |
3 | 168 | => {self.convert_adjacent(i, &i.convert_adjacent(d, p).unwrap())} |
0 | 169 | }.unwrap() |
170 | } | |
171 | ||
172 | ||
173 | /// Returns an iterator over all the paths from `self` to `other`. | |
174 | fn paths(&self, other : Face) -> PathIter { | |
3 | 175 | //dbg!(self, other); |
0 | 176 | if self.opposing_face() == other { |
177 | PathIter::Indirect { | |
178 | intermediate : self.adjacent_faces(), | |
179 | destination : other, | |
180 | current : 0 | |
181 | } | |
182 | } else { | |
183 | PathIter::Direct(other) | |
184 | } | |
185 | } | |
3 | 186 | |
13 | 187 | /// Indicates whether an unfolded point `p` is on this face, i.e., |
188 | /// has coordinates in [0,1]². | |
3 | 189 | pub fn is_in_face(&self, p: &Point) -> bool { |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
190 | p.iter().all(|t| 0.0 <= *t && *t <= 1.0) |
3 | 191 | } |
192 | ||
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
193 | /// Given an unfolded point `p` and a destination point `d` in unfolded coordinates, |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
194 | /// but possibly outside this face, find the crossing point of the line between |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
195 | /// `p` and `d` on an edge of (`self`). Return the point and the edge presented |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
196 | /// by an adjacent face. |
13 | 197 | /// |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
198 | /// Crossing at corners is decided arbitrarily. |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
199 | pub fn find_crossing(&self, p :& Point, d : &Point) -> (Face, Point) { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
200 | //assert!(self.is_in_face(p)); |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
201 | |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
202 | if self.is_in_face(d) { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
203 | return (*self, *p) |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
204 | } |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
205 | |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
206 | use std::cmp::Ordering::*; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
207 | |
3 | 208 | let &Loc([x, y]) = p; |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
209 | let &Loc([xd, yd]) = d; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
210 | let tx = xd - x; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
211 | let ty = yd - y; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
212 | |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
213 | // Move towards tangent as (x + s tx, y + s ty) for the largest s<=1.0 for which |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
214 | // both coordinates is within [0, 1]. |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
215 | let sx = match tx.partial_cmp(&0.0) { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
216 | Some(Less) => 1.0f64.min(-x/tx), |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
217 | Some(Greater) => 1.0f64.min((1.0-x)/tx), |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
218 | _ => 1.0, |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
219 | }; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
220 | let sy = match ty.partial_cmp(&0.0) { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
221 | Some(Less) => 1.0f64.min(-y/ty), |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
222 | Some(Greater) => 1.0f64.min((1.0-y)/ty), |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
223 | _ => 1.0, |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
224 | }; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
225 | // We use the point where one coordinate comes within the range to decide on |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
226 | // the edge. |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
227 | let s = sx.max(sy); |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
228 | // But move such that both coordinates are within the range. |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
229 | let c = sx.min(sy); |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
230 | let (cx, cy) = (x + c*tx, y + c*ty); |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
231 | |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
232 | let crossing = |t| match (0.0 <= t, t <= 1.0) { |
3 | 233 | (false, _) => Less, |
234 | (_, false) => Greater, | |
235 | _ => Equal, | |
236 | }; | |
237 | ||
238 | // TODO: how to properly handle corners? Just throw an error? | |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
239 | let crossing = match (crossing(x + s*tx), crossing(y + s*ty)) { |
3 | 240 | (Equal, Equal) => *self, |
241 | (Less, _) => self.adjacent_faces()[0], | |
242 | (Greater, _) => self.adjacent_faces()[1], | |
243 | (Equal, Less) => self.adjacent_faces()[2], | |
244 | (Equal, Greater) => self.adjacent_faces()[3], | |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
245 | }; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
246 | (crossing, Loc([cx, cy])) |
3 | 247 | } |
7 | 248 | |
249 | /// Get embedded 3D coordinates | |
250 | pub fn embedded_coords(&self, p : &Point) -> Loc<f64, 3> { | |
251 | let &Loc([x, y]) = p; | |
252 | Loc(match *self { | |
253 | F1 => [x, y, 0.0], | |
254 | F2 => [1.0, x, y], | |
255 | F3 => [0.0, 1.0-x, y], | |
256 | F4 => [x, 0.0, y], | |
257 | F5 => [1.0 - x, 1.0, y], | |
258 | F6 => [x, y, 1.0], | |
259 | }) | |
260 | } | |
0 | 261 | } |
262 | ||
12 | 263 | #[derive(Clone, Debug, PartialEq, Serialize)] |
0 | 264 | pub struct OnCube { |
265 | face : Face, | |
266 | point : Point, | |
267 | } | |
268 | ||
5 | 269 | impl OnCube { |
7 | 270 | /// Creates a new point on the cube, given a face and face-relative coordinates |
271 | /// in [0, 1]^2 | |
272 | pub fn new(face : Face, point : Point) -> Self { | |
273 | assert!(face.is_in_face(&point)); | |
274 | OnCube { face, point } | |
275 | } | |
276 | ||
5 | 277 | /// Calculates both the logarithmic map and distance to another point |
278 | fn log_dist(&self, other : &Self) -> (<Self as ManifoldPoint>::Tangent, f64) { | |
279 | let mut best_len = f64::INFINITY; | |
280 | let mut best_tan = Loc([0.0, 0.0]); | |
281 | for path in self.face.paths(other.face) { | |
282 | let tan = self.face.convert(&path, &other.point) - &self.point; | |
283 | let len = tan.norm(L2); | |
284 | if len < best_len { | |
285 | best_tan = tan; | |
286 | best_len = len; | |
287 | } | |
288 | } | |
289 | (best_tan, best_len) | |
290 | } | |
12 | 291 | |
13 | 292 | /// Returns the face of this point. |
12 | 293 | pub fn face(&self) -> Face { |
294 | self.face | |
295 | } | |
5 | 296 | } |
297 | ||
7 | 298 | |
299 | impl EmbeddedManifoldPoint for OnCube { | |
300 | type EmbeddedCoords = Loc<f64, 3>; | |
301 | ||
302 | /// Get embedded 3D coordinates | |
303 | fn embedded_coords(&self) -> Loc<f64, 3> { | |
304 | self.face.embedded_coords(&self.point) | |
305 | } | |
306 | } | |
307 | ||
0 | 308 | impl ManifoldPoint for OnCube { |
309 | type Tangent = Point; | |
310 | ||
8 | 311 | fn exp(self, tangent : &Self::Tangent) -> Self { |
3 | 312 | let mut face = self.face; |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
313 | let mut point = self.point; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
314 | let mut dest = self.point + tangent; |
3 | 315 | loop { |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
316 | let (next_face, cross) = face.find_crossing(&point, &dest); |
3 | 317 | if next_face == face { |
318 | break | |
319 | } | |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
320 | point = next_face.convert_adjacent(face, &cross).unwrap(); |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
321 | dest = next_face.convert_adjacent(face, &dest).unwrap(); |
3 | 322 | face = next_face; |
323 | } | |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
324 | OnCube { face, point : dest } |
0 | 325 | } |
326 | ||
327 | fn log(&self, other : &Self) -> Self::Tangent { | |
5 | 328 | self.log_dist(other).0 |
329 | } | |
330 | ||
331 | fn dist_to(&self, other : &Self) -> f64 { | |
332 | self.log_dist(other).1 | |
0 | 333 | } |
6
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
334 | |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
335 | fn tangent_origin(&self) -> Self::Tangent { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
336 | Loc([0.0, 0.0]) |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
337 | } |
0 | 338 | } |
339 | ||
340 | #[cfg(test)] | |
341 | mod tests { | |
342 | use super::*; | |
343 | ||
344 | #[test] | |
10 | 345 | fn convert_adjacent() { |
346 | let point = Loc([0.4, 0.6]); | |
347 | ||
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
348 | for f1 in Face::all() { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
349 | for f2 in Face::all() { |
10 | 350 | println!("{:?}-{:?}", f1, f2); |
351 | match f1.convert_adjacent(f2, &point) { | |
352 | None => assert_eq!(f2.opposing_face(), f1), | |
353 | Some(q) => { | |
354 | match f2.convert_adjacent(f1, &q) { | |
355 | None => assert_eq!(f1.opposing_face(), f2), | |
356 | Some(p) => assert!((p-&point).norm(L2) < 1e-9), | |
357 | } | |
358 | } | |
359 | } | |
360 | } | |
361 | } | |
362 | } | |
363 | ||
364 | // This will fail, as different return path does not guarantee | |
365 | // that a point outside the face will be returned to its point of origin. | |
366 | // #[test] | |
367 | // fn convert_paths() { | |
368 | // let point = Loc([0.4, 0.6]); | |
369 | ||
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
370 | // for f1 in Face::all() { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
371 | // for f2 in Face::all() { |
10 | 372 | // for p1 in f2.paths(f1) { |
373 | // for p2 in f1.paths(f2) { | |
374 | // println!("{:?}-{:?}; {:?} {:?}", f1, f2, p1, p2); | |
375 | // let v = &f2.convert(&p1, &point); | |
376 | // let q = f1.convert(&p2, v); | |
377 | // assert!((q-&point).norm(L2) < 1e-9, | |
378 | // "norm({}-{}) ≥ 1e-9 (dest {})", q, &point, &v); | |
379 | // } | |
380 | // } | |
381 | // } | |
382 | // } | |
383 | // } | |
384 | ||
385 | #[test] | |
386 | fn log_adjacent() { | |
0 | 387 | let p1 = OnCube{ face : F1, point : Loc([0.5, 0.5])}; |
388 | let p2 = OnCube{ face : F2, point : Loc([0.5, 0.5])}; | |
389 | ||
390 | assert_eq!(p1.log(&p2).norm(L2), 1.0); | |
391 | } | |
392 | ||
393 | #[test] | |
10 | 394 | fn log_opposing_equal() { |
0 | 395 | let p1 = OnCube{ face : F1, point : Loc([0.5, 0.5])}; |
396 | let p2 = OnCube{ face : F6, point : Loc([0.5, 0.5])}; | |
397 | ||
398 | assert_eq!(p1.log(&p2).norm(L2), 2.0); | |
399 | } | |
400 | ||
401 | #[test] | |
10 | 402 | fn log_opposing_unique_shortest() { |
0 | 403 | let p1 = OnCube{ face : F1, point : Loc([0.3, 0.25])}; |
404 | let p2 = OnCube{ face : F6, point : Loc([0.3, 0.25])}; | |
405 | ||
406 | assert_eq!(p1.log(&p2).norm(L2), 1.5); | |
407 | } | |
408 | } | |
409 |