gistools/util/interpolation/
average.rs

1use crate::util::GetInterpolateValue;
2use s2json::{GetM, GetXY, GetZ};
3
4use super::Interpolatable;
5
6/// # Average Neighbor Interpolation
7///
8/// ## Description
9/// Finds the avarage point in the reference data to the given point and returns its value.
10///
11/// ## Usage
12pub fn average_interpolation<M: Clone, P: GetXY + GetZ, R: GetM<M>, V: Interpolatable>(
13    _point: &P,
14    ref_data: &[R],
15    get_value: GetInterpolateValue<R, V>,
16) -> V {
17    let mut res = V::default();
18    for ref_point in ref_data {
19        res += get_value(ref_point);
20    }
21
22    res /= ref_data.len() as f64;
23
24    res
25}