timedata-org / old-timedata

Time arts data - high-performance color processing in C++ and Python.
7 stars 3 forks source link

Accessing a `ColorList` creates a new `Color` every time. #119

Closed rec closed 8 years ago

rec commented 8 years ago

For matrix operations, this is going to involve a great deal of unnecessary calculation.

We need to cache these Colors, and they need to be a new type that looks just like a Color but reference a ColorList.

rec commented 8 years ago

After going in the wrong direction for a bit, I think I've decided that we will still create a new Color when subscripted (using the default accessor __getitem__()) - because this is extremely convenient and easy-to-use.

To solve this, we'll have an alternate accessor that writes to a mutable color! So you create it once, and then fill it in from your ColorList - no allocations.

This doubles the number of colors classes we have, but I can probably use inheritance, though I might need to create a hierarchy with three classes total: ColorRGBBase, ColorRGB, ColorRGBMutable. Hopefully not!