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