Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/math/calculation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down