2 use alg_tools::mapping::Apply; |
2 use alg_tools::mapping::Apply; |
3 use crate::manifold::ManifoldPoint; |
3 use crate::manifold::ManifoldPoint; |
4 use crate::fb::{Grad, Desc}; |
4 use crate::fb::{Grad, Desc}; |
5 |
5 |
6 /// Structure for distance-to functions |
6 /// Structure for distance-to functions |
7 pub struct DistTo<M : ManifoldPoint> { |
7 pub struct DistTo<M : ManifoldPoint>(pub M); |
8 base : M |
|
9 } |
|
10 |
8 |
11 impl<M : ManifoldPoint> Apply<M> for DistTo<M> { |
9 impl<M : ManifoldPoint> Apply<M> for DistTo<M> { |
12 type Output = f64; |
10 type Output = f64; |
13 |
11 |
14 fn apply(&self, x : M) -> Self::Output { |
12 fn apply(&self, x : M) -> Self::Output { |
15 self.base.dist_to(&x) |
13 self.0.dist_to(&x) |
16 } |
14 } |
17 } |
15 } |
18 |
16 |
19 impl<'a, M : ManifoldPoint> Apply<&'a M> for DistTo<M> { |
17 impl<'a, M : ManifoldPoint> Apply<&'a M> for DistTo<M> { |
20 type Output = f64; |
18 type Output = f64; |
21 |
19 |
22 fn apply(&self, x : &'a M) -> Self::Output { |
20 fn apply(&self, x : &'a M) -> Self::Output { |
23 self.base.dist_to(x) |
21 self.0.dist_to(x) |
24 } |
22 } |
25 } |
23 } |
26 |
24 |
27 /// Structure for distance-to functions |
25 /// Structure for distance-to functions |
28 pub struct DistToSquaredDiv2<M : ManifoldPoint> { |
26 pub struct DistToSquaredDiv2<M : ManifoldPoint>(pub M); |
29 base : M |
|
30 } |
|
31 |
27 |
32 impl<M : ManifoldPoint> Apply<M> for DistToSquaredDiv2<M> { |
28 impl<M : ManifoldPoint> Apply<M> for DistToSquaredDiv2<M> { |
33 type Output = f64; |
29 type Output = f64; |
34 |
30 |
35 fn apply(&self, x : M) -> Self::Output { |
31 fn apply(&self, x : M) -> Self::Output { |
36 let d = self.base.dist_to(&x); |
32 let d = self.0.dist_to(&x); |
37 d*d / 2.0 |
33 d*d / 2.0 |
38 } |
34 } |
39 } |
35 } |
40 |
36 |
41 impl<'a, M : ManifoldPoint> Apply<&'a M> for DistToSquaredDiv2<M> { |
37 impl<'a, M : ManifoldPoint> Apply<&'a M> for DistToSquaredDiv2<M> { |
42 type Output = f64; |
38 type Output = f64; |
43 |
39 |
44 fn apply(&self, x : &'a M) -> Self::Output { |
40 fn apply(&self, x : &'a M) -> Self::Output { |
45 let d = self.base.dist_to(x); |
41 let d = self.0.dist_to(x); |
46 d*d / 2.0 |
42 d*d / 2.0 |
47 } |
43 } |
48 } |
44 } |
49 |
45 |
50 impl<M : ManifoldPoint> Desc<M> for DistToSquaredDiv2<M> { |
46 impl<M : ManifoldPoint> Desc<M> for DistToSquaredDiv2<M> { |