https://kotlinlang.org logo
#compose
Title
# compose
g

Grigorii Yurkov

11/12/2020, 12:48 PM
I am wondering, why
Color
has 3 properties named
red
green
blue
if
Color
can store non-RGB colors, for instance HSV. Isn't it confusing?
c

caelum19

11/12/2020, 1:05 PM
Looks like the only things stored are 1 int packed with 4 values and which ColorSpace is used
the red, green and blue vals have overridden getters and so don't actually store anything but provide a way of extracting those values from the int
g

Grigorii Yurkov

11/12/2020, 1:10 PM
I don't care about internal implementation. I am wondering why they named properties as they named
c

caelum19

11/12/2020, 1:18 PM
I suppose for convenience? Seems you can get the components used in the model without mentioning those colours with the component1...4 properties. It does seem a little less safe after looking into it, in case someone was unaware of the color space and expected "red" to mean it has an rgb color space and they got back a component from another model
maybe an exception should be thrown if the model isn't rgb? Maybe I'm missing something
g

Grigorii Yurkov

11/12/2020, 1:21 PM
maybe an exception should be thrown if the model isn't rgb?
No it should not
Copy code
* If this color's color model is not [RGB][ColorModel.Rgb],
* calling this is the first component of the ColorSpace.
This is
red
property documentation
c

caelum19

11/12/2020, 1:23 PM
Yeah that's the part that seems too implicit to me, as it seems it doesn't actually derive what the red value would be from the actually used model and just returns the first component
I think we agree the naming could lead to confusion
👌 1