From b1237d3bae66c52ee6399270c8abb31b7f0b8b9c Mon Sep 17 00:00:00 2001 From: Tonny2442 Date: Wed, 6 Apr 2022 15:31:21 -0400 Subject: [PATCH] rudimentary area cache --- web/_js/atlas.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/_js/atlas.js b/web/_js/atlas.js index 92bada94..dc60e0de 100644 --- a/web/_js/atlas.js +++ b/web/_js/atlas.js @@ -39,9 +39,15 @@ function getPositionOfEntry(entry){ return [parseInt(startX), parseInt(startY)]; } +const areaMap = new Map(); // Modified from https://stackoverflow.com/a/33670691 function calcPolygonArea(vertices) { + var hit = areaMap.get(vertices); + if (hit != null) { + return hit; + } + var total = 0; for (var i = 0, l = vertices.length; i < l; i++) { @@ -54,5 +60,8 @@ function calcPolygonArea(vertices) { total -= (subX * subY * 0.5); } - return Math.floor(Math.abs(total)); + var area = Math.floor(Math.abs(total)); + areaMap.set(vertices, area); + + return area; } \ No newline at end of file