color icon indicating copy to clipboard operation
color copied to clipboard

Add an option to keep the alpha/a in a RGBA object return

Open Nukiloco opened this issue 3 years ago • 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!

Nukiloco avatar Aug 08 '21 09:08 Nukiloco

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.

Qix- avatar Aug 24 '21 17:08 Qix-

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;
}  

headwindz avatar Dec 22 '21 15:12 headwindz