From 79168d35a4665d6ea8d0f2c8377b43f5e35003a0 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Mon, 27 May 2024 11:24:57 +0200 Subject: [PATCH] fix: cells ids can go over UINT16_MAX (v1.97.11) --- main.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 96b26c33..b53a86dc 100644 --- a/main.js +++ b/main.js @@ -1196,11 +1196,6 @@ function reGraph() { newCells.h.push(height); } - function getCellArea(i) { - const area = Math.abs(d3.polygonArea(getPackPolygon(i))); - return Math.min(area, UINT16_MAX); - } - const {cells: packCells, vertices} = calculateVoronoi(newCells.p, grid.boundary); pack.vertices = vertices; pack.cells = packCells; @@ -1208,7 +1203,10 @@ function reGraph() { pack.cells.g = createTypedArray({maxValue: grid.points.length, from: newCells.g}); pack.cells.q = d3.quadtree(newCells.p.map(([x, y], i) => [x, y, i])); pack.cells.h = createTypedArray({maxValue: 100, from: newCells.h}); - pack.cells.area = createTypedArray({maxValue: UINT32_MAX, from: pack.cells.i}).map(getCellArea); + pack.cells.area = createTypedArray({maxValue: UINT16_MAX, length: packCells.i.length}).map((_, cellId) => { + const area = Math.abs(d3.polygonArea(getPackPolygon(cellId))); + return Math.min(area, UINT16_MAX); + }); TIME && console.timeEnd("reGraph"); }