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

Should we take short path in interpolateAngle? #33

Open
safareli opened this issue Aug 31, 2017 · 6 comments
Open

Should we take short path in interpolateAngle? #33

safareli opened this issue Aug 31, 2017 · 6 comments

Comments

@safareli
Copy link
Contributor

I came to this question lately when I saw gradient which was going over hue cycle 5 times here
screen shot 2017-08-31 at 9 33 49 pm
as we can't have similar scale because of the "short path" thing

@sharkdp
Copy link
Collaborator

sharkdp commented Aug 31, 2017

Well, using mixCubehelix, this should work, right?

Concerning mix, I'm not sure if it's a good idea. We would loose the symmetry mix a b n = mix b a (1 - n) (or similar 😄).

@safareli
Copy link
Contributor Author

using custom interpolation function it will work. if a.hue = 0 and b.hue = 720 and interpolateAngle is just a linear interpolation then mix a b n = mix b a (1 - n) isn't it? how would we loose that symmetry

@sharkdp
Copy link
Collaborator

sharkdp commented Aug 31, 2017

True.

But we would certainly loose the ability to interpolate between two colors in the shortest possible way (in HSL space).

Right now:

> midpoint = mix HSL (hsl 10.0 1.0 0.5) (hsl 350.0 1.0 0.5) 0.5
> (toHSLA midpoint).h
360.0

If we would use normal linear interpolation, we would get a hue of 180°.

@safareli
Copy link
Contributor Author

Yes but is short path always desired?

If I want short path mix I would have done this:
mix HSL (hsl 10.0 1.0 0.5) (hsl -10.0 1.0 0.5)

but by restricting to always use short path now i can't do
mix HSL (hsl 10.0 1.0 0.5) (hsl 350.0 1.0 0.5) such it that it contains 180

@sharkdp
Copy link
Collaborator

sharkdp commented Aug 31, 2017

Good points.

This is pretty much the question whether we treat the HSL space as being periodic (in the hue-dimension) or as being infinite (also allowing multiple turns, as illustrated below).

One possible option could be to add a HSLNonPeriodic color space that would have the desired mix implementation.. not sure if that's a good idea ;-)

@safareli
Copy link
Contributor Author

safareli commented Sep 1, 2017

btw if toHSLA returned unclipped hue, an if a.hue as 0 and b.hue 720 then short path found by current algorithm will have been { from: a + 360.0, to: b}.

not sure,

also in complementary = rotateHue 180.0 we might want to get same color if we do it twice but we wouldn't.

maybe we can add normalize function which clips hue to 360 range.

will think on it a bit more

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

No branches or pull requests

2 participants