better constructors for Int/Float/StringList

This commit is contained in:
Ben Fry
2015-06-08 15:03:23 -04:00
parent a8a954cf0b
commit 39a1a4fda5
3 changed files with 124 additions and 37 deletions

View File

@@ -28,6 +28,7 @@ public class FloatList implements Iterable<Float> {
data = new float[10];
}
/**
* @nowebref
*/
@@ -35,6 +36,7 @@ public class FloatList implements Iterable<Float> {
data = new float[length];
}
/**
* @nowebref
*/
@@ -44,13 +46,49 @@ public class FloatList implements Iterable<Float> {
System.arraycopy(list, 0, data, 0, count);
}
/**
* Construct an FloatList from an iterable pile of objects.
* For instance, a float array, an array of strings, who knows).
* Un-parseable or null values will be set to NaN.
* @nowebref
*/
public FloatList(Iterable<Float> iter) {
public FloatList(Iterable<Object> iter) {
this(10);
for (float v : iter) {
append(v);
for (Object o : iter) {
if (o == null) {
append(Float.NaN);
} else if (o instanceof Number) {
append(((Number) o).floatValue());
} else {
append(PApplet.parseFloat(o.toString().trim()));
}
}
crop();
}
/**
* Construct an FloatList from a random pile of objects.
* Un-parseable or null values will be set to NaN.
*/
public FloatList(Object... items) {
// nuts, no good way to pass missingValue to this fn (varargs must be last)
final float missingValue = Float.NaN;
count = items.length;
data = new float[count];
int index = 0;
for (Object o : items) {
float value = missingValue;
if (o != null) {
if (o instanceof Number) {
value = ((Number) o).floatValue();
} else {
value = PApplet.parseFloat(o.toString().trim(), missingValue);
}
}
data[index++] = value;
}
}

View File

@@ -33,6 +33,7 @@ public class IntList implements Iterable<Integer> {
data = new int[10];
}
/**
* @nowebref
*/
@@ -40,6 +41,7 @@ public class IntList implements Iterable<Integer> {
data = new int[length];
}
/**
* @nowebref
*/
@@ -49,13 +51,48 @@ public class IntList implements Iterable<Integer> {
System.arraycopy(source, 0, data, 0, count);
}
/**
* Construct an IntList from an iterable pile of objects.
* For instance, a float array, an array of strings, who knows).
* Un-parseable or null values will be set to 0.
* @nowebref
*/
public IntList(Iterable<Integer> iter) {
public IntList(Iterable<Object> iter) {
this(10);
for (int v : iter) {
append(v);
for (Object o : iter) {
if (o == null) {
append(0); // missing value default
} else if (o instanceof Number) {
append(((Number) o).intValue());
} else {
append(PApplet.parseInt(o.toString().trim()));
}
}
crop();
}
/**
* Construct an IntList from a random pile of objects.
* Un-parseable or null values will be set to zero.
*/
public IntList(Object... items) {
final int missingValue = 0; // nuts, can't be last/final/second arg
count = items.length;
data = new int[count];
int index = 0;
for (Object o : items) {
int value = missingValue;
if (o != null) {
if (o instanceof Number) {
value = ((Number) o).intValue();
} else {
value = PApplet.parseInt(o.toString().trim(), missingValue);
}
}
data[index++] = value;
}
}

View File

@@ -7,6 +7,23 @@ fixed earlier/can no longer reproduce
X strips when rendering spheres with lights and anti-aliasing
X https://github.com/processing/processing/issues/1185
api decisions
o min() and max() to use varargs
o https://github.com/processing/processing/issues/3027
X not enough use cases here to make sense
o join() to use varargs
X handling this in the Int/Float/StringList constructors instead
X users can call new StringList(...).join(",") instead
X make join() work with Iterable or Object... or both?
X will this collide with the current String[] version?
o remove OPENGL constant (tell people to use P3D or P2D)
X breaks too much code without really helping anything
o break PUtil out from PApplet
o pro: weird to call PApplet for things like hex/join/etc
o con: still lots of things like selectFolder() that need GUI
X final: not enough functions to split out to have it truly make sense
X or rather, doesn't clean up enough code that the mess is worthwhile
smooth and noSmooth
o add imageSmooth()?
o https://github.com/processing/processing/issues/1272
@@ -40,12 +57,22 @@ X moved things to settings()
X split 'present' and 'full screen'?
X --full-screen causes considerable flicker at this point
X or split them when sketchWidth/Height are implemented?
X add displayDensity() methods
X size() inside setup() can only have numbers
X size() inside settings() is left alone and can do whatever it wants
X comments are being removed before size() is getting checked
X probably remove anything inside settings() as well?
pixelDensity and 2X
X add displayDensity() methods
X add pixelDensity() method
X 2X nomenclature last call
X https://github.com/processing/processing/issues/3361
X the 2X thing on the renderer name is unnecessary
X just do pixelFactor() (and pull it during compilation)?
X add sketchPixelFactor() to handle the scenario?
X or is it just a boolean, because pixelFactor(2) is the only option?
X remove retina hint
andres/opengl
X set(0, 0, image) does not set alpha channel to opaque in P2D/P3D
X https://github.com/processing/processing/issues/2125
@@ -83,11 +110,19 @@ _ or sketchInt() or settingsInt()?
_ surface.size(), surface.noSmooth()... just like PGraphics methods?
_ make final to move folks away from these?
_ or is this a bad move until we've sorted out Android?
_ 2X nomenclature last call
_ https://github.com/processing/processing/issues/3361
critical
breaking api
_ add chaining operations to PVector
_ https://github.com/processing/processing/issues/257
_ add chaining operations to XML and JSON
_ exec() and open() to use varargs
_ cross-language awkwardness
_ python has to use launch() instead of open()
_ map() is bad for Python and JavaScript
high priority
_ draw() executes twice when noLoop() called in setup()
_ https://github.com/processing/processing/issues/3310
_ broken since 3.0a7, but not in 3.0a5
@@ -95,9 +130,8 @@ _ static mode broken with Java2D on Windows and Linux
_ https://github.com/processing/processing/issues/3315
_ sketch sometimes doesn't show with noLoop() on Linux
_ https://github.com/processing/processing/issues/3316
high priority
_ sketch not always showing with empty draw()
_ https://github.com/processing/processing/issues/3363
_ prevent running _2X renderers on non-2x hardware
_ PGraphic ignores PNG transparency (regression from 3.0a5)
_ https://github.com/processing/processing/issues/3317
@@ -211,25 +245,6 @@ _ present mode is 30-40% slower than windowed
_ w/ this example: https://github.com/processing/processing/issues/2423
breaking api
_ bring back chaining in JSON (and add to XML)
_ add chaining operations to PVector
_ https://github.com/processing/processing/issues/257
_ min() and max() to use varargs
_ https://github.com/processing/processing/issues/3027
_ make join() work with Iterable or Object... or both?
_ will this collide with the current String[] version?
_ remove OPENGL constant (tell people to use P3D or P2D)
_ exec() and open() to use varargs
_ join() to use varargs
_ break PUtil out from PApplet
_ pro: weird to call PApplet for things like hex/join/etc
_ con: still lots of things like selectFolder() that need GUI
_ cross-language awkwardness
_ python has to use launch() instead of open()
_ map() is bad for Python and JavaScript
data
_ handling of 'missing' values in Table needs serious work
_ if missing int is zero, can't just remove those values from saving a table
@@ -264,13 +279,10 @@ _ draw(s) doesn't work on the returned PShape
retina/hidpi
_ How do images behave when pixelDensity(2) is set?
_ https://github.com/processing/processing/issues/3364
_ save() and saveFrame() with 2X renderers fails
_ https://github.com/processing/processing/issues/3255
_ the 2X thing on the renderer name is unnecessary
_ just do pixelFactor() (and pull it during compilation)?
_ add sketchPixelFactor() to handle the scenario?
_ or is it just a boolean, because pixelFactor(2) is the only option?
_ remove retina hint
_ saveFrame() with retina render is making black images
_ no high-res display support for OpenGL
_ https://github.com/processing/processing/issues/2573