Merge pull request #16951 from Snuffleupagus/tweak-pattern-getB

Make it possible to clear the cache, used by the `getB` function in `src/core/pattern.js`
This commit is contained in:
Jonas Jenwald 2023-09-15 14:06:51 +02:00 committed by GitHub
commit 586d3add46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 23 deletions

View File

@ -13,10 +13,12 @@
* limitations under the License.
*/
import { clearPatternCaches } from "./pattern.js";
import { clearPrimitiveCaches } from "./primitives.js";
import { clearUnicodeCaches } from "./unicode.js";
function clearGlobalCaches() {
clearPatternCaches();
clearPrimitiveCaches();
clearUnicodeCaches();
}

View File

@ -411,29 +411,26 @@ class MeshStreamReader {
}
}
const getB = (function getBClosure() {
function buildB(count) {
const lut = [];
for (let i = 0; i <= count; i++) {
const t = i / count,
t_ = 1 - t;
lut.push(
new Float32Array([
t_ * t_ * t_,
3 * t * t_ * t_,
3 * t * t * t_,
t * t * t,
])
);
}
return lut;
}
const cache = Object.create(null);
let bCache = Object.create(null);
return function (count) {
return (cache[count] ||= buildB(count));
};
})();
function buildB(count) {
const lut = [];
for (let i = 0; i <= count; i++) {
const t = i / count,
t_ = 1 - t;
lut.push(
new Float32Array([t_ ** 3, 3 * t * t_ ** 2, 3 * t ** 2 * t_, t ** 3])
);
}
return lut;
}
function getB(count) {
return (bCache[count] ||= buildB(count));
}
function clearPatternCaches() {
bCache = Object.create(null);
}
class MeshShading extends BaseShading {
static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
@ -1005,4 +1002,4 @@ function getTilingPatternIR(operatorList, dict, color) {
];
}
export { getTilingPatternIR, Pattern };
export { clearPatternCaches, getTilingPatternIR, Pattern };