7 Commits

Author SHA1 Message Date
David Briscoe
7d99a08134 [Breaking] color: Convert hue [0,359] -> [0,1]
imgui [uses 0-1 for everything internally](
https://github.com/ocornut/imgui/blob/master/imgui.cpp#L2045).

[Both Unity](https://docs.unity3d.com/ScriptReference/Color.RGBToHSV.html)
[and Godot](https://docs.godotengine.org/en/stable/classes/class_color.html#class-color-property-h)
use H, S, and V in the range 0.0 to 1.0

Since we're switching colours out of 0,255 we should also switch hue out
of 0,359. Now all of our r,g,b,a,h,s,v values are all in 0,1.
2022-04-01 21:55:40 -07:00
David Briscoe
0c12f17805 color: Linear alpha in linear<->gamma conversions
Maintain linear alpha when converting to gamma.

Update to latest wikipedia links.

Add simple test that does the round trip conversion.
2022-04-01 21:55:40 -07:00
David Briscoe
41b1f0b5b9 color: Add more tests 2022-04-01 21:47:56 -07:00
David Briscoe
343f320e2f [Breaking] color: Convert 0-255 -> 0-1 range
Our hsv logic assumes 0-1 (cs.rit.edu says "r,g,b values are from 0 to
1") and it makes more sense to provide __mul for multiplying in 0-1
since the result will stay in that range. Additionally, love switched to
0-1 color since 11.0.

Included an as_255() function to unpack the color in 0-255 for some
amount of backwards compatibility. Doesn't make sense to provide any
kind of color object for it since most of our functions won't work
correctly.

Add tests for hue(), saturation(), value() that fail (even with /255
removed) for the old code, but pass on the new 0-1 range because the hsv
logic outputs colors in 0-1. Test comparisons use reduced precision
because my input data has limited precision.
2022-04-01 21:47:56 -07:00
David Briscoe
df92f0c5cd [Breaking] color: Make expected range match docs
lighten/darken: documented range is 0-255, so we don't need to multiply.
Makes more sense to work with colors in the same range that we're
incrementing by, but this changes behaviour.

saturation/value: we use a percent, so it's 0-1. It's clamped so that's
obviously expected.

Add tests to validate this new behaviour.
2022-04-01 21:47:09 -07:00
David Briscoe
509594aec2 color: Use color_mt and normal indexing
Fix #34.

Set color_mt on new colors so add, subtract, multiply, is_color work.

We don't use ffi for color (32cf0e8), so remove cdata check for 0-based
offset indexing.

Add tests for creating colours and using operators.
2022-04-01 19:55:55 -07:00
karai17
52814eed9f Added a few more specs, no new tests though 2016-07-25 02:07:24 -03:00