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