Skip to content

Commit

Permalink
Make longer and undefined/same hues have parity with CSS spec (#474)
Browse files Browse the repository at this point in the history
* Make longer and undefined have parity with CSS spec

* Don't correct hues until after raw angles are returned

* Doesn't just apply to undefined
  • Loading branch information
facelessuser committed Mar 14, 2024
1 parent e3a0a0d commit c8207e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/angles.js
@@ -1,13 +1,31 @@
import * as util from "./util.js";

export function constrain (angle) {
return ((angle % 360) + 360) % 360;
}

export function adjust (arc, angles) {
let [a1, a2] = angles;

let none1 = util.isNone(a1);
let none2 = util.isNone(a2);

if (none1 && none2) {
return [a1, a2];
}
else if (none1) {
a1 = a2;
}
else if (none2) {
a2 = a1;
}

if (arc === "raw") {
return angles;
}

let [a1, a2] = angles.map(constrain);
a1 = constrain(a1);
a2 = constrain(a2);

let angleDiff = a2 - a1;

Expand Down
10 changes: 10 additions & 0 deletions test/angles.js
Expand Up @@ -31,5 +31,15 @@ export default {
args: ["raw", [-20, 380]],
expect: [-20, 380],
},
{
name: "Longer and Undefined",
args: ["longer", [90, NaN]],
expect: [90, 450],
},
{
name: "Longer and Same Hues",
args: ["longer", [90, 90]],
expect: [90, 450],
},
],
};

0 comments on commit c8207e1

Please sign in to comment.