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

Fix hue related mix issues #338

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export function mix (c1, c2, p = .5, o = {}) {
[p, o] = [.5, p];
}

let {space, outputSpace, premultiplied} = o;

let r = range(c1, c2, {space, outputSpace, premultiplied});
let r = range(c1, c2, o);
return r(p);
}

Expand Down Expand Up @@ -167,6 +165,15 @@ export function range (color1, color2, options = {}) {

let hue = [space, "h"];
let [θ1, θ2] = [get(color1, hue), get(color2, hue)];
// Undefined hues must be evaluated before hue fix-up to properly
// calculate hue arcs between undefined and defined hues.
// See https://github.com/w3c/csswg-drafts/issues/9436#issuecomment-1746957545
if (isNaN(θ1) && !isNaN(θ2)) {
θ1 = θ2;
}
else if (isNaN(θ2) && !isNaN(θ1)) {
θ2 = θ1;
}
[θ1, θ2] = angles.adjust(arc, [θ1, θ2]);
set(color1, hue, θ1);
set(color2, hue, θ2);
Expand Down