Skip to content

Conversation

0xJonas
Copy link
Contributor

@0xJonas 0xJonas commented Jul 15, 2021

Changes:

When using the setRed()/setGreen()/setBlue()/setAlpha() methods of p5.Color, cached HSL and HSB values are not cleared properly. This leads to the following bug:

const c = color(255, 0, 0);
console.log(lightness(c)) // 50
c.setRed(0);
console.log(lightness(c)); // bug: still 50

The first call to lightness() computes the HSL values and caches them, the second call retrieves the cached values even though the RGB values have changed. The fix is simple: Clear the hsba and hsla fields of p5.Color when calling setRed()/setGreen()/setBlue()/setAlpha().

PR Checklist

  • npm run lint passes
  • [Inline documentation] is included / updated
  • [Unit tests] are included / updated

@welcome
Copy link

welcome bot commented Jul 15, 2021

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@ecridge
Copy link
Contributor

ecridge commented Sep 4, 2021

Nice catch!

It might be better to test that the value returned from lightness(c) changes when you call c.setRed(100) etc (rather than looking at the caches directly), but either way this LGTM – thanks :)

@lmccart lmccart merged commit f6c6daf into processing:main Mar 2, 2022
@montoyamoraga
Copy link
Member

@all-contributors please add @0xJonas for bug

@allcontributors
Copy link
Contributor

@montoyamoraga

I've put up a pull request to add @0xJonas! 🎉

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.

4 participants