1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use necsim_core_maths::MathsCore;

use super::{vector::VecType, NoiseEvaluator, PermTable};

pub fn contribute<NoiseEvaluatorType: NoiseEvaluator<Vec>, Vec: VecType<f64>, M: MathsCore>(
    delta: Vec,
    origin: Vec,
    grid: Vec,
    perm: &PermTable,
    wrap: f64,
) -> f64 {
    let shifted: Vec = origin - delta - NoiseEvaluatorType::SQUISH_POINT * delta.sum();
    let attn: f64 = 2.0 - shifted.get_attenuation_factor();

    if attn <= 0.0 {
        return 0.0;
    }

    let attn2 = attn * attn;
    let attn4 = attn2 * attn2;

    attn4 * NoiseEvaluatorType::extrapolate::<M>(grid + delta, shifted, perm, wrap)
}