๐Ÿ“ฆ ordovicia / kd-tree

๐Ÿ“„ split.rs ยท 21 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};

#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Split<Axis: Clone> {
    pub dim: usize,
    pub thresh: Axis,
}

impl<Axis> Split<Axis>
where
    Axis: Clone + PartialOrd,
{
    #[inline]
    pub fn belongs_to_left<Point: AsRef<[Axis]>>(&self, point: &Point) -> bool {
        let point = point.as_ref();
        point[self.dim] < self.thresh
    }
}