Wed, 06 Nov 2024 18:39:24 -0500
Also store initial iterate in log
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 |
15
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
214 | // both coordinates is within [0, 1]. Also gives the direction of move along |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
215 | // each coordinate. |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
216 | let (sx, dirx) = match tx.partial_cmp(&0.0) { |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
217 | Some(Less) => (1.0f64.min(-x/tx), Less), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
218 | Some(Greater) => (1.0f64.min((1.0-x)/tx), Greater), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
219 | _ => (1.0, Equal) |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
220 | }; |
15
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
221 | let (sy, diry) = match ty.partial_cmp(&0.0) { |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
222 | Some(Less) => (1.0f64.min(-y/ty), Less), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
223 | Some(Greater) => (1.0f64.min((1.0-y)/ty), Greater), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
224 | _ => (1.0, Equal), |
3 | 225 | }; |
226 | ||
227 | // TODO: how to properly handle corners? Just throw an error? | |
15
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
228 | let (crossing, c) = match (sx < sy, dirx, diry) { |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
229 | // x move is less than y move, so crossing is either on left or right edge |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
230 | (true, Less, _) => (self.adjacent_faces()[0], sx), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
231 | (true, Greater, _) => (self.adjacent_faces()[1], sx), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
232 | (true, Equal, _) => (*self, sx), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
233 | // y move is less than x move, so crossing is either on bottom or top edge |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
234 | (false, _, Less) => (self.adjacent_faces()[2], sy), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
235 | (false, _, Greater) => (self.adjacent_faces()[3], sy), |
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
236 | (false, _, Equal) => (*self, sy), |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
237 | }; |
15
2f4af30af476
Simplify crossing calculations
Tuomo Valkonen <tuomov@iki.fi>
parents:
14
diff
changeset
|
238 | (crossing, Loc([x + c*tx, y + c*ty])) |
3 | 239 | } |
7 | 240 | |
241 | /// Get embedded 3D coordinates | |
242 | pub fn embedded_coords(&self, p : &Point) -> Loc<f64, 3> { | |
243 | let &Loc([x, y]) = p; | |
244 | Loc(match *self { | |
245 | F1 => [x, y, 0.0], | |
246 | F2 => [1.0, x, y], | |
247 | F3 => [0.0, 1.0-x, y], | |
248 | F4 => [x, 0.0, y], | |
249 | F5 => [1.0 - x, 1.0, y], | |
250 | F6 => [x, y, 1.0], | |
251 | }) | |
252 | } | |
0 | 253 | } |
254 | ||
12 | 255 | #[derive(Clone, Debug, PartialEq, Serialize)] |
0 | 256 | pub struct OnCube { |
257 | face : Face, | |
258 | point : Point, | |
259 | } | |
260 | ||
5 | 261 | impl OnCube { |
7 | 262 | /// Creates a new point on the cube, given a face and face-relative coordinates |
263 | /// in [0, 1]^2 | |
264 | pub fn new(face : Face, point : Point) -> Self { | |
265 | assert!(face.is_in_face(&point)); | |
266 | OnCube { face, point } | |
267 | } | |
268 | ||
5 | 269 | /// Calculates both the logarithmic map and distance to another point |
270 | fn log_dist(&self, other : &Self) -> (<Self as ManifoldPoint>::Tangent, f64) { | |
271 | let mut best_len = f64::INFINITY; | |
272 | let mut best_tan = Loc([0.0, 0.0]); | |
273 | for path in self.face.paths(other.face) { | |
274 | let tan = self.face.convert(&path, &other.point) - &self.point; | |
275 | let len = tan.norm(L2); | |
276 | if len < best_len { | |
277 | best_tan = tan; | |
278 | best_len = len; | |
279 | } | |
280 | } | |
281 | (best_tan, best_len) | |
282 | } | |
12 | 283 | |
13 | 284 | /// Returns the face of this point. |
12 | 285 | pub fn face(&self) -> Face { |
286 | self.face | |
287 | } | |
5 | 288 | } |
289 | ||
7 | 290 | |
291 | impl EmbeddedManifoldPoint for OnCube { | |
292 | type EmbeddedCoords = Loc<f64, 3>; | |
293 | ||
294 | /// Get embedded 3D coordinates | |
295 | fn embedded_coords(&self) -> Loc<f64, 3> { | |
296 | self.face.embedded_coords(&self.point) | |
297 | } | |
298 | } | |
299 | ||
0 | 300 | impl ManifoldPoint for OnCube { |
301 | type Tangent = Point; | |
302 | ||
8 | 303 | fn exp(self, tangent : &Self::Tangent) -> Self { |
3 | 304 | let mut face = self.face; |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
305 | let mut point = self.point; |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
306 | let mut dest = self.point + tangent; |
3 | 307 | loop { |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
308 | let (next_face, cross) = face.find_crossing(&point, &dest); |
3 | 309 | if next_face == face { |
310 | break | |
311 | } | |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
312 | point = next_face.convert_adjacent(face, &cross).unwrap(); |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
313 | dest = next_face.convert_adjacent(face, &dest).unwrap(); |
3 | 314 | face = next_face; |
315 | } | |
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
316 | OnCube { face, point : dest } |
0 | 317 | } |
318 | ||
319 | fn log(&self, other : &Self) -> Self::Tangent { | |
5 | 320 | self.log_dist(other).0 |
321 | } | |
322 | ||
323 | fn dist_to(&self, other : &Self) -> f64 { | |
324 | self.log_dist(other).1 | |
0 | 325 | } |
6
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
326 | |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
327 | fn tangent_origin(&self) -> Self::Tangent { |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
328 | Loc([0.0, 0.0]) |
df9628092285
Add a zero function on manifolds
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
329 | } |
0 | 330 | } |
331 | ||
332 | #[cfg(test)] | |
333 | mod tests { | |
334 | use super::*; | |
335 | ||
336 | #[test] | |
10 | 337 | fn convert_adjacent() { |
338 | let point = Loc([0.4, 0.6]); | |
339 | ||
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
340 | for f1 in Face::all() { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
341 | for f2 in Face::all() { |
10 | 342 | println!("{:?}-{:?}", f1, f2); |
343 | match f1.convert_adjacent(f2, &point) { | |
344 | None => assert_eq!(f2.opposing_face(), f1), | |
345 | Some(q) => { | |
346 | match f2.convert_adjacent(f1, &q) { | |
347 | None => assert_eq!(f1.opposing_face(), f2), | |
348 | Some(p) => assert!((p-&point).norm(L2) < 1e-9), | |
349 | } | |
350 | } | |
351 | } | |
352 | } | |
353 | } | |
354 | } | |
355 | ||
356 | // This will fail, as different return path does not guarantee | |
357 | // that a point outside the face will be returned to its point of origin. | |
358 | // #[test] | |
359 | // fn convert_paths() { | |
360 | // let point = Loc([0.4, 0.6]); | |
361 | ||
14
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
362 | // for f1 in Face::all() { |
d0f20c6cb49c
Fixes to find_crossing and exp
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
363 | // for f2 in Face::all() { |
10 | 364 | // for p1 in f2.paths(f1) { |
365 | // for p2 in f1.paths(f2) { | |
366 | // println!("{:?}-{:?}; {:?} {:?}", f1, f2, p1, p2); | |
367 | // let v = &f2.convert(&p1, &point); | |
368 | // let q = f1.convert(&p2, v); | |
369 | // assert!((q-&point).norm(L2) < 1e-9, | |
370 | // "norm({}-{}) ≥ 1e-9 (dest {})", q, &point, &v); | |
371 | // } | |
372 | // } | |
373 | // } | |
374 | // } | |
375 | // } | |
376 | ||
377 | #[test] | |
378 | fn log_adjacent() { | |
0 | 379 | let p1 = OnCube{ face : F1, point : Loc([0.5, 0.5])}; |
380 | let p2 = OnCube{ face : F2, point : Loc([0.5, 0.5])}; | |
381 | ||
382 | assert_eq!(p1.log(&p2).norm(L2), 1.0); | |
383 | } | |
384 | ||
385 | #[test] | |
10 | 386 | fn log_opposing_equal() { |
0 | 387 | let p1 = OnCube{ face : F1, point : Loc([0.5, 0.5])}; |
388 | let p2 = OnCube{ face : F6, point : Loc([0.5, 0.5])}; | |
389 | ||
390 | assert_eq!(p1.log(&p2).norm(L2), 2.0); | |
391 | } | |
392 | ||
393 | #[test] | |
10 | 394 | fn log_opposing_unique_shortest() { |
0 | 395 | let p1 = OnCube{ face : F1, point : Loc([0.3, 0.25])}; |
396 | let p2 = OnCube{ face : F6, point : Loc([0.3, 0.25])}; | |
397 | ||
398 | assert_eq!(p1.log(&p2).norm(L2), 1.5); | |
399 | } | |
400 | } | |
401 |