kernel_api/point_match.rs
1//! When two mesh points count as one: the key every weld and every match
2//! of mesh corners hashes a point by, so each caller says only how close.
3
4/// When two mesh points are one point.
5#[derive(Clone, Copy, Debug, PartialEq)]
6pub enum PointMatch {
7 /// The very same coordinates, `-0.0` and `0.0` alike.
8 Exact,
9 /// Rounding to the same cell of a grid of `per_mm` cells to the
10 /// millimetre on each axis.
11 Grid { per_mm: f64 },
12}
13
14impl PointMatch {
15 /// The key `p` hashes by: two points are one when their keys are equal.
16 /// A grid's cells have edges, so two points a hair apart either side of
17 /// one stay two.
18 pub fn key(self, p: [f32; 3]) -> [i64; 3] {
19 match self {
20 // Adding zero turns `-0.0` into `0.0` and leaves every other
21 // value as it is.
22 Self::Exact => p.map(|c| i64::from((c + 0.0).to_bits())),
23 Self::Grid { per_mm } => p.map(|c| (f64::from(c) * per_mm).round() as i64),
24 }
25 }
26}