Public
Edited
Nov 6, 2023
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function tilePlacements(tile, w, h) {
// Get all flipped and rotated variations.
const perms = tilePermutations(tile);
const placements = new BigUint64Array(w * h * perms.length);
let idx = 0;
for(const perm of perms) {
const {width, height} = perm;
for(let dy=0; dy < h - height + 1; ++dy) {
for(let dx=0; dx < w - width + 1; ++dx) {
perm.pack(placements, {idx, dx, dy});
idx++;
}
}
}
// Return a trimmed array of packed values.
return placements.slice(0, idx);
}
Insert cell
function tilePermutations(tile) {
const {height, width, at} = tile;
const size = Math.max(height, width), s = size - 1;
const perms = [ ];
for(const flip of [
([i,j]) => [i,j], // normal
([i,j]) => [j,i] // flipped
]) {
for(const rotate of [
([i,j]) => [i,j], // normal
([i,j]) => [j,s-i], // rotate 90
([i,j]) => [s-i,s-j], // rotate 180
([i,j]) => [s-j,i] // rotate 270
]) {
let values = new Uint8Array(size * size);
for(let i=0; i < height; ++i) {
for(let j=0; j < width; ++j) {
if(tile.at(i,j)) {
//if(at(i,j)) {
const [i2,j2] = flip(rotate([i,j]));
values[i2*size + j2] = 1;
}
}
}
const perm = new PixelData(size, size, values.slice()).squeezed();
// Check that this permutation is new.
let isNew = true;
for(const old of perms) if(perm.isEqualTo(old)) {
isNew = false;
break;
}
if(isNew) perms.push(perm);
}
}
return perms;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more