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

Make longer and undefined/same hues have parity with CSS spec #474

Merged
merged 3 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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],
},
],
};