Box array

This commit is contained in:
asonix 2024-02-18 01:18:04 -06:00
parent d55e17ec78
commit 835825f617

View file

@ -34,7 +34,7 @@ impl std::fmt::Display for ComponentError {
pub struct Encoder {
index: usize,
components: Components,
factors: Vec<(ComponentState, [f32; 3])>,
factors: Box<[(ComponentState, [f32; 3])]>,
bounds: ImageBounds,
}
@ -60,11 +60,13 @@ impl Encoder {
Ok(Self {
index: 0,
components: Components { x, y },
factors: (0..y)
.flat_map(|y| {
(0..x).map(move |x| (ComponentState { x, y, basis: 0. }, [0., 0., 0.]))
})
.collect(),
factors: Box::from(
(0..y)
.flat_map(|y| {
(0..x).map(move |x| (ComponentState { x, y, basis: 0. }, [0., 0., 0.]))
})
.collect::<Vec<_>>(),
),
bounds,
})
}
@ -137,7 +139,7 @@ impl Encoder {
}
pub fn finalize(mut self) -> String {
for (ComponentState { x, y, .. }, [r, g, b]) in &mut self.factors {
for (ComponentState { x, y, .. }, [r, g, b]) in self.factors.iter_mut() {
let normalisation = if *x == 0 && *y == 0 { 1. } else { 2. };
let scale = normalisation / (self.bounds.width * self.bounds.height) as f32;