Skip to content

Commit

Permalink
Rebase accounting for null changes
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Aug 26, 2024
1 parent b34f781 commit 61d0f70
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/spaces/oklrab.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default new ColorSpace({

// Note that XYZ is relative to D65
white: "D65",

base: OKLab,
fromBase (oklab) {
return [toe(oklab[0]), oklab[1], oklab[2]];
Expand Down
42 changes: 3 additions & 39 deletions src/spaces/oklrch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import ColorSpace from "../space.js";
import OKLrab from "./oklrab.js";
import {toe, toeInv} from "./okhsl.js";
import {constrain as constrainAngle} from "../angles.js";
import {isNone} from "../util.js";
import lch from "./lch.js";

export default new ColorSpace({
id: "oklrch",
Expand All @@ -25,42 +23,8 @@ export default new ColorSpace({
white: "D65",

base: OKLrab,
fromBase (oklab) {
// Convert to polar form
let [L, a, b] = oklab;
let h;
const ε = 0.0002; // chromatic components much smaller than a,b

if (Math.abs(a) < ε && Math.abs(b) < ε) {
h = NaN;
}
else {
h = Math.atan2(b, a) * 180 / Math.PI;
}

return [
L, // OKLab L is still L
Math.sqrt(a ** 2 + b ** 2), // Chroma
constrainAngle(h), // Hue, in degrees [0 to 360)
];
},
// Convert from polar form
toBase (oklch) {
let [L, C, h] = oklch;
let a, b;

// check for NaN hue
if (isNone(h)) {
a = 0;
b = 0;
}
else {
a = C * Math.cos(h * Math.PI / 180);
b = C * Math.sin(h * Math.PI / 180);
}

return [ L, a, b ];
},
fromBase: lch.fromBase,
toBase: lch.toBase,

formats: {
"color": {
Expand Down
2 changes: 1 addition & 1 deletion test/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ const tests = {
{
name: "sRGB white (D65) to OKlrch",
args: "white",
expect: [1.0, 0.0, NaN],
expect: [1.0, 0.0, null],
},
{
name: "sRGB red (D65) to OKlrch",
Expand Down

0 comments on commit 61d0f70

Please sign in to comment.