propane 2.7.2-java → 2.8.0.pre-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/CHANGELOG.md +1 -1
- data/README.md +10 -8
- data/Rakefile +1 -1
- data/lib/propane/app.rb +3 -3
- data/lib/propane/version.rb +1 -1
- data/lib/{processing-core.jar → propane-2.8.0.jar} +0 -0
- data/library/control_panel/control_panel.rb +3 -2
- data/pom.rb +89 -88
- data/pom.xml +75 -46
- data/propane.gemspec +1 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/{monkstone → main/java/monkstone}/ColorUtil.java +0 -0
- data/src/{monkstone → main/java/monkstone}/MathToolModule.java +0 -0
- data/src/{monkstone → main/java/monkstone}/PropaneLibrary.java +0 -0
- data/src/{monkstone → main/java/monkstone}/core/LibraryProxy.java +0 -0
- data/src/{monkstone → main/java/monkstone}/fastmath/Deglut.java +0 -0
- data/src/{monkstone → main/java/monkstone}/fastmath/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/filechooser/Chooser.java +0 -0
- data/src/{monkstone → main/java/monkstone}/noise/SimplexNoise.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/CustomHorizontalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/CustomVerticalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SimpleHorizontalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SimpleSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SimpleVerticalSlider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/Slider.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SliderBar.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/SliderGroup.java +0 -0
- data/src/{monkstone → main/java/monkstone}/slider/WheelHandler.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/AppRender.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/JRender.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/ShapeRender.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec2/Vec2.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec2/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec3/Vec3.java +0 -0
- data/src/{monkstone → main/java/monkstone}/vecmath/vec3/package-info.java +0 -0
- data/src/{monkstone → main/java/monkstone}/videoevent/VideoInterface.java +0 -0
- data/src/{monkstone → main/java/monkstone}/videoevent/package-info.java +0 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3029 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +377 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1567 -0
- data/src/main/java/processing/core/PApplet.java +15709 -0
- data/src/main/java/processing/core/PConstants.java +527 -0
- data/src/main/java/processing/core/PFont.java +1098 -0
- data/src/main/java/processing/core/PGraphics.java +8467 -0
- data/src/main/java/processing/core/PImage.java +3438 -0
- data/src/main/java/processing/core/PMatrix.java +208 -0
- data/src/main/java/processing/core/PMatrix2D.java +534 -0
- data/src/main/java/processing/core/PMatrix3D.java +877 -0
- data/src/main/java/processing/core/PShape.java +3445 -0
- data/src/main/java/processing/core/PShapeOBJ.java +469 -0
- data/src/main/java/processing/core/PShapeSVG.java +1787 -0
- data/src/main/java/processing/core/PStyle.java +63 -0
- data/src/main/java/processing/core/PSurface.java +161 -0
- data/src/main/java/processing/core/PSurfaceNone.java +374 -0
- data/src/main/java/processing/core/PVector.java +1063 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +125 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/vendors/Rakefile +5 -20
- metadata +115 -33
- data/lib/propane.jar +0 -0
@@ -0,0 +1,912 @@
|
|
1
|
+
package processing.data;
|
2
|
+
|
3
|
+
import java.util.Arrays;
|
4
|
+
import java.util.Iterator;
|
5
|
+
import java.util.Random;
|
6
|
+
|
7
|
+
import processing.core.PApplet;
|
8
|
+
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Helper class for a list of floats. Lists are designed to have some of the
|
12
|
+
* features of ArrayLists, but to maintain the simplicity and efficiency of
|
13
|
+
* working with arrays.
|
14
|
+
*
|
15
|
+
* Functions like sort() and shuffle() always act on the list itself. To get
|
16
|
+
* a sorted copy, use list.copy().sort().
|
17
|
+
*
|
18
|
+
* @webref data:composite
|
19
|
+
* @see IntList
|
20
|
+
* @see StringList
|
21
|
+
*/
|
22
|
+
public class FloatList implements Iterable<Float> {
|
23
|
+
int count;
|
24
|
+
float[] data;
|
25
|
+
|
26
|
+
|
27
|
+
public FloatList() {
|
28
|
+
data = new float[10];
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @nowebref
|
34
|
+
*/
|
35
|
+
public FloatList(int length) {
|
36
|
+
data = new float[length];
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @nowebref
|
42
|
+
*/
|
43
|
+
public FloatList(float[] list) {
|
44
|
+
count = list.length;
|
45
|
+
data = new float[count];
|
46
|
+
System.arraycopy(list, 0, data, 0, count);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Construct an FloatList from an iterable pile of objects.
|
52
|
+
* For instance, a float array, an array of strings, who knows).
|
53
|
+
* Un-parseable or null values will be set to NaN.
|
54
|
+
* @nowebref
|
55
|
+
*/
|
56
|
+
public FloatList(Iterable<Object> iter) {
|
57
|
+
this(10);
|
58
|
+
for (Object o : iter) {
|
59
|
+
if (o == null) {
|
60
|
+
append(Float.NaN);
|
61
|
+
} else if (o instanceof Number) {
|
62
|
+
append(((Number) o).floatValue());
|
63
|
+
} else {
|
64
|
+
append(PApplet.parseFloat(o.toString().trim()));
|
65
|
+
}
|
66
|
+
}
|
67
|
+
crop();
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Construct an FloatList from a random pile of objects.
|
73
|
+
* Un-parseable or null values will be set to NaN.
|
74
|
+
*/
|
75
|
+
public FloatList(Object... items) {
|
76
|
+
// nuts, no good way to pass missingValue to this fn (varargs must be last)
|
77
|
+
final float missingValue = Float.NaN;
|
78
|
+
|
79
|
+
count = items.length;
|
80
|
+
data = new float[count];
|
81
|
+
int index = 0;
|
82
|
+
for (Object o : items) {
|
83
|
+
float value = missingValue;
|
84
|
+
if (o != null) {
|
85
|
+
if (o instanceof Number) {
|
86
|
+
value = ((Number) o).floatValue();
|
87
|
+
} else {
|
88
|
+
value = PApplet.parseFloat(o.toString().trim(), missingValue);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
data[index++] = value;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Improve efficiency by removing allocated but unused entries from the
|
98
|
+
* internal array used to store the data. Set to private, though it could
|
99
|
+
* be useful to have this public if lists are frequently making drastic
|
100
|
+
* size changes (from very large to very small).
|
101
|
+
*/
|
102
|
+
private void crop() {
|
103
|
+
if (count != data.length) {
|
104
|
+
data = PApplet.subset(data, 0, count);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Get the length of the list.
|
111
|
+
*
|
112
|
+
* @webref floatlist:method
|
113
|
+
* @brief Get the length of the list
|
114
|
+
*/
|
115
|
+
public int size() {
|
116
|
+
return count;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
public void resize(int length) {
|
121
|
+
if (length > data.length) {
|
122
|
+
float[] temp = new float[length];
|
123
|
+
System.arraycopy(data, 0, temp, 0, count);
|
124
|
+
data = temp;
|
125
|
+
|
126
|
+
} else if (length > count) {
|
127
|
+
Arrays.fill(data, count, length, 0);
|
128
|
+
}
|
129
|
+
count = length;
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Remove all entries from the list.
|
135
|
+
*
|
136
|
+
* @webref floatlist:method
|
137
|
+
* @brief Remove all entries from the list
|
138
|
+
*/
|
139
|
+
public void clear() {
|
140
|
+
count = 0;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Get an entry at a particular index.
|
146
|
+
*
|
147
|
+
* @webref floatlist:method
|
148
|
+
* @brief Get an entry at a particular index
|
149
|
+
*/
|
150
|
+
public float get(int index) {
|
151
|
+
if (index >= count) {
|
152
|
+
throw new ArrayIndexOutOfBoundsException(index);
|
153
|
+
}
|
154
|
+
return data[index];
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Set the entry at a particular index. If the index is past the length of
|
160
|
+
* the list, it'll expand the list to accommodate, and fill the intermediate
|
161
|
+
* entries with 0s.
|
162
|
+
*
|
163
|
+
* @webref floatlist:method
|
164
|
+
* @brief Set the entry at a particular index
|
165
|
+
*/
|
166
|
+
public void set(int index, float what) {
|
167
|
+
if (index >= count) {
|
168
|
+
data = PApplet.expand(data, index+1);
|
169
|
+
for (int i = count; i < index; i++) {
|
170
|
+
data[i] = 0;
|
171
|
+
}
|
172
|
+
count = index+1;
|
173
|
+
}
|
174
|
+
data[index] = what;
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
/** Just an alias for append(), but matches pop() */
|
179
|
+
public void push(float value) {
|
180
|
+
append(value);
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
public float pop() {
|
185
|
+
if (count == 0) {
|
186
|
+
throw new RuntimeException("Can't call pop() on an empty list");
|
187
|
+
}
|
188
|
+
float value = get(count-1);
|
189
|
+
count--;
|
190
|
+
return value;
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Remove an element from the specified index.
|
196
|
+
*
|
197
|
+
* @webref floatlist:method
|
198
|
+
* @brief Remove an element from the specified index
|
199
|
+
*/
|
200
|
+
public float remove(int index) {
|
201
|
+
if (index < 0 || index >= count) {
|
202
|
+
throw new ArrayIndexOutOfBoundsException(index);
|
203
|
+
}
|
204
|
+
float entry = data[index];
|
205
|
+
// int[] outgoing = new int[count - 1];
|
206
|
+
// System.arraycopy(data, 0, outgoing, 0, index);
|
207
|
+
// count--;
|
208
|
+
// System.arraycopy(data, index + 1, outgoing, 0, count - index);
|
209
|
+
// data = outgoing;
|
210
|
+
// For most cases, this actually appears to be faster
|
211
|
+
// than arraycopy() on an array copying into itself.
|
212
|
+
for (int i = index; i < count-1; i++) {
|
213
|
+
data[i] = data[i+1];
|
214
|
+
}
|
215
|
+
count--;
|
216
|
+
return entry;
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
// Remove the first instance of a particular value,
|
221
|
+
// and return the index at which it was found.
|
222
|
+
public int removeValue(int value) {
|
223
|
+
int index = index(value);
|
224
|
+
if (index != -1) {
|
225
|
+
remove(index);
|
226
|
+
return index;
|
227
|
+
}
|
228
|
+
return -1;
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
// Remove all instances of a particular value,
|
233
|
+
// and return the number of values found and removed
|
234
|
+
public int removeValues(int value) {
|
235
|
+
int ii = 0;
|
236
|
+
if (Float.isNaN(value)) {
|
237
|
+
for (int i = 0; i < count; i++) {
|
238
|
+
if (!Float.isNaN(data[i])) {
|
239
|
+
data[ii++] = data[i];
|
240
|
+
}
|
241
|
+
}
|
242
|
+
} else {
|
243
|
+
for (int i = 0; i < count; i++) {
|
244
|
+
if (data[i] != value) {
|
245
|
+
data[ii++] = data[i];
|
246
|
+
}
|
247
|
+
}
|
248
|
+
}
|
249
|
+
int removed = count - ii;
|
250
|
+
count = ii;
|
251
|
+
return removed;
|
252
|
+
}
|
253
|
+
|
254
|
+
|
255
|
+
/** Replace the first instance of a particular value */
|
256
|
+
public boolean replaceValue(float value, float newValue) {
|
257
|
+
if (Float.isNaN(value)) {
|
258
|
+
for (int i = 0; i < count; i++) {
|
259
|
+
if (Float.isNaN(data[i])) {
|
260
|
+
data[i] = newValue;
|
261
|
+
return true;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
} else {
|
265
|
+
int index = index(value);
|
266
|
+
if (index != -1) {
|
267
|
+
data[index] = newValue;
|
268
|
+
return true;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
/** Replace all instances of a particular value */
|
276
|
+
public boolean replaceValues(float value, float newValue) {
|
277
|
+
boolean changed = false;
|
278
|
+
if (Float.isNaN(value)) {
|
279
|
+
for (int i = 0; i < count; i++) {
|
280
|
+
if (Float.isNaN(data[i])) {
|
281
|
+
data[i] = newValue;
|
282
|
+
changed = true;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
} else {
|
286
|
+
for (int i = 0; i < count; i++) {
|
287
|
+
if (data[i] == value) {
|
288
|
+
data[i] = newValue;
|
289
|
+
changed = true;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
return changed;
|
294
|
+
}
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Add a new entry to the list.
|
300
|
+
*
|
301
|
+
* @webref floatlist:method
|
302
|
+
* @brief Add a new entry to the list
|
303
|
+
*/
|
304
|
+
public void append(float value) {
|
305
|
+
if (count == data.length) {
|
306
|
+
data = PApplet.expand(data);
|
307
|
+
}
|
308
|
+
data[count++] = value;
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
public void append(float[] values) {
|
313
|
+
for (float v : values) {
|
314
|
+
append(v);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
|
319
|
+
public void append(FloatList list) {
|
320
|
+
for (float v : list.values()) { // will concat the list...
|
321
|
+
append(v);
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
/** Add this value, but only if it's not already in the list. */
|
327
|
+
public void appendUnique(float value) {
|
328
|
+
if (!hasValue(value)) {
|
329
|
+
append(value);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
// public void insert(int index, int value) {
|
335
|
+
// if (index+1 > count) {
|
336
|
+
// if (index+1 < data.length) {
|
337
|
+
// }
|
338
|
+
// }
|
339
|
+
// if (index >= data.length) {
|
340
|
+
// data = PApplet.expand(data, index+1);
|
341
|
+
// data[index] = value;
|
342
|
+
// count = index+1;
|
343
|
+
//
|
344
|
+
// } else if (count == data.length) {
|
345
|
+
// if (index >= count) {
|
346
|
+
// //int[] temp = new int[count << 1];
|
347
|
+
// System.arraycopy(data, 0, temp, 0, index);
|
348
|
+
// temp[index] = value;
|
349
|
+
// System.arraycopy(data, index, temp, index+1, count - index);
|
350
|
+
// data = temp;
|
351
|
+
//
|
352
|
+
// } else {
|
353
|
+
// // data[] has room to grow
|
354
|
+
// // for() loop believed to be faster than System.arraycopy over itself
|
355
|
+
// for (int i = count; i > index; --i) {
|
356
|
+
// data[i] = data[i-1];
|
357
|
+
// }
|
358
|
+
// data[index] = value;
|
359
|
+
// count++;
|
360
|
+
// }
|
361
|
+
// }
|
362
|
+
|
363
|
+
|
364
|
+
public void insert(int index, float value) {
|
365
|
+
insert(index, new float[] { value });
|
366
|
+
}
|
367
|
+
|
368
|
+
|
369
|
+
// same as splice
|
370
|
+
public void insert(int index, float[] values) {
|
371
|
+
if (index < 0) {
|
372
|
+
throw new IllegalArgumentException("insert() index cannot be negative: it was " + index);
|
373
|
+
}
|
374
|
+
if (index >= data.length) {
|
375
|
+
throw new IllegalArgumentException("insert() index " + index + " is past the end of this list");
|
376
|
+
}
|
377
|
+
|
378
|
+
float[] temp = new float[count + values.length];
|
379
|
+
|
380
|
+
// Copy the old values, but not more than already exist
|
381
|
+
System.arraycopy(data, 0, temp, 0, Math.min(count, index));
|
382
|
+
|
383
|
+
// Copy the new values into the proper place
|
384
|
+
System.arraycopy(values, 0, temp, index, values.length);
|
385
|
+
|
386
|
+
// if (index < count) {
|
387
|
+
// The index was inside count, so it's a true splice/insert
|
388
|
+
System.arraycopy(data, index, temp, index+values.length, count - index);
|
389
|
+
count = count + values.length;
|
390
|
+
// } else {
|
391
|
+
// // The index was past 'count', so the new count is weirder
|
392
|
+
// count = index + values.length;
|
393
|
+
// }
|
394
|
+
data = temp;
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
public void insert(int index, FloatList list) {
|
399
|
+
insert(index, list.values());
|
400
|
+
}
|
401
|
+
|
402
|
+
|
403
|
+
// below are aborted attempts at more optimized versions of the code
|
404
|
+
// that are harder to read and debug...
|
405
|
+
|
406
|
+
// if (index + values.length >= count) {
|
407
|
+
// // We're past the current 'count', check to see if we're still allocated
|
408
|
+
// // index 9, data.length = 10, values.length = 1
|
409
|
+
// if (index + values.length < data.length) {
|
410
|
+
// // There's still room for these entries, even though it's past 'count'.
|
411
|
+
// // First clear out the entries leading up to it, however.
|
412
|
+
// for (int i = count; i < index; i++) {
|
413
|
+
// data[i] = 0;
|
414
|
+
// }
|
415
|
+
// data[index] =
|
416
|
+
// }
|
417
|
+
// if (index >= data.length) {
|
418
|
+
// int length = index + values.length;
|
419
|
+
// int[] temp = new int[length];
|
420
|
+
// System.arraycopy(data, 0, temp, 0, count);
|
421
|
+
// System.arraycopy(values, 0, temp, index, values.length);
|
422
|
+
// data = temp;
|
423
|
+
// count = data.length;
|
424
|
+
// } else {
|
425
|
+
//
|
426
|
+
// }
|
427
|
+
//
|
428
|
+
// } else if (count == data.length) {
|
429
|
+
// int[] temp = new int[count << 1];
|
430
|
+
// System.arraycopy(data, 0, temp, 0, index);
|
431
|
+
// temp[index] = value;
|
432
|
+
// System.arraycopy(data, index, temp, index+1, count - index);
|
433
|
+
// data = temp;
|
434
|
+
//
|
435
|
+
// } else {
|
436
|
+
// // data[] has room to grow
|
437
|
+
// // for() loop believed to be faster than System.arraycopy over itself
|
438
|
+
// for (int i = count; i > index; --i) {
|
439
|
+
// data[i] = data[i-1];
|
440
|
+
// }
|
441
|
+
// data[index] = value;
|
442
|
+
// count++;
|
443
|
+
// }
|
444
|
+
|
445
|
+
|
446
|
+
/** Return the first index of a particular value. */
|
447
|
+
public int index(float what) {
|
448
|
+
/*
|
449
|
+
if (indexCache != null) {
|
450
|
+
try {
|
451
|
+
return indexCache.get(what);
|
452
|
+
} catch (Exception e) { // not there
|
453
|
+
return -1;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
*/
|
457
|
+
for (int i = 0; i < count; i++) {
|
458
|
+
if (data[i] == what) {
|
459
|
+
return i;
|
460
|
+
}
|
461
|
+
}
|
462
|
+
return -1;
|
463
|
+
}
|
464
|
+
|
465
|
+
|
466
|
+
/**
|
467
|
+
* @webref floatlist:method
|
468
|
+
* @brief Check if a number is a part of the list
|
469
|
+
*/
|
470
|
+
public boolean hasValue(float value) {
|
471
|
+
if (Float.isNaN(value)) {
|
472
|
+
for (int i = 0; i < count; i++) {
|
473
|
+
if (Float.isNaN(data[i])) {
|
474
|
+
return true;
|
475
|
+
}
|
476
|
+
}
|
477
|
+
} else {
|
478
|
+
for (int i = 0; i < count; i++) {
|
479
|
+
if (data[i] == value) {
|
480
|
+
return true;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
}
|
484
|
+
return false;
|
485
|
+
}
|
486
|
+
|
487
|
+
|
488
|
+
private void boundsProblem(int index, String method) {
|
489
|
+
final String msg = String.format("The list size is %d. " +
|
490
|
+
"You cannot %s() to element %d.", count, method, index);
|
491
|
+
throw new ArrayIndexOutOfBoundsException(msg);
|
492
|
+
}
|
493
|
+
|
494
|
+
|
495
|
+
/**
|
496
|
+
* @webref floatlist:method
|
497
|
+
* @brief Add to a value
|
498
|
+
*/
|
499
|
+
public void add(int index, float amount) {
|
500
|
+
if (index < count) {
|
501
|
+
data[index] += amount;
|
502
|
+
} else {
|
503
|
+
boundsProblem(index, "add");
|
504
|
+
}
|
505
|
+
}
|
506
|
+
|
507
|
+
|
508
|
+
/**
|
509
|
+
* @webref floatlist:method
|
510
|
+
* @brief Subtract from a value
|
511
|
+
*/
|
512
|
+
public void sub(int index, float amount) {
|
513
|
+
if (index < count) {
|
514
|
+
data[index] -= amount;
|
515
|
+
} else {
|
516
|
+
boundsProblem(index, "sub");
|
517
|
+
}
|
518
|
+
}
|
519
|
+
|
520
|
+
|
521
|
+
/**
|
522
|
+
* @webref floatlist:method
|
523
|
+
* @brief Multiply a value
|
524
|
+
*/
|
525
|
+
public void mult(int index, float amount) {
|
526
|
+
if (index < count) {
|
527
|
+
data[index] *= amount;
|
528
|
+
} else {
|
529
|
+
boundsProblem(index, "mult");
|
530
|
+
}
|
531
|
+
}
|
532
|
+
|
533
|
+
|
534
|
+
/**
|
535
|
+
* @webref floatlist:method
|
536
|
+
* @brief Divide a value
|
537
|
+
*/
|
538
|
+
public void div(int index, float amount) {
|
539
|
+
if (index < count) {
|
540
|
+
data[index] /= amount;
|
541
|
+
} else {
|
542
|
+
boundsProblem(index, "div");
|
543
|
+
}
|
544
|
+
}
|
545
|
+
|
546
|
+
|
547
|
+
private void checkMinMax(String functionName) {
|
548
|
+
if (count == 0) {
|
549
|
+
String msg =
|
550
|
+
String.format("Cannot use %s() on an empty %s.",
|
551
|
+
functionName, getClass().getSimpleName());
|
552
|
+
throw new RuntimeException(msg);
|
553
|
+
}
|
554
|
+
}
|
555
|
+
|
556
|
+
|
557
|
+
/**
|
558
|
+
* @webref floatlist:method
|
559
|
+
* @brief Return the smallest value
|
560
|
+
*/
|
561
|
+
public float min() {
|
562
|
+
checkMinMax("min");
|
563
|
+
int index = minIndex();
|
564
|
+
return index == -1 ? Float.NaN : data[index];
|
565
|
+
}
|
566
|
+
|
567
|
+
|
568
|
+
public int minIndex() {
|
569
|
+
checkMinMax("minIndex");
|
570
|
+
float m = Float.NaN;
|
571
|
+
int mi = -1;
|
572
|
+
for (int i = 0; i < count; i++) {
|
573
|
+
// find one good value to start
|
574
|
+
if (data[i] == data[i]) {
|
575
|
+
m = data[i];
|
576
|
+
mi = i;
|
577
|
+
|
578
|
+
// calculate the rest
|
579
|
+
for (int j = i+1; j < count; j++) {
|
580
|
+
float d = data[j];
|
581
|
+
if (!Float.isNaN(d) && (d < m)) {
|
582
|
+
m = data[j];
|
583
|
+
mi = j;
|
584
|
+
}
|
585
|
+
}
|
586
|
+
break;
|
587
|
+
}
|
588
|
+
}
|
589
|
+
return mi;
|
590
|
+
}
|
591
|
+
|
592
|
+
|
593
|
+
/**
|
594
|
+
* @webref floatlist:method
|
595
|
+
* @brief Return the largest value
|
596
|
+
*/
|
597
|
+
public float max() {
|
598
|
+
checkMinMax("max");
|
599
|
+
int index = maxIndex();
|
600
|
+
return index == -1 ? Float.NaN : data[index];
|
601
|
+
}
|
602
|
+
|
603
|
+
|
604
|
+
public int maxIndex() {
|
605
|
+
checkMinMax("maxIndex");
|
606
|
+
float m = Float.NaN;
|
607
|
+
int mi = -1;
|
608
|
+
for (int i = 0; i < count; i++) {
|
609
|
+
// find one good value to start
|
610
|
+
if (data[i] == data[i]) {
|
611
|
+
m = data[i];
|
612
|
+
mi = i;
|
613
|
+
|
614
|
+
// calculate the rest
|
615
|
+
for (int j = i+1; j < count; j++) {
|
616
|
+
float d = data[j];
|
617
|
+
if (!Float.isNaN(d) && (d > m)) {
|
618
|
+
m = data[j];
|
619
|
+
mi = j;
|
620
|
+
}
|
621
|
+
}
|
622
|
+
break;
|
623
|
+
}
|
624
|
+
}
|
625
|
+
return mi;
|
626
|
+
}
|
627
|
+
|
628
|
+
|
629
|
+
public float sum() {
|
630
|
+
double amount = sumDouble();
|
631
|
+
if (amount > Float.MAX_VALUE) {
|
632
|
+
throw new RuntimeException("sum() exceeds " + Float.MAX_VALUE + ", use sumDouble()");
|
633
|
+
}
|
634
|
+
if (amount < -Float.MAX_VALUE) {
|
635
|
+
throw new RuntimeException("sum() lower than " + -Float.MAX_VALUE + ", use sumDouble()");
|
636
|
+
}
|
637
|
+
return (float) amount;
|
638
|
+
}
|
639
|
+
|
640
|
+
|
641
|
+
public double sumDouble() {
|
642
|
+
double sum = 0;
|
643
|
+
for (int i = 0; i < count; i++) {
|
644
|
+
sum += data[i];
|
645
|
+
}
|
646
|
+
return sum;
|
647
|
+
}
|
648
|
+
|
649
|
+
|
650
|
+
/**
|
651
|
+
* Sorts the array in place.
|
652
|
+
*
|
653
|
+
* @webref floatlist:method
|
654
|
+
* @brief Sorts an array, lowest to highest
|
655
|
+
*/
|
656
|
+
public void sort() {
|
657
|
+
Arrays.sort(data, 0, count);
|
658
|
+
}
|
659
|
+
|
660
|
+
|
661
|
+
/**
|
662
|
+
* Reverse sort, orders values from highest to lowest
|
663
|
+
*
|
664
|
+
* @webref floatlist:method
|
665
|
+
* @brief Reverse sort, orders values from highest to lowest
|
666
|
+
*/
|
667
|
+
public void sortReverse() {
|
668
|
+
new Sort() {
|
669
|
+
@Override
|
670
|
+
public int size() {
|
671
|
+
// if empty, don't even mess with the NaN check, it'll AIOOBE
|
672
|
+
if (count == 0) {
|
673
|
+
return 0;
|
674
|
+
}
|
675
|
+
// move NaN values to the end of the list and don't sort them
|
676
|
+
int right = count - 1;
|
677
|
+
while (data[right] != data[right]) {
|
678
|
+
right--;
|
679
|
+
if (right == -1) { // all values are NaN
|
680
|
+
return 0;
|
681
|
+
}
|
682
|
+
}
|
683
|
+
for (int i = right; i >= 0; --i) {
|
684
|
+
float v = data[i];
|
685
|
+
if (v != v) {
|
686
|
+
data[i] = data[right];
|
687
|
+
data[right] = v;
|
688
|
+
--right;
|
689
|
+
}
|
690
|
+
}
|
691
|
+
return right + 1;
|
692
|
+
}
|
693
|
+
|
694
|
+
@Override
|
695
|
+
public float compare(int a, int b) {
|
696
|
+
return data[b] - data[a];
|
697
|
+
}
|
698
|
+
|
699
|
+
@Override
|
700
|
+
public void swap(int a, int b) {
|
701
|
+
float temp = data[a];
|
702
|
+
data[a] = data[b];
|
703
|
+
data[b] = temp;
|
704
|
+
}
|
705
|
+
}.run();
|
706
|
+
}
|
707
|
+
|
708
|
+
|
709
|
+
// use insert()
|
710
|
+
// public void splice(int index, int value) {
|
711
|
+
// }
|
712
|
+
|
713
|
+
|
714
|
+
// public void subset(int start) {
|
715
|
+
// subset(start, count - start);
|
716
|
+
// }
|
717
|
+
|
718
|
+
|
719
|
+
// public void subset(int start, int num) {
|
720
|
+
// for (int i = 0; i < num; i++) {
|
721
|
+
// data[i] = data[i+start];
|
722
|
+
// }
|
723
|
+
// count = num;
|
724
|
+
// }
|
725
|
+
|
726
|
+
|
727
|
+
/**
|
728
|
+
* @webref floatlist:method
|
729
|
+
* @brief Reverse the order of the list elements
|
730
|
+
*/
|
731
|
+
public void reverse() {
|
732
|
+
int ii = count - 1;
|
733
|
+
for (int i = 0; i < count/2; i++) {
|
734
|
+
float t = data[i];
|
735
|
+
data[i] = data[ii];
|
736
|
+
data[ii] = t;
|
737
|
+
--ii;
|
738
|
+
}
|
739
|
+
}
|
740
|
+
|
741
|
+
|
742
|
+
/**
|
743
|
+
* Randomize the order of the list elements. Note that this does not
|
744
|
+
* obey the randomSeed() function in PApplet.
|
745
|
+
*
|
746
|
+
* @webref floatlist:method
|
747
|
+
* @brief Randomize the order of the list elements
|
748
|
+
*/
|
749
|
+
public void shuffle() {
|
750
|
+
Random r = new Random();
|
751
|
+
int num = count;
|
752
|
+
while (num > 1) {
|
753
|
+
int value = r.nextInt(num);
|
754
|
+
num--;
|
755
|
+
float temp = data[num];
|
756
|
+
data[num] = data[value];
|
757
|
+
data[value] = temp;
|
758
|
+
}
|
759
|
+
}
|
760
|
+
|
761
|
+
|
762
|
+
/**
|
763
|
+
* Randomize the list order using the random() function from the specified
|
764
|
+
* sketch, allowing shuffle() to use its current randomSeed() setting.
|
765
|
+
*/
|
766
|
+
public void shuffle(PApplet sketch) {
|
767
|
+
int num = count;
|
768
|
+
while (num > 1) {
|
769
|
+
int value = (int) sketch.random(num);
|
770
|
+
num--;
|
771
|
+
float temp = data[num];
|
772
|
+
data[num] = data[value];
|
773
|
+
data[value] = temp;
|
774
|
+
}
|
775
|
+
}
|
776
|
+
|
777
|
+
|
778
|
+
public FloatList copy() {
|
779
|
+
FloatList outgoing = new FloatList(data);
|
780
|
+
outgoing.count = count;
|
781
|
+
return outgoing;
|
782
|
+
}
|
783
|
+
|
784
|
+
|
785
|
+
/**
|
786
|
+
* Returns the actual array being used to store the data. For advanced users,
|
787
|
+
* this is the fastest way to access a large list. Suitable for iterating
|
788
|
+
* with a for() loop, but modifying the list will have terrible consequences.
|
789
|
+
*/
|
790
|
+
public float[] values() {
|
791
|
+
crop();
|
792
|
+
return data;
|
793
|
+
}
|
794
|
+
|
795
|
+
|
796
|
+
/** Implemented this way so that we can use a FloatList in a for loop. */
|
797
|
+
@Override
|
798
|
+
public Iterator<Float> iterator() {
|
799
|
+
// }
|
800
|
+
//
|
801
|
+
//
|
802
|
+
// public Iterator<Float> valueIterator() {
|
803
|
+
return new Iterator<Float>() {
|
804
|
+
int index = -1;
|
805
|
+
|
806
|
+
public void remove() {
|
807
|
+
FloatList.this.remove(index);
|
808
|
+
index--;
|
809
|
+
}
|
810
|
+
|
811
|
+
public Float next() {
|
812
|
+
return data[++index];
|
813
|
+
}
|
814
|
+
|
815
|
+
public boolean hasNext() {
|
816
|
+
return index+1 < count;
|
817
|
+
}
|
818
|
+
};
|
819
|
+
}
|
820
|
+
|
821
|
+
|
822
|
+
/**
|
823
|
+
* Create a new array with a copy of all the values.
|
824
|
+
* @return an array sized by the length of the list with each of the values.
|
825
|
+
* @webref floatlist:method
|
826
|
+
* @brief Create a new array with a copy of all the values
|
827
|
+
*/
|
828
|
+
public float[] array() {
|
829
|
+
return array(null);
|
830
|
+
}
|
831
|
+
|
832
|
+
|
833
|
+
/**
|
834
|
+
* Copy values into the specified array. If the specified array is null or
|
835
|
+
* not the same size, a new array will be allocated.
|
836
|
+
* @param array
|
837
|
+
*/
|
838
|
+
public float[] array(float[] array) {
|
839
|
+
if (array == null || array.length != count) {
|
840
|
+
array = new float[count];
|
841
|
+
}
|
842
|
+
System.arraycopy(data, 0, array, 0, count);
|
843
|
+
return array;
|
844
|
+
}
|
845
|
+
|
846
|
+
|
847
|
+
/**
|
848
|
+
* Returns a normalized version of this array. Called getPercent() for
|
849
|
+
* consistency with the Dict classes. It's a getter method because it needs
|
850
|
+
* to returns a new list (because IntList/Dict can't do percentages or
|
851
|
+
* normalization in place on int values).
|
852
|
+
*/
|
853
|
+
public FloatList getPercent() {
|
854
|
+
double sum = 0;
|
855
|
+
for (float value : array()) {
|
856
|
+
sum += value;
|
857
|
+
}
|
858
|
+
FloatList outgoing = new FloatList(count);
|
859
|
+
for (int i = 0; i < count; i++) {
|
860
|
+
double percent = data[i] / sum;
|
861
|
+
outgoing.set(i, (float) percent);
|
862
|
+
}
|
863
|
+
return outgoing;
|
864
|
+
}
|
865
|
+
|
866
|
+
|
867
|
+
public FloatList getSubset(int start) {
|
868
|
+
return getSubset(start, count - start);
|
869
|
+
}
|
870
|
+
|
871
|
+
|
872
|
+
public FloatList getSubset(int start, int num) {
|
873
|
+
float[] subset = new float[num];
|
874
|
+
System.arraycopy(data, start, subset, 0, num);
|
875
|
+
return new FloatList(subset);
|
876
|
+
}
|
877
|
+
|
878
|
+
|
879
|
+
public String join(String separator) {
|
880
|
+
if (count == 0) {
|
881
|
+
return "";
|
882
|
+
}
|
883
|
+
StringBuilder sb = new StringBuilder();
|
884
|
+
sb.append(data[0]);
|
885
|
+
for (int i = 1; i < count; i++) {
|
886
|
+
sb.append(separator);
|
887
|
+
sb.append(data[i]);
|
888
|
+
}
|
889
|
+
return sb.toString();
|
890
|
+
}
|
891
|
+
|
892
|
+
|
893
|
+
public void print() {
|
894
|
+
for (int i = 0; i < count; i++) {
|
895
|
+
System.out.format("[%d] %f%n", i, data[i]);
|
896
|
+
}
|
897
|
+
}
|
898
|
+
|
899
|
+
|
900
|
+
/**
|
901
|
+
* Return this dictionary as a String in JSON format.
|
902
|
+
*/
|
903
|
+
public String toJSON() {
|
904
|
+
return "[ " + join(", ") + " ]";
|
905
|
+
}
|
906
|
+
|
907
|
+
|
908
|
+
@Override
|
909
|
+
public String toString() {
|
910
|
+
return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
|
911
|
+
}
|
912
|
+
}
|