- From: Dan Burzo via GitHub <sysbot+gh@w3.org>
- Date: Mon, 28 Mar 2022 20:38:07 +0000
- To: public-css-archive@w3.org
Here are the two algorithms, shown as a diff for clearer comparison:
```diff
+let lower_bound_in_gamut = true;
let start = 0;
let end = candidate.c;
let ε = 0.001;
let e;
while (end - start > ε) {
candidate.c = (start + end) * 0.5;
- if (inGamut(candidate)) {
+ if (inGamut(candidate) && lower_bound_in_gamut) {
start = candidate.c;
} else {
clipped = clipToGamut(candidate);
e = delta(candidate, clipped);
if (e <= jnd) {
- start = candidate.c;
+ if (jnd - e < ε) {
+ return clipped;
+ } else {
+ lower_bound_in_gamut = false;
+ start = candidate.c;
+ }
} else {
end = candidate.c;
}
```
They converge to the same solution, but your proposed version has the following optimizations:
* when we've left the gamut, the `lower_bound_in_gamut` flag prevents further gamut computations, which we know they're going to return false from now on
* if you happen to land very close to the upper bound of the out-of-gamut-but-within-JND range, return early instead of letting the binary search converge to the same solution.
--
GitHub Notification of comment by danburzo
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7135#issuecomment-1081118244 using your GitHub account
--
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 28 March 2022 20:38:09 UTC