1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::math::{Point, Vector};
use na::{RealField, Unit};
pub trait Kernel: Send + Sync {
fn scalar_apply<N: RealField>(r: N, h: N) -> N;
fn scalar_apply_diff<N: RealField>(r: N, h: N) -> N;
fn apply<N: RealField>(v: Vector<N>, h: N) -> N {
Self::scalar_apply(v.norm(), h)
}
fn apply_diff<N: RealField>(v: Vector<N>, h: N) -> Vector<N> {
if let Some((dir, norm)) = Unit::try_new_and_get(v, N::default_epsilon()) {
*dir * Self::scalar_apply_diff(norm, h)
} else {
Vector::zeros()
}
}
fn points_apply<N: RealField>(p1: &Point<N>, p2: &Point<N>, h: N) -> N {
Self::apply(p1 - p2, h)
}
fn points_apply_diff1<N: RealField>(p1: &Point<N>, p2: &Point<N>, h: N) -> Vector<N> {
Self::apply_diff(p1 - p2, h)
}
fn points_apply_diff2<N: RealField>(p1: &Point<N>, p2: &Point<N>, h: N) -> Vector<N> {
-Self::apply_diff(p1 - p2, h)
}
}