mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-09-07 02:46:39 +02:00
rudimentary area cache
This commit is contained in:
parent
31b83c6a1b
commit
b1237d3bae
1 changed files with 10 additions and 1 deletions
|
@ -39,9 +39,15 @@ function getPositionOfEntry(entry){
|
||||||
return [parseInt(startX), parseInt(startY)];
|
return [parseInt(startX), parseInt(startY)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const areaMap = new Map();
|
||||||
|
|
||||||
// Modified from https://stackoverflow.com/a/33670691
|
// Modified from https://stackoverflow.com/a/33670691
|
||||||
function calcPolygonArea(vertices) {
|
function calcPolygonArea(vertices) {
|
||||||
|
var hit = areaMap.get(vertices);
|
||||||
|
if (hit != null) {
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
var total = 0;
|
var total = 0;
|
||||||
|
|
||||||
for (var i = 0, l = vertices.length; i < l; i++) {
|
for (var i = 0, l = vertices.length; i < l; i++) {
|
||||||
|
@ -54,5 +60,8 @@ function calcPolygonArea(vertices) {
|
||||||
total -= (subX * subY * 0.5);
|
total -= (subX * subY * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.floor(Math.abs(total));
|
var area = Math.floor(Math.abs(total));
|
||||||
|
areaMap.set(vertices, area);
|
||||||
|
|
||||||
|
return area;
|
||||||
}
|
}
|
Loading…
Reference in a new issue