pub fn predict_grid_position<F: Float>(
labelled: &HashMap<Coord, Point2<F>>,
at: Coord,
kind: LatticeKind,
) -> Option<PredictedPosition<F>>Expand description
Predict a lattice coordinate’s image position from its labelled neighbours.
For each axis family of kind, if both opposite neighbours of at are
present in labelled, their midpoint predicts at; the returned position
averages the available midpoints. Returns None when no complete
opposite pair exists — this function interpolates only, it never
extrapolates outward from the labelled set.
On a square lattice the pairs are (±1, 0) and (0, ±1); on a hex axial
lattice they are (±1, 0), (0, ±1), and ±(1, -1).
use nalgebra::Point2;
use projective_grid::{predict_grid_position, Coord, LatticeKind};
use std::collections::HashMap;
let mut labelled: HashMap<Coord, Point2<f32>> = HashMap::new();
labelled.insert(Coord::new(-1, 0), Point2::new(10.0, 50.0));
labelled.insert(Coord::new(1, 0), Point2::new(90.0, 50.0));
let pred = predict_grid_position(&labelled, Coord::new(0, 0), LatticeKind::Square).unwrap();
assert_eq!(pred.position, Point2::new(50.0, 50.0));
assert_eq!(pred.n_axis_pairs, 1);
// A frontier coordinate with no opposite pair is not predicted.
assert!(predict_grid_position(&labelled, Coord::new(2, 0), LatticeKind::Square).is_none());