src/cube.rs

changeset 7
8979a6638424
parent 6
df9628092285
child 8
17d71ca4ce84
equal deleted inserted replaced
6:df9628092285 7:8979a6638424
1 1
2 use core::f64; 2 use core::f64;
3 3
4 use alg_tools::loc::Loc; 4 use alg_tools::loc::Loc;
5 use alg_tools::norms::{Norm, L2}; 5 use alg_tools::norms::{Norm, L2};
6 use crate::manifold::ManifoldPoint; 6 use crate::manifold::{ManifoldPoint, EmbeddedManifoldPoint};
7 7
8 #[derive(Copy, Clone, Debug, Eq, PartialEq)] 8 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
9 pub enum Face {F1, F2, F3, F4, F5, F6} 9 pub enum Face {F1, F2, F3, F4, F5, F6}
10 use Face::*; 10 use Face::*;
11 11
181 (Greater, _) => self.adjacent_faces()[1], 181 (Greater, _) => self.adjacent_faces()[1],
182 (Equal, Less) => self.adjacent_faces()[2], 182 (Equal, Less) => self.adjacent_faces()[2],
183 (Equal, Greater) => self.adjacent_faces()[3], 183 (Equal, Greater) => self.adjacent_faces()[3],
184 } 184 }
185 } 185 }
186
187 /// Get embedded 3D coordinates
188 pub fn embedded_coords(&self, p : &Point) -> Loc<f64, 3> {
189 let &Loc([x, y]) = p;
190 Loc(match *self {
191 F1 => [x, y, 0.0],
192 F2 => [1.0, x, y],
193 F3 => [0.0, 1.0-x, y],
194 F4 => [x, 0.0, y],
195 F5 => [1.0 - x, 1.0, y],
196 F6 => [x, y, 1.0],
197 })
198 }
186 } 199 }
187 200
188 #[derive(Clone, Debug, PartialEq)] 201 #[derive(Clone, Debug, PartialEq)]
189 pub struct OnCube { 202 pub struct OnCube {
190 face : Face, 203 face : Face,
191 point : Point, 204 point : Point,
192 } 205 }
193 206
194 impl OnCube { 207 impl OnCube {
208 /// Creates a new point on the cube, given a face and face-relative coordinates
209 /// in [0, 1]^2
210 pub fn new(face : Face, point : Point) -> Self {
211 assert!(face.is_in_face(&point));
212 OnCube { face, point }
213 }
214
195 /// Calculates both the logarithmic map and distance to another point 215 /// Calculates both the logarithmic map and distance to another point
196 fn log_dist(&self, other : &Self) -> (<Self as ManifoldPoint>::Tangent, f64) { 216 fn log_dist(&self, other : &Self) -> (<Self as ManifoldPoint>::Tangent, f64) {
197 let mut best_len = f64::INFINITY; 217 let mut best_len = f64::INFINITY;
198 let mut best_tan = Loc([0.0, 0.0]); 218 let mut best_tan = Loc([0.0, 0.0]);
199 for path in self.face.paths(other.face) { 219 for path in self.face.paths(other.face) {
206 } 226 }
207 (best_tan, best_len) 227 (best_tan, best_len)
208 } 228 }
209 } 229 }
210 230
231
232 impl EmbeddedManifoldPoint for OnCube {
233 type EmbeddedCoords = Loc<f64, 3>;
234
235 /// Get embedded 3D coordinates
236 fn embedded_coords(&self) -> Loc<f64, 3> {
237 self.face.embedded_coords(&self.point)
238 }
239 }
240
211 impl ManifoldPoint for OnCube { 241 impl ManifoldPoint for OnCube {
212 type Tangent = Point; 242 type Tangent = Point;
213 243
214 fn exp(&self, tangent : &Self::Tangent) -> Self { 244 fn exp(&self, tangent : &Self::Tangent) -> Self {
215 let mut face = self.face; 245 let mut face = self.face;

mercurial