map/mapPatchContext.js
2026-05-30 03:25:19 +09:00

24 lines
865 B
JavaScript

export function createPatchContext({ world, rects, candidateWindow, seed, patchAlpha, sourceIndexForWorld, worldIndex }) {
const writeRect = rects?.writeRect;
const writeCells = [];
if (world && writeRect && typeof patchAlpha === "function" && typeof sourceIndexForWorld === "function" && typeof worldIndex === "function") {
for (let y = writeRect.y0; y < writeRect.y1; y++) {
for (let x = writeRect.x0; x < writeRect.x1; x++) {
const wi = worldIndex(world, x, y);
if (wi < 0) continue;
const si = sourceIndexForWorld(rects, candidateWindow, x, y);
if (si < 0) continue;
const alpha = patchAlpha(x, y, rects, seed);
if (alpha <= 0.005) continue;
writeCells.push({ x, y, wi, si, alpha });
}
}
}
return {
world,
rects,
candidateWindow,
seed,
writeCells,
};
}