CodingTrain / CodingTrain/Wave-Function-Collapse

Simple way to remove duplicated tiles to improve performance

未關閉
#24 6 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
218
分支
64
PR 合併指標
30 天內沒有已合併 PR

描述

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:

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

未指定檔案或測試。先定位 tile 生成與旋轉邏輯,然後將目前的 tile 數量和生成時間與提議的去重步驟進行比較;完成標準是移除重複的旋轉 tile,同時不改變最終得到的唯一 tile 集合。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript
領域
performance
Issue 類型
重構
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。