Correct the number of colors returned by quantize#10
Correct the number of colors returned by quantize#10ijambro wants to merge 3 commits intoolivierlesnicki:masterfrom
Conversation
… even for values > 7
…of all palettes, given a variety of inputs
|
I created Mocha tests for the quantize function, asserting that the format of all returned palettes is valid, for a variety of inputs. For each of the tests below, I run it using many values of maximumColorCount between 2 and 256: The most interesting results are how the returned ("Actual") count of colors lines up with the requested ("Expected") maximum color count. Using the current quantize code: Using my proposed change, adding "+ 1" to current quantize code line 474: Two conclusions:
|
|
After testing AlfredJKwack's change from #6 , I've seen that it returns the exact count of colors requested for all input values between 2 and 256! I've replaced my partial correction with his superior fix. |
|
+1 for this! |
|
and, if anyone else stumbles across this I have a fork with this pull request, which seems to fix the issue, implemented here: |


Closes #9
The number of colors returned by quantize should match maxcolors, including for values > 7.
I've tested this fix using a test.js from a separate project that requires quantize, for many values ranging from 1 to 256, and this fix corrects the off-by-one color count.
A test.js and a Readme update would help to support this Pull Request. Let me know if you're interested.
Curious if anyone else has noticed or investigated this behavior?