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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  3. data/CHANGELOG.md +1 -5
  4. data/README.md +23 -12
  5. data/Rakefile +23 -12
  6. data/lib/propane/helpers/version_error.rb +6 -0
  7. data/lib/propane/runner.rb +12 -0
  8. data/lib/propane/version.rb +1 -1
  9. data/library/slider/slider.rb +1 -1
  10. data/mvnw +234 -0
  11. data/mvnw.cmd +145 -0
  12. data/pom.xml +28 -27
  13. data/propane.gemspec +2 -2
  14. data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
  15. data/src/main/java/monkstone/ColorUtil.java +1 -1
  16. data/src/main/java/monkstone/MathToolModule.java +12 -11
  17. data/src/main/java/monkstone/PropaneLibrary.java +9 -10
  18. data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
  19. data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
  20. data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
  21. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
  22. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
  23. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  24. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
  25. data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
  26. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
  27. data/src/main/java/monkstone/slider/Slider.java +1 -1
  28. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  29. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  30. data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
  31. data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
  32. data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
  33. data/src/main/java/monkstone/vecmath/package-info.java +2 -2
  34. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  35. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  36. data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
  37. data/src/main/java/monkstone/videoevent/package-info.java +2 -2
  38. data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
  39. data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
  40. data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
  41. data/src/main/java/processing/core/DesktopHandler.java +94 -0
  42. data/src/main/java/processing/core/PApplet.java +14170 -14082
  43. data/src/main/java/processing/core/PConstants.java +447 -473
  44. data/src/main/java/processing/core/PFont.java +867 -873
  45. data/src/main/java/processing/core/PGraphics.java +7193 -7428
  46. data/src/main/java/processing/core/PImage.java +3051 -3117
  47. data/src/main/java/processing/core/PMatrix.java +159 -172
  48. data/src/main/java/processing/core/PMatrix2D.java +403 -444
  49. data/src/main/java/processing/core/PMatrix3D.java +735 -749
  50. data/src/main/java/processing/core/PShape.java +2651 -2793
  51. data/src/main/java/processing/core/PShapeOBJ.java +415 -422
  52. data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
  53. data/src/main/java/processing/core/PStyle.java +37 -40
  54. data/src/main/java/processing/core/PSurface.java +98 -103
  55. data/src/main/java/processing/core/PSurfaceNone.java +208 -236
  56. data/src/main/java/processing/core/PVector.java +961 -990
  57. data/src/main/java/processing/data/DoubleDict.java +709 -753
  58. data/src/main/java/processing/data/DoubleList.java +695 -748
  59. data/src/main/java/processing/data/FloatDict.java +702 -746
  60. data/src/main/java/processing/data/FloatList.java +697 -751
  61. data/src/main/java/processing/data/IntDict.java +673 -718
  62. data/src/main/java/processing/data/IntList.java +633 -699
  63. data/src/main/java/processing/data/JSONArray.java +873 -931
  64. data/src/main/java/processing/data/JSONObject.java +1165 -1262
  65. data/src/main/java/processing/data/JSONTokener.java +341 -351
  66. data/src/main/java/processing/data/LongDict.java +662 -707
  67. data/src/main/java/processing/data/LongList.java +634 -700
  68. data/src/main/java/processing/data/Sort.java +41 -37
  69. data/src/main/java/processing/data/StringDict.java +486 -522
  70. data/src/main/java/processing/data/StringList.java +580 -624
  71. data/src/main/java/processing/data/Table.java +3508 -3686
  72. data/src/main/java/processing/data/TableRow.java +183 -182
  73. data/src/main/java/processing/data/XML.java +883 -957
  74. data/src/main/java/processing/event/Event.java +66 -87
  75. data/src/main/java/processing/event/KeyEvent.java +41 -48
  76. data/src/main/java/processing/event/MouseEvent.java +93 -103
  77. data/src/main/java/processing/event/TouchEvent.java +6 -10
  78. data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
  79. data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
  80. data/src/main/java/processing/opengl/FontTexture.java +270 -290
  81. data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
  82. data/src/main/java/processing/opengl/LinePath.java +500 -543
  83. data/src/main/java/processing/opengl/LineStroker.java +582 -593
  84. data/src/main/java/processing/opengl/PGL.java +2881 -2904
  85. data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
  86. data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
  87. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
  88. data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
  89. data/src/main/java/processing/opengl/PShader.java +1257 -1260
  90. data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
  91. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
  92. data/src/main/java/processing/opengl/Texture.java +1397 -1462
  93. data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
  94. data/src/main/resources/icon/icon-1024.png +0 -0
  95. data/src/main/resources/icon/icon-128.png +0 -0
  96. data/src/main/resources/icon/icon-16.png +0 -0
  97. data/src/main/resources/icon/icon-256.png +0 -0
  98. data/src/main/resources/icon/icon-32.png +0 -0
  99. data/src/main/resources/icon/icon-48.png +0 -0
  100. data/src/main/resources/icon/icon-512.png +0 -0
  101. data/src/main/resources/icon/icon-64.png +0 -0
  102. data/vendors/Rakefile +1 -1
  103. metadata +12 -8
  104. 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
- * a sorted copy, use list.copy().sort().
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
- 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);
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
- /** Just an alias for append(), but matches pop() */
181
- public void push(float value) {
182
- append(value);
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
- public float pop() {
187
- if (count == 0) {
188
- throw new RuntimeException("Can't call pop() on an empty list");
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
- * 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);
169
+ /**
170
+ * Just an alias for append(), but matches pop()
171
+ */
172
+ public void push(float value) {
173
+ append(value);
205
174
  }
206
- float entry = data[index];
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
- // 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];
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
- } else {
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
- /** 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;
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
- /** 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;
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
- } else {
288
- for (int i = 0; i < count; i++) {
289
- if (data[i] == value) {
290
- data[i] = newValue;
291
- changed = true;
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
- 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);
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
- public void append(float[] values) {
315
- for (float v : values) {
316
- append(v);
300
+ public void append(float[] values) {
301
+ for (float v : values) {
302
+ append(v);
303
+ }
317
304
  }
318
- }
319
-
320
305
 
321
- public void append(FloatList list) {
322
- for (float v : list.values()) { // will concat the list...
323
- append(v);
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
- /** 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);
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
- float[] temp = new float[count + values.length];
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
- // Copy the old values, but not more than already exist
383
- System.arraycopy(data, 0, temp, 0, Math.min(count, index));
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
- // Copy the new values into the proper place
386
- System.arraycopy(values, 0, temp, index, values.length);
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
- // 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;
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
- data = temp;
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
- /** Return the first index of a particular value. */
449
- public int index(float what) {
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
- for (int i = 0; i < count; i++) {
460
- if (data[i] == what) {
461
- return i;
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
- * @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;
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
- 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()");
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
- public double sumDouble() {
644
- double sum = 0;
645
- for (int i = 0; i < count; i++) {
646
- sum += data[i];
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
- * 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
- }
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
- 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
- }
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
- @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
- }
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
- // use insert()
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
- * @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() {
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
- 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];
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
- 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 "";
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
- public void print() {
897
- for (int i = 0; i < count; i++) {
898
- System.out.format("[%d] %f%n", i, data[i]);
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
- * 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]);
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
- * Return this dictionary as a String in JSON format.
926
- */
927
- public String toJSON() {
928
- return "[ " + join(", ") + " ]";
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
- @Override
933
- public String toString() {
934
- return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
935
- }
878
+ @Override
879
+ public String toString() {
880
+ return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
881
+ }
936
882
  }