use nalgebra::Point2;
use crate::lattice::Coord;
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct PointFeature {
pub source_index: usize,
pub position: Point2<f32>,
}
impl PointFeature {
pub fn new(source_index: usize, position: Point2<f32>) -> Self {
Self {
source_index,
position,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct LocalAxis {
pub angle_rad: f32,
pub sigma_rad: Option<f32>,
}
impl LocalAxis {
pub fn new(angle_rad: f32, sigma_rad: Option<f32>) -> Self {
Self {
angle_rad,
sigma_rad,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct OrientedFeature<const N: usize> {
pub point: PointFeature,
pub axes: [LocalAxis; N],
}
impl<const N: usize> OrientedFeature<N> {
pub fn new(point: PointFeature, axes: [LocalAxis; N]) -> Self {
Self { point, axes }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct CoordinateHypothesis {
pub source_index: usize,
pub coord: Coord,
pub confidence: Option<f32>,
}
impl CoordinateHypothesis {
pub fn new(source_index: usize, coord: Coord, confidence: Option<f32>) -> Self {
Self {
source_index,
coord,
confidence,
}
}
pub fn unweighted(source_index: usize, coord: Coord) -> Self {
Self::new(source_index, coord, None)
}
}
#[cfg(test)]
mod tests {
use nalgebra::Point2;
use super::*;
#[test]
fn point_feature_constructs() {
let p = PointFeature::new(7, Point2::new(1.0_f32, 2.0));
assert_eq!(p.source_index, 7);
assert_eq!(p.position, Point2::new(1.0, 2.0));
}
#[test]
fn oriented_feature_arities_construct() {
let p = PointFeature::new(0, Point2::new(0.0_f32, 0.0));
let a = LocalAxis::new(0.0, Some(0.1));
let one = OrientedFeature::<1>::new(p, [a]);
let two = OrientedFeature::<2>::new(p, [a, LocalAxis::new(1.0, None)]);
let three =
OrientedFeature::<3>::new(p, [a, LocalAxis::new(1.0, None), LocalAxis::new(2.0, None)]);
assert_eq!(one.axes.len(), 1);
assert_eq!(two.axes.len(), 2);
assert_eq!(three.axes.len(), 3);
}
#[test]
fn coordinate_hypothesis_constructs() {
let h = CoordinateHypothesis::new(3, Coord::new(4, -2), Some(0.9_f32));
assert_eq!(h.source_index, 3);
assert_eq!(h.coord, Coord::new(4, -2));
assert_eq!(h.confidence, Some(0.9));
}
#[test]
fn coordinate_hypothesis_unweighted_has_no_confidence() {
let h = CoordinateHypothesis::unweighted(7, Coord::new(1, 2));
assert_eq!(h.source_index, 7);
assert_eq!(h.coord, Coord::new(1, 2));
assert_eq!(h.confidence, None);
}
}