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

BlendHcl() edge cases slightly off #46

Open
khughitt opened this issue Aug 2, 2020 · 2 comments
Open

BlendHcl() edge cases slightly off #46

khughitt opened this issue Aug 2, 2020 · 2 comments

Comments

@khughitt
Copy link

khughitt commented Aug 2, 2020

Greetings!

I've been experimenting with go-colorful and noticed that for the edge cases (t = 0 and t = 1), the resulting colors are actually slightly different from what is suggested.

For example:

a,err = colorful.Hex("#ff0000")
b,err = colorful.Hex("#00ff00")

a.BlendHcl(b, 0)
// colorful.Color{
//   R: 1.000000,
//   G: 0.000002,
//   B: -0.000000,
// }

a.BlendHcl(b, 1)
// colorful.Color{
//  R: 0.000001,
//  G: 1.000000,
//  B: -0.000000,
//}

Where as I would expect G to be 0.0 in the first case, and R to be 0.0 in the later case. Also, from the negative sign assigned to "B", I'm guessing that both of those are slightly off as well.

Is it possible that there is an off-by-one error somewhere?

If not, and the interpolation calculations simply don't allow this kind of precise generation of boundary cases, a minor / simple improvement might be to clip all resulting colors so that the RGB vals fall within [0, 1]?

If I have the time down the road, I will try and look into it myself, but I'm still only just learning Go, so it may be a little while :)

Thanks for your work on this great package!

makew0rld added a commit that referenced this issue Jan 27, 2021
@makew0rld
Copy link
Collaborator

Hello, thanks for reporting this! I'll have to look into the package more deeply to see where this error is coming from. For now I have clamped the output of BlendHCL in d49a4a4, and this will be in the next release.

It's worth noting that the errors you've noticed are well below 1/256, and so will not have any effect on the displayed RGB values.

@khughitt
Copy link
Author

Sounds good! And thanks for the clarification.

I definitely wouldn't spend a lot of time tracking this down if the origin isn't obvious and it doesn't ultimately have any impact on the output.

Perhaps something to keep in mind the next time you are working on that part of the code :)

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