From 905605f3d1a758d66d503d13f5bd7f0bdf7ea62c Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Wed, 19 May 2021 01:09:52 -0500 Subject: [PATCH 1/3] Add maximum triangle size configuration --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e93a9f3..4205127 100644 --- a/index.js +++ b/index.js @@ -92,13 +92,17 @@ class Tile { } } - getMesh(maxError = 0) { + getMesh(maxError = 0, maxLength = null) { const {gridSize: size, indices} = this.martini; const {errors} = this; let numVertices = 0; let numTriangles = 0; const max = size - 1; + // The maxLength parameter will cause triangles to be generated until the legs are below this length + // It is meant to support cases where a certain mesh density is required to do spherical math on digital globes + const maxScale = maxLength || size + // use an index grid to keep track of vertices that were already used to avoid duplication indices.fill(0); @@ -110,7 +114,8 @@ class Tile { const mx = (ax + bx) >> 1; const my = (ay + by) >> 1; - if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) { + const legLength = Math.abs(ax - cx) + Math.abs(ay - cy) + if ((legLength > 1 && errors[my * size + mx] > maxError) || legLength > maxScale) { countElements(cx, cy, ax, ay, mx, my); countElements(bx, by, cx, cy, mx, my); } else { @@ -131,7 +136,8 @@ class Tile { const mx = (ax + bx) >> 1; const my = (ay + by) >> 1; - if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) { + const legLength = Math.abs(ax - cx) + Math.abs(ay - cy); + if (legLength > 1 && errors[my * size + mx] > maxError) || legLength > maxScale) { // triangle doesn't approximate the surface well enough; drill down further processTriangle(cx, cy, ax, ay, mx, my); processTriangle(bx, by, cx, cy, mx, my); From 7fc6149b47f457fb44ccf13de166ff4547dec89b Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Wed, 19 May 2021 01:24:44 -0500 Subject: [PATCH 2/3] Fix typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4205127..b049bcf 100644 --- a/index.js +++ b/index.js @@ -137,7 +137,7 @@ class Tile { const my = (ay + by) >> 1; const legLength = Math.abs(ax - cx) + Math.abs(ay - cy); - if (legLength > 1 && errors[my * size + mx] > maxError) || legLength > maxScale) { + if ((legLength > 1 && errors[my * size + mx] > maxError) || legLength > maxScale) { // triangle doesn't approximate the surface well enough; drill down further processTriangle(cx, cy, ax, ay, mx, my); processTriangle(bx, by, cx, cy, mx, my); From b90ba22822b0e93082ae7123c7df85d28f6429cb Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Wed, 19 May 2021 01:29:37 -0500 Subject: [PATCH 3/3] Add semicolons --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b049bcf..604b8eb 100644 --- a/index.js +++ b/index.js @@ -101,7 +101,7 @@ class Tile { // The maxLength parameter will cause triangles to be generated until the legs are below this length // It is meant to support cases where a certain mesh density is required to do spherical math on digital globes - const maxScale = maxLength || size + const maxScale = maxLength || size; // use an index grid to keep track of vertices that were already used to avoid duplication indices.fill(0); @@ -114,7 +114,7 @@ class Tile { const mx = (ax + bx) >> 1; const my = (ay + by) >> 1; - const legLength = Math.abs(ax - cx) + Math.abs(ay - cy) + const legLength = Math.abs(ax - cx) + Math.abs(ay - cy); if ((legLength > 1 && errors[my * size + mx] > maxError) || legLength > maxScale) { countElements(cx, cy, ax, ay, mx, my); countElements(bx, by, cx, cy, mx, my);