Closed Ogeon closed 1 year ago
Good summary :slightly_smiling_face:
Another feature that I think would be useful is some way to reuse the existing allocations. It might be an extend
-like interface so that users could call clear
on the existing data and re-initialize with an iterator.
Ah, yes, that should also be there! I'll edit the description to include them...
Description
As discussed in https://github.com/Ogeon/palette/discussions/303, it would be useful to have an interface for converting an array/
Vec
of colors to and from Struct of Arrays format. The first step should be:Rgb<S, Vec<T>>
from someI: IntoIterator<Item = Rgb<S, T>>
, and the same for the other color types.fn get_mut(&mut self, index: usize) -> Option<Rgb<S, &mut T>>
.fn iter_mut(&mut self) -> impl Iterator<Item = Rgb<S, &mut T>
.Rgb<S, &mut T>
.Vec::clear
andVec::extend
.In addition to that, we may want to add chunks and windows iterators.
The reference components will likely be necessary, due to the split into separate arrays, unless there's a smarter solution. They don't have to enable much more than reading and writing, though. It's also what would make it hard to implement the
Index
andIndexMut
traits, if possible at all.Motivation
The discussions in https://github.com/Ogeon/palette/discussions/303 covers it pretty well. One of the main reasons for a built-in interface is that it gives a way to correctly preserve the color type information across conversions. It also lowers the bar for working with SoA data.