Repository navigation
Better handling of small rays - #773
facelessuser wants to merge 4 commits into
Conversation
Do not discount an axis just because distance is very small, but instead reject an entire ray if all axes have very small distances. Fixes issue, most often with very small rays near white and black, that exited improperly causing the colors to not be correct. A note was added that an offset of 1e-5 for anchor adjustment may be preferable as real world tests have shone that math functions on various systems may be more coarse, and produce more noise than 1e-6 can handle. In tests, it seems this adjustment is only needed for the offset related to moving the anchor closer to the gamut surface. The cutoff for ray distance in `raytrace_box` is currently still recommended to be 1e-6. Issues found by @lloydk
✅ Deploy Preview for colorjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
For more context, see the discussion between @lloydk and me over at this ColorAide issue: facelessuser/coloraide#529. |
|
I had Claude review the PR: I checked this against near-black, near-white and just-outside-gamut sweeps in sRGB, P3 and Rec.2020, with the cast instrumented to flag any ray that lands outside the RGB cube. On Only one of the new tests fails without the fix: // sRGB
{
args: ["oklch(0.0000951210968196392 0.41658416169229895 328.082845620811)"],
expect: "rgb(0% 0% 0%)",
},
// P3
{
args: ["oklch(0.0001220703125 0.4 19.5)"],
expect: "color(display-p3 0 0 0)",
},
// Rec. 2020
{
args: ["oklch(0.0001220703125 0.4 17)"],
expect: "color(rec2020 0 0 0)",
},Two small things:
|
|
I've updated whitespace, spelling, and added the additional tests that target the Color.js implementation more specifically. As there are a lot of things that influence the noise between different implementations, it is good to have tests that specifically target this implementation. |
|
LGTM |
Do not discount an axis just because distance is very small, but instead reject an entire ray if all axes have very small distances.
Fixes issue, most often with very small rays near white and black, that exited improperly causing the colors to not be correct.
A note was added that an offset of 1e-5 for anchor adjustment may be preferable as real world tests have shone that math functions on various systems may be more coarse, and produce more noise than 1e-6 can handle. In tests, it seems this adjustment is only needed for the offset related to moving the anchor closer to the gamut surface. The cutoff for ray distance in
raytrace_boxis currently still recommended to be 1e-6.Issues found by @lloydk