From 6ddd99502b3bff73c4d2aa6272a13d4480df64e4 Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Sat, 8 Aug 2026 08:48:30 +0530 Subject: [PATCH] fix: handle zero-range in map() to avoid NaN/Infinity (#8282) --- src/math/calculation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/math/calculation.js b/src/math/calculation.js index aaa3e61158..03ebc745e9 100644 --- a/src/math/calculation.js +++ b/src/math/calculation.js @@ -863,6 +863,9 @@ function calculation(p5, fn){ */ fn.map = function(n, start1, stop1, start2, stop2, withinBounds) { // p5._validateParameters('map', arguments); + if (stop1 === start1) { + return start2; + } const newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2; if (!withinBounds) { return newval;