Skip to content

Commit

Permalink
Fix hue related mix issues (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser authored Oct 11, 2023
1 parent 6a3535a commit d8ffbee
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit d8ffbee

Please sign in to comment.