Closed flxzt closed 11 months ago
That discussion is about Copy
and f64
implements Copy
. If floats cause issues for const
then this here is a different decision.
The code itself looks good.
Sorry, poorly worded. What I meant: Right now Color simply holds an int. When piet would switch to a more complex data type (to support HDR for example) it could be challenging to keep the methods I am introducing here const
, because a const fn
cannot use regular fn
's inside it, and the methods for floating point arithmetics are currently all regular fn
's .
So I see two (potential) decisions:
const
similar to
with_alpha()
, which unfortunately can't currently beconst fn
due to floating point arithmetic's, I am suggesting to addconst fn with_a8()
.My personal use case for it: I have a palette of predefined colors (think Gnome Colors), which I use as the basis for other default colors definitions (which is why I need 'const' ).
Related: the discussion that Color probably won't be anything else than u32 so the
const
is unlikely to become a problem in the future.With the same thought,
as_rgba_u32()
can then also converted to be const.I could also add analogous methods
with_r8()
,with_g8()
andwith_b8()
to the PR for completeness sake, if the idea is approved.