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