CodingTrain / CodingTrain/Wave-Function-Collapse

Simple way to remove duplicated tiles to improve performance

Aperta
#24 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
218
Fork
64
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi :smiley: We can write a function to get only the unique tiles in an array :

```js
function removeDuplicatedTiles(tiles) {
const uniqueTilesMap = {};
for (const tile of tiles) {
const key = tile.edges.join(","); // ex: "ABB,BCB,BBA,AAA"
uniqueTilesMap[key] = tile;
}
return Object.values(uniqueTilesMap);
}
```

So we can apply rotations to all the tiles and then keep only the unique ones :
```js
const initialTileCount = tiles.length;
for (let i = 0; i < initialTileCount; i++) {
for (let j = 1; j < 4; j++) {
tiles.push(tiles[i].rotate(j));
}
}
tiles = removeDuplicatedTiles(tiles);
```

In our case, we have **13** images. By rotating all of them, we get **52**. And by removing the duplicates, we get down to **33**.

On my PC, the generation time goes from **23s** to **14s** :rocket:

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.