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

hue: "longer" interpolates in reverse order when colors have hues that differ by multiples of 360 #156

Closed
LeaVerou opened this issue Jun 25, 2022 · 2 comments · Fixed by #281
Assignees
Labels
bug Something isn't working

Comments

@LeaVerou
Copy link
Member

Testcase:

let color1 = new Color("lch", [50, 50, 0]);
let color2 = new Color("lch", [50, 50, 360]);
let steps = Color.steps(color1, color2, {space: "lch", steps: 10, hue: "longer"});
console.log(steps.map(c => c.coords[2]));

Outputs:

[360, 320, 280, 240, 200, 160, 120, 80.00000000000006, 40, 0]

It should instead output:

[0, 40, 80.00000000000006, 120, 160, 200, 240, 280, 320, 360]
@LeaVerou LeaVerou added the bug Something isn't working label Jun 25, 2022
@LeaVerou
Copy link
Member Author

I made a page with tests so we can iterate on the algorithm, then hopefully backport it to Color 4: https://colorjs.io/tests/angles.html

@LeaVerou LeaVerou changed the title hue: "longer" interpolates in reverse order hue: "longer" interpolates in reverse order when colors have hues that differ by 360 Jun 26, 2022
@LeaVerou LeaVerou changed the title hue: "longer" interpolates in reverse order when colors have hues that differ by 360 hue: "longer" interpolates in reverse order when colors have hues that differ by multiples of 360 Jun 26, 2022
@svgeesus
Copy link
Member

svgeesus commented Jul 2, 2022

Nice tests.

I think it helps, for this -20 380 case, to consider the least surprise if we are actually animating from, say, -18 to -22. We want a consistent interpolation direction, not a discontinuity or reversal as we pass through "angular difference mod 360 is zero".

I also think (by analogy with the "zero length vector has no direction" problem in geometry) that the algorithm should extract a direction before all the angle fix-up happens

facelessuser added a commit to facelessuser/color.js that referenced this issue Feb 6, 2023
svgeesus pushed a commit that referenced this issue Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants