Add an option to keep the alpha/a in a RGBA object return
Nukiloco opened this issue · 2 comments
When for example the alpha is set to 1 in an RGBA object return, the alpha
/a
variable disappears. I know this is a part of the design of the library though this means that there has to be extra code checking to make sure the variable isn't missing before using it. Can there be an option where the RGBA object keeps it's alpha
/a
variable? Thanks!
Yes that's strange, I think I remember the reasoning for it back then but it doesn't make much sense these days.
It should be changed, but I'm going to consider it a breaking change given how many people (mis)use this library.
I think a way to get this solved with backward compatibility is to add a third paramater to Color
constructor which indicates whether we want to always keeps the alpha/a
variable . E.g.
function Color(object, model, alwaysKeepAlpha = false) {
this.alwaysKeepAlpha = alwaysKeepAlpha;
}
Then in the corresponding code, do:
if (this.alwaysKeepAlpha || (!this.alwaysKeepAlpha && this.valpha !== 1)) {
result.alpha = this.valpha;
}