print warning with bad map(), also add nf(float) (#3314)

This commit is contained in:
Ben Fry
2015-08-11 12:06:36 -04:00
parent 4c8dcccf4d
commit 9433ba2a7b
2 changed files with 30 additions and 1 deletions

View File

@@ -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.
*/

View File

@@ -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