Skip to content

Commit

Permalink
Fix renderer background edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Nov 6, 2024
1 parent f71caaf commit dcc620a
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions renderer/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,26 @@ export function getBitMask(
x: number,
y: number,
outOfBoundToken = " ",
cmp = (x: string) => x === "R",
) {
let bitmask = 0;

for (let i = 0; i < neighborOffsets.length; i++) {
const [dx, dy] = neighborOffsets[i];
const token = map[y + dy]?.[x + dx] ?? outOfBoundToken;

if (token === "R") {
bitmask |= 1 << i;
}
}

return bitmask;
const [topLeft, top, topRight, left, right, bottomLeft, bottom, bottomRight] =
neighborOffsets.map(([dx, dy]) => map[y + dy]?.[x + dx] ?? outOfBoundToken);

const matchBottom = cmp(bottom);
const matchLeft = cmp(left);
const matchRight = cmp(right);
const matchTop = cmp(top);

return [
matchLeft && matchTop && cmp(topLeft),
matchTop,
matchRight && matchTop && cmp(topRight),
matchLeft,
matchRight,
matchLeft && matchBottom && cmp(bottomLeft),
matchBottom,
matchRight && matchBottom && cmp(bottomRight),
].reduce((acc, match, i) => (match ? acc | (1 << i) : acc), 0);
}

export async function generateBg(
Expand Down

0 comments on commit dcc620a

Please sign in to comment.