Qix-/color

Do you want to work on this issue?

You can request for a bounty in order to promote it!

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

Nukiloco posted onGitHub

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.

posted by Qix- over 3 years ago

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;
}  
posted by n0ruSh over 3 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests