Skip to content

Ensure saturation/lightness between 0 and 1#4

Open
adamrutter wants to merge 1 commit intoyuri:masterfrom
adamrutter:bugfix
Open

Ensure saturation/lightness between 0 and 1#4
adamrutter wants to merge 1 commit intoyuri:masterfrom
adamrutter:bugfix

Conversation

@adamrutter
Copy link

The current Color:desaturate_by() function allows you to multiply the saturation value of the color to greater than 1, and less than 0. The result is obviously invalid colors being returned in such cases. See:

local color = Color.new("#ff0000")
local saturated_color = color:desaturate_by(1.1)
print(tostring(saturated_color)) -- result: #10cfffffffffffffff3fffffffffffffff3

The same goes for Color:lighten_by():

local color = Color.new("#ffffff")
local lighter_color = color:lighten_by(1.1)
print(tostring(lighter_color)) -- result: #119119119

I've added a couple of checks to each function so now:

print(tostring(saturated_color)) -- result: #ff0000
print(tostring(lighter_color)) -- result: #ffffff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant