Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected colours from BlendFoo() #11

Closed
quite opened this issue Feb 23, 2017 · 3 comments
Closed

Unexpected colours from BlendFoo() #11

quite opened this issue Feb 23, 2017 · 3 comments

Comments

@quite
Copy link

quite commented Feb 23, 2017

I'd expect all these to print #1a1a46, but they don't. I does matter what colour c2 is, so I think this would take some broader testing initially. Also, for example c1 as #1a1a00 gives yields expected result.

func main() {
	c1, _ := colorful.Hex("#1a1a46")
	c2, _ := colorful.Hex("#666666")

	fmt.Printf("%s\n", c1.BlendHsv(c2, 0).Hex())
	fmt.Printf("%s\n", c1.BlendLuv(c2, 0).Hex())
	fmt.Printf("%s\n", c1.BlendRgb(c2, 0).Hex())
	fmt.Printf("%s\n", c1.BlendLab(c2, 0).Hex())
	fmt.Printf("%s\n", c1.BlendHcl(c2, 0).Hex())
}
#461a1a
#1a1a46
#1a1a46
#1a1a46
#440320
@lucasb-eyer
Copy link
Owner

lucasb-eyer commented Feb 23, 2017

Thank you, great report! Since only Hsv (you don't want to use that) and Hcl are wrong, and only for some second colors, it indicates the error probably lies in one of these angular branches. I'll have a look.

@lucasb-eyer
Copy link
Owner

I found what I think is a better (and hopefully correct) formula for angular interpolation. I don't remember where I got the original from or if I made it up myself, but it was wrong for some pairs of angles.

I added unit-tests based on your snippet, but it only tests that both extremes of the interpolation are correct, which they now are. I'm not sure where I could get values from for testing intermediate values during the interpolation, if you know a trustworthy source we could add another table-based test for that.

But anyways, please give the new code a try and let me know. Feel free to reopen this issue should you find more interpolation problems!

@lucasb-eyer
Copy link
Owner

Added some more tests in a follow-up commit so we can be a little more confident that it's correct now 😄

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

No branches or pull requests

2 participants