use crate::feature::{LocalAxis, OrientedFeature};
#[derive(Clone, Copy, Debug)]
pub(super) struct AxisCache {
pub(super) angle_rad: [f32; 2],
pub(super) informative: [bool; 2],
}
impl AxisCache {
#[inline]
pub(super) fn any_informative(&self) -> bool {
self.informative[0] || self.informative[1]
}
}
#[inline]
pub(super) fn is_informative(axis: &LocalAxis, max_sigma_rad: f32) -> bool {
match axis.sigma_rad {
None => true,
Some(s) => s.is_finite() && s < max_sigma_rad,
}
}
pub(super) fn build_axis_caches(
features: &[OrientedFeature<2>],
max_sigma_rad: f32,
) -> Vec<AxisCache> {
features
.iter()
.map(|f| AxisCache {
angle_rad: [f.axes[0].angle_rad, f.axes[1].angle_rad],
informative: [
is_informative(&f.axes[0], max_sigma_rad),
is_informative(&f.axes[1], max_sigma_rad),
],
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::feature::{LocalAxis, PointFeature};
use nalgebra::Point2;
fn feature(idx: usize, axes: [LocalAxis; 2]) -> OrientedFeature<2> {
OrientedFeature::new(PointFeature::new(idx, Point2::new(0.0, 0.0)), axes)
}
#[test]
fn none_sigma_is_informative() {
let cache = build_axis_caches(
&[feature(
0,
[
LocalAxis::new(0.0, None),
LocalAxis::new(std::f32::consts::FRAC_PI_2, None),
],
)],
0.6,
);
assert!(cache[0].informative[0]);
assert!(cache[0].informative[1]);
}
#[test]
fn high_sigma_is_not_informative() {
let cache = build_axis_caches(
&[feature(
0,
[
LocalAxis::new(0.0, Some(0.1)),
LocalAxis::new(std::f32::consts::FRAC_PI_2, Some(std::f32::consts::PI)),
],
)],
0.6,
);
assert!(cache[0].informative[0]);
assert!(!cache[0].informative[1]);
}
#[test]
fn pi_sigma_is_not_informative() {
let cache = build_axis_caches(
&[feature(
7,
[
LocalAxis::new(0.0, Some(std::f32::consts::PI)),
LocalAxis::new(std::f32::consts::FRAC_PI_2, Some(std::f32::consts::PI)),
],
)],
0.6,
);
assert!(!cache[0].informative[0]);
assert!(!cache[0].informative[1]);
assert!(!cache[0].any_informative());
}
#[test]
fn non_finite_sigma_is_not_informative() {
let cache = build_axis_caches(
&[feature(
0,
[
LocalAxis::new(0.0, Some(f32::INFINITY)),
LocalAxis::new(std::f32::consts::FRAC_PI_2, Some(f32::NAN)),
],
)],
0.6,
);
assert!(!cache[0].informative[0]);
assert!(!cache[0].informative[1]);
}
}