mod exact;
#[cfg(test)]
mod reference;
#[cfg(test)]
mod tests;
mod vp;
use crate::attr::Profile;
use crate::pal::{FPixel, PalF};
#[allow(clippy::large_enum_variant)]
pub(crate) enum Nearest {
Compat(vp::VpNearest),
Improved(exact::ExactNearest),
}
impl Nearest {
pub fn new(map: &PalF, fast: bool, profile: Profile) -> Self {
match profile {
Profile::Compat => Self::Compat(vp::VpNearest::new(map, fast)),
Profile::Improved => {
let colors: Vec<FPixel> = map.items.iter().map(|p| p.color).collect();
Self::Improved(exact::ExactNearest::new(&colors))
}
}
}
#[inline]
pub fn search(&self, px: FPixel, likely_colormap_index: usize, min_opaque_val: f32) -> (usize, f32) {
match self {
Self::Compat(n) => n.search(px, likely_colormap_index, min_opaque_val),
Self::Improved(n) => n.search(px, likely_colormap_index, min_opaque_val),
}
}
}