diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 847291e1d..17aef6038 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -4802,7 +4802,16 @@ public class PApplet implements PConstants { static public final float map(float value, float start1, float stop1, float start2, float stop2) { - return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); + float outgoing = + start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); + if (!Float.isFinite(outgoing)) { + final String msg = + String.format("map(%s, %s, %s, %s, %s) called, " + + "which returns NaN or infinity", + nf(value), nf(start1), nf(stop1), nf(start2), nf(stop2)); + PGraphics.showWarning(msg); + } + return outgoing; } @@ -9196,6 +9205,24 @@ public class PApplet implements PConstants { // INT NUMBER FORMATTING + static public String nf(float num) { + int inum = (int) num; + if (num == inum) { + return str(inum); + } + return str(num); + } + + + static public String[] nf(float[] num) { + String[] outgoing = new String[num.length]; + for (int i = 0; i < num.length; i++) { + outgoing[i] = nf(num[i]); + } + return outgoing; + } + + /** * Integer number formatter. */ diff --git a/core/todo.txt b/core/todo.txt index b0e6a0759..edc739991 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -4,6 +4,8 @@ opengl X IndexOutOfBoundsException with pixelDensity(2) and P2D X https://github.com/processing/processing/issues/3568 +X Shaders output to bottom left corner rather than full window in 3.0b2 +X https://github.com/processing/processing/issues/3572 _ `focused` variable always false in P2D/P3D _ https://github.com/processing/processing/issues/3564 _ Use PBOs for async texture copy