Ogeon / palette

A Rust library for linear color calculations and conversion
Apache License 2.0
748 stars 60 forks source link

Add `ArithmeticsAssignable` trait, or equivalent #340

Closed okaneco closed 1 year ago

okaneco commented 1 year ago

I've started porting my crates to 0.7 and this seemed like a small gap in convenience.

I had to rewrite a few places where I was summing individual components.

let mut l = T::from_f64(0.0);
// ...
l += color.l; // error, need to rewrite as the next line
l = l + color.l;

I'd like to see a trait where all the num::Arithmetics operations' Assignable variants are implemented.

Ogeon commented 1 year ago

That could be useful in general! Especially if it should branch off as its own crate.

The traits as they are are currently added as I need them, so it's far from a "complete" math trait library. More of a proof of concept, so it's still a bit minimal. For now, the work-around is for the caller to add additional bounds and maybe use num_traits if that's fine.

Ogeon commented 1 year ago

Thinking a bit more about it, I don't think this trait should be added unless Palette needs it. It's not based on any traits that only exist in Palette and it has the negative property of being impossible to extend without making a breaking change, so it goes against what I would like the palette::num traits to be. If I break that module off, the Arithmetics trait should either stay in Palette as a laziness helper or be removed. It's simple to create local versions of it, though, or it could be material for a separate crate.