From 6d3e355cbd37b42d48aa4f747f5d4fbfa4d74668 Mon Sep 17 00:00:00 2001 From: VIPAX-JIT Date: Thu, 20 Nov 2025 20:54:34 +0530 Subject: [PATCH] fix(math): add zero-range guard to map() to prevent NaN/Infinity --- src/math/calculation.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/math/calculation.js b/src/math/calculation.js index 5ed489190b..da75446594 100644 --- a/src/math/calculation.js +++ b/src/math/calculation.js @@ -604,6 +604,10 @@ p5.prototype.mag = function(x, y) { */ p5.prototype.map = function(n, start1, stop1, start2, stop2, withinBounds) { p5._validateParameters('map', arguments); + // NEW: guard against zero input range to avoid division by zero + if (start1 === stop1) { + return start2; + } const newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2; if (!withinBounds) { return newval;