adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 125 forks source link

color: Implement floating-point representation struct #407

Closed 0xEAB closed 6 months ago

0xEAB commented 6 months ago

Adds floating-point color representation wrapper struct (with contracts) to arsd.color.

Use case

auto clear = ColorF(backgroundColor);
glClearColor(clear.r, clear.g, clear.b, clear.a);

Correct me, if there’s something better for this already in there.

adamdruppe commented 6 months ago

This seems ok enough, I just normally do the division but it is a bit lossy to store it that way (the minigui color widget has some hacks to deal with the lossy conversions so it doesn't break the ui, it is p hacky lol).

adamdruppe commented 6 months ago

I've always avoided using that in(expr) thing because it wasn't compatible with older compilers, but I think I've dropped support for them now... my old raspberry pi even i think uses a newer gdc now. But if that fails I'll just edit.

Another potential future direction would be to template some of this for other types but I'm not sure it is worth the complication, so let's just do this, if needed we can do compatibility aliases later.

0xEAB commented 6 months ago

Note that there’s an embarrassing bug in here. Gonna send another PR :/