Repository navigation
[interpolation] Fix steps using deltaEMethod inconsistently - #740
Conversation
β Deploy Preview for colorjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
I feel like this should have a test representing what previously failed but is now working due to the fix. |
|
Makes sense! I've been trying to write one, but I need some advice regarding the test runner. Since the I couldn't find an existing solution in the other tests, or an intended approach in the Details// test/interpolation.js
import { ColorSpace, OKLCH, steps } from "../src/index-fn.js";
let originalRegistry;
export default {
name: "Interpolation Tests",
tests: [
{
name: "steps",
tests: [
{
name: "One more level",
tests: [
{
name: "No error",
beforeAll () {
originalRegistry = ColorSpace.registry;
ColorSpace.registry = {};
},
afterAll () {
ColorSpace.registry = originalRegistry;
},
beforeEach () {
ColorSpace.registry = {};
this.data.colorSpaces.forEach(space => {
ColorSpace.register(space);
});
},
run (first, second) {
steps(first, second);
},
tests: [
{
name: "first",
data: {
colorSpaces: [OKLCH],
},
args: [
{ space: "oklch", coords: [1, 0, 360], alpha: 1 },
{ space: "oklch", coords: [0, 0, 0], alpha: 1 },
],
},
],
},
],
},
],
},
],
}; |
|
I'd probably just use something like this: // test/interpolation.js
import Color from "../src/index.js";
import * as check from "../node_modules/htest.dev/src/check.js";
export default {
name: "Interpolation Tests",
check: check.deep(check.proximity({ epsilon: 0.00001 })),
tests: [
{
name: "steps",
tests: [
{
name: "One more level",
tests: [
{
name: "No error",
run (first, second, options) {
const colors = new Color(first).steps(first, options).map(c => {return c.coords});
return colors;
},
tests: [
{
name: "first",
args: [
{ space: "oklch", coords: [1, 0, 360], alpha: 1 },
{ space: "oklch", coords: [1, 0, 0], alpha: 1 },
{ space: "oklch", steps: 3, hue: "longer", deltaEMethod: "OK" }
],
expect: [[1, 0, 0], [1, 0, 180], [1, 0, 360]]
},
],
},
],
},
],
},
],
}; |
|
That unfortunately doesn't test what this PR fixes. As I said, the issue only happens while the Here's a minimal reproduction: // example.mjs
import { ColorSpace, OKLCH, steps } from "colorjs.io/fn"
ColorSpace.register(OKLCH)
steps({ space: "oklch", coords: [1, 0, 360], alpha: 1 }, { space: "oklch", coords: [0, 0, 0], alpha: 1 }, {
deltaEMethod: "OK2"
})If you save this as |
|
Ah, I guess I didn't look super close at the issue it's fixing. |
|
No problem! :) I still think a regression test would make sense if there's some clean way to do the override, but relying on nesting levels seems too brittle. If someone can recommend a solution, I'll be happy to add the test case! |
|
Yeah, I'll take a closer look when I get a chance, assuming someone doesn't answer your question before I do. |
Fixes #632
I stumbled over the same issue. Due to my limited experience with color stuff I'm not sure this fix is correct, especially since this comment mentions that some parts might already have been fixed, which I can't find - but this change fixes the error, the resulting colors look roughly as I'd expect them to, and the same amount of tests pass with and without.
Hope this is useful!