(palette: &'pal PalF)
| 4 | impl<'pal> Nearest<'pal> { |
| 5 | #[inline(never)] |
| 6 | pub fn new(palette: &'pal PalF) -> Result<Self, Error> { |
| 7 | if palette.len() > PalIndex::MAX as usize + 1 { |
| 8 | return Err(Error::Unsupported); |
| 9 | } |
| 10 | let mut indexes: Vec<_> = (0..palette.len()) |
| 11 | .map(|idx| MapIndex { idx: idx as _ }) |
| 12 | .collect(); |
| 13 | if indexes.is_empty() { |
| 14 | return Err(Error::Unsupported); |
| 15 | } |
| 16 | let mut handle = Nearest { |
| 17 | root: vp_create_node(&mut indexes, palette), |
| 18 | palette, |
| 19 | nearest_other_color_dist: [0.; MAX_COLORS], |
| 20 | }; |
| 21 | for (i, color) in palette.as_slice().iter().enumerate() { |
| 22 | let mut best = Visitor { |
| 23 | idx: 0, |
| 24 | distance: f32::MAX, |
| 25 | distance_squared: f32::MAX, |
| 26 | exclude: Some(i as PalIndex), |
| 27 | }; |
| 28 | vp_search_node(&handle.root, color, &mut best); |
| 29 | handle.nearest_other_color_dist[i] = best.distance_squared / 4.; |
| 30 | } |
| 31 | Ok(handle) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | impl Nearest<'_> { |
nothing calls this directly
no test coverage detected