← back to Voronoi Shatter
chore: guard centroid() against empty polygon (session close)
062b60715bd0abcad43b8615480f2a970a0b088b · 2026-07-24 23:45:23 -0700 · Steve
Defensive n===0 guard so centroid never emits NaN into gradient/arc math.
Both lint + refactor review passes otherwise found the code clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Files touched
Diff
commit 062b60715bd0abcad43b8615480f2a970a0b088b
Author: Steve <steve@designerwallcoverings.com>
Date: Fri Jul 24 23:45:23 2026 -0700
chore: guard centroid() against empty polygon (session close)
Defensive n===0 guard so centroid never emits NaN into gradient/arc math.
Both lint + refactor review passes otherwise found the code clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---
index.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/index.html b/index.html
index fbbfc7e..a32f9f2 100644
--- a/index.html
+++ b/index.html
@@ -394,6 +394,7 @@
function centroid(poly) {
var a = 0, cx = 0, cy = 0, n = poly.length;
+ if (n === 0) return [W / 2, H / 2]; // guard: never emit NaN from an empty poly
for (var i = 0; i < n; i++) {
var j = (i + 1) % n;
var x0 = poly[i][0], y0 = poly[i][1];
← 0225bb9 Voronoi Shatter: single-file interactive power-diagram shatt
·
back to Voronoi Shatter
·
Voronoi Shatter: clamp seeds into viewport on resize + honor 88e9a81 →