propane 3.10.0-java → 3.11.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/maven-wrapper.properties +1 -1
  3. data/CHANGELOG.md +2 -0
  4. data/README.md +7 -7
  5. data/lib/propane/app.rb +2 -5
  6. data/lib/propane/helper_methods.rb +6 -6
  7. data/lib/propane/version.rb +1 -1
  8. data/lib/{propane-3.10.0.jar → propane-3.11.0.jar} +0 -0
  9. data/pom.rb +6 -6
  10. data/pom.xml +6 -6
  11. data/propane.gemspec +3 -3
  12. data/src/main/java/monkstone/noise/OpenSimplex2F.java +838 -737
  13. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +8 -13
  14. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +14 -28
  15. data/src/main/java/processing/awt/PImageAWT.java +6 -4
  16. data/src/main/java/processing/core/PApplet.java +71 -59
  17. data/src/main/java/processing/core/PImage.java +14 -14
  18. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13 -13
  19. data/src/main/java/processing/opengl/PShader.java +1 -6
  20. data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
  21. data/{lib/java/processing/opengl → src/main/resources}/cursors/arrow.png +0 -0
  22. data/{lib/java/processing/opengl → src/main/resources}/cursors/cross.png +0 -0
  23. data/{lib/java/processing/opengl → src/main/resources}/cursors/hand.png +0 -0
  24. data/{lib/java/processing/opengl → src/main/resources}/cursors/license.txt +0 -0
  25. data/{lib/java/processing/opengl → src/main/resources}/cursors/move.png +0 -0
  26. data/{lib/java/processing/opengl → src/main/resources}/cursors/text.png +0 -0
  27. data/{lib/java/processing/opengl → src/main/resources}/cursors/wait.png +0 -0
  28. data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorFrag.glsl +0 -0
  29. data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorVert.glsl +0 -0
  30. data/{lib/java/processing/opengl → src/main/resources}/shaders/LightFrag.glsl +0 -0
  31. data/{lib/java/processing/opengl → src/main/resources}/shaders/LightVert.glsl +0 -0
  32. data/{lib/java/processing/opengl → src/main/resources}/shaders/LineFrag.glsl +0 -0
  33. data/{lib/java/processing/opengl → src/main/resources}/shaders/LineVert.glsl +0 -0
  34. data/{lib/java/processing/opengl → src/main/resources}/shaders/MaskFrag.glsl +0 -0
  35. data/{lib/java/processing/opengl → src/main/resources}/shaders/PointFrag.glsl +0 -0
  36. data/{lib/java/processing/opengl → src/main/resources}/shaders/PointVert.glsl +0 -0
  37. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexFrag.glsl +0 -0
  38. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightFrag.glsl +0 -0
  39. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightVert.glsl +0 -0
  40. data/{lib/java/processing/opengl → src/main/resources}/shaders/TexVert.glsl +0 -0
  41. data/test/test_helper.rb +1 -0
  42. data/vendors/Rakefile +1 -1
  43. metadata +29 -155
  44. data/lib/java/japplemenubar/JAppleMenuBar.java +0 -88
  45. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  46. data/lib/java/monkstone/ColorUtil.java +0 -127
  47. data/lib/java/monkstone/MathToolModule.java +0 -287
  48. data/lib/java/monkstone/PropaneLibrary.java +0 -46
  49. data/lib/java/monkstone/core/LibraryProxy.java +0 -136
  50. data/lib/java/monkstone/fastmath/DegLutTables.java +0 -111
  51. data/lib/java/monkstone/fastmath/Deglut.java +0 -71
  52. data/lib/java/monkstone/fastmath/package-info.java +0 -6
  53. data/lib/java/monkstone/filechooser/Chooser.java +0 -39
  54. data/lib/java/monkstone/noise/FastTerrain.java +0 -874
  55. data/lib/java/monkstone/noise/Noise.java +0 -90
  56. data/lib/java/monkstone/noise/NoiseGenerator.java +0 -75
  57. data/lib/java/monkstone/noise/NoiseMode.java +0 -28
  58. data/lib/java/monkstone/noise/OpenSimplex2F.java +0 -881
  59. data/lib/java/monkstone/noise/OpenSimplex2S.java +0 -1106
  60. data/lib/java/monkstone/noise/SmoothTerrain.java +0 -1099
  61. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +0 -164
  62. data/lib/java/monkstone/slider/CustomVerticalSlider.java +0 -178
  63. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +0 -145
  64. data/lib/java/monkstone/slider/SimpleSlider.java +0 -166
  65. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +0 -157
  66. data/lib/java/monkstone/slider/Slider.java +0 -61
  67. data/lib/java/monkstone/slider/SliderBar.java +0 -245
  68. data/lib/java/monkstone/slider/SliderGroup.java +0 -56
  69. data/lib/java/monkstone/slider/WheelHandler.java +0 -35
  70. data/lib/java/monkstone/vecmath/GfxRender.java +0 -86
  71. data/lib/java/monkstone/vecmath/JRender.java +0 -56
  72. data/lib/java/monkstone/vecmath/ShapeRender.java +0 -87
  73. data/lib/java/monkstone/vecmath/package-info.java +0 -20
  74. data/lib/java/monkstone/vecmath/vec2/Vec2.java +0 -802
  75. data/lib/java/monkstone/vecmath/vec2/package-info.java +0 -6
  76. data/lib/java/monkstone/vecmath/vec3/Vec3.java +0 -727
  77. data/lib/java/monkstone/vecmath/vec3/package-info.java +0 -6
  78. data/lib/java/monkstone/videoevent/CaptureEvent.java +0 -27
  79. data/lib/java/monkstone/videoevent/MovieEvent.java +0 -32
  80. data/lib/java/monkstone/videoevent/package-info.java +0 -20
  81. data/lib/java/processing/awt/PGraphicsJava2D.java +0 -3040
  82. data/lib/java/processing/awt/PImageAWT.java +0 -377
  83. data/lib/java/processing/awt/PShapeJava2D.java +0 -387
  84. data/lib/java/processing/awt/PSurfaceAWT.java +0 -1581
  85. data/lib/java/processing/awt/ShimAWT.java +0 -581
  86. data/lib/java/processing/core/PApplet.java +0 -15156
  87. data/lib/java/processing/core/PConstants.java +0 -523
  88. data/lib/java/processing/core/PFont.java +0 -1126
  89. data/lib/java/processing/core/PGraphics.java +0 -8600
  90. data/lib/java/processing/core/PImage.java +0 -3377
  91. data/lib/java/processing/core/PMatrix.java +0 -208
  92. data/lib/java/processing/core/PMatrix2D.java +0 -562
  93. data/lib/java/processing/core/PMatrix3D.java +0 -890
  94. data/lib/java/processing/core/PShape.java +0 -3561
  95. data/lib/java/processing/core/PShapeOBJ.java +0 -483
  96. data/lib/java/processing/core/PShapeSVG.java +0 -2016
  97. data/lib/java/processing/core/PStyle.java +0 -63
  98. data/lib/java/processing/core/PSurface.java +0 -198
  99. data/lib/java/processing/core/PSurfaceNone.java +0 -431
  100. data/lib/java/processing/core/PVector.java +0 -1066
  101. data/lib/java/processing/core/ThinkDifferent.java +0 -115
  102. data/lib/java/processing/data/DoubleDict.java +0 -850
  103. data/lib/java/processing/data/DoubleList.java +0 -928
  104. data/lib/java/processing/data/FloatDict.java +0 -847
  105. data/lib/java/processing/data/FloatList.java +0 -936
  106. data/lib/java/processing/data/IntDict.java +0 -807
  107. data/lib/java/processing/data/IntList.java +0 -936
  108. data/lib/java/processing/data/JSONArray.java +0 -1260
  109. data/lib/java/processing/data/JSONObject.java +0 -2282
  110. data/lib/java/processing/data/JSONTokener.java +0 -435
  111. data/lib/java/processing/data/LongDict.java +0 -802
  112. data/lib/java/processing/data/LongList.java +0 -937
  113. data/lib/java/processing/data/Sort.java +0 -46
  114. data/lib/java/processing/data/StringDict.java +0 -613
  115. data/lib/java/processing/data/StringList.java +0 -800
  116. data/lib/java/processing/data/Table.java +0 -4936
  117. data/lib/java/processing/data/TableRow.java +0 -198
  118. data/lib/java/processing/data/XML.java +0 -1156
  119. data/lib/java/processing/dxf/RawDXF.java +0 -404
  120. data/lib/java/processing/event/Event.java +0 -125
  121. data/lib/java/processing/event/KeyEvent.java +0 -70
  122. data/lib/java/processing/event/MouseEvent.java +0 -114
  123. data/lib/java/processing/event/TouchEvent.java +0 -57
  124. data/lib/java/processing/javafx/PGraphicsFX2D.java +0 -32
  125. data/lib/java/processing/javafx/PSurfaceFX.java +0 -173
  126. data/lib/java/processing/net/Client.java +0 -744
  127. data/lib/java/processing/net/Server.java +0 -388
  128. data/lib/java/processing/opengl/FontTexture.java +0 -378
  129. data/lib/java/processing/opengl/FrameBuffer.java +0 -513
  130. data/lib/java/processing/opengl/LinePath.java +0 -627
  131. data/lib/java/processing/opengl/LineStroker.java +0 -681
  132. data/lib/java/processing/opengl/PGL.java +0 -3483
  133. data/lib/java/processing/opengl/PGraphics2D.java +0 -615
  134. data/lib/java/processing/opengl/PGraphics3D.java +0 -281
  135. data/lib/java/processing/opengl/PGraphicsOpenGL.java +0 -13753
  136. data/lib/java/processing/opengl/PJOGL.java +0 -2008
  137. data/lib/java/processing/opengl/PShader.java +0 -1484
  138. data/lib/java/processing/opengl/PShapeOpenGL.java +0 -5269
  139. data/lib/java/processing/opengl/PSurfaceJOGL.java +0 -1385
  140. data/lib/java/processing/opengl/Texture.java +0 -1696
  141. data/lib/java/processing/opengl/VertexBuffer.java +0 -88
  142. data/lib/java/processing/pdf/PGraphicsPDF.java +0 -581
  143. data/lib/java/processing/svg/PGraphicsSVG.java +0 -378
  144. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  145. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  146. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  147. data/src/main/java/processing/opengl/cursors/license.txt +0 -27
  148. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  149. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  150. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  151. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +0 -32
  152. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +0 -34
  153. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +0 -33
  154. data/src/main/java/processing/opengl/shaders/LightVert.glsl +0 -151
  155. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +0 -32
  156. data/src/main/java/processing/opengl/shaders/LineVert.glsl +0 -100
  157. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +0 -40
  158. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +0 -32
  159. data/src/main/java/processing/opengl/shaders/PointVert.glsl +0 -56
  160. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +0 -37
  161. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +0 -37
  162. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +0 -157
  163. data/src/main/java/processing/opengl/shaders/TexVert.glsl +0 -38
@@ -1,850 +0,0 @@
1
- package processing.data;
2
-
3
- import java.io.*;
4
- import java.util.HashMap;
5
- import java.util.Iterator;
6
- import java.util.Map;
7
- import java.util.NoSuchElementException;
8
-
9
- import processing.core.PApplet;
10
-
11
-
12
- /**
13
- * A simple table class to use a String as a lookup for an double value.
14
- *
15
- * @nowebref
16
- * @see IntDict
17
- * @see StringDict
18
- */
19
- public class DoubleDict {
20
-
21
- /** Number of elements in the table */
22
- protected int count;
23
-
24
- protected String[] keys;
25
- protected double[] values;
26
-
27
- /** Internal implementation for faster lookups */
28
- private HashMap<String, Integer> indices = new HashMap<>();
29
-
30
-
31
- public DoubleDict() {
32
- count = 0;
33
- keys = new String[10];
34
- values = new double[10];
35
- }
36
-
37
-
38
- /**
39
- * Create a new lookup with a specific size. This is more efficient than not
40
- * specifying a size. Use it when you know the rough size of the thing you're creating.
41
- *
42
- * @nowebref
43
- */
44
- public DoubleDict(int length) {
45
- count = 0;
46
- keys = new String[length];
47
- values = new double[length];
48
- }
49
-
50
-
51
- /**
52
- * Read a set of entries from a Reader that has each key/value pair on
53
- * a single line, separated by a tab.
54
- *
55
- * @nowebref
56
- */
57
- public DoubleDict(BufferedReader reader) {
58
- String[] lines = PApplet.loadStrings(reader);
59
- keys = new String[lines.length];
60
- values = new double[lines.length];
61
-
62
- for (int i = 0; i < lines.length; i++) {
63
- String[] pieces = PApplet.split(lines[i], '\t');
64
- if (pieces.length == 2) {
65
- keys[count] = pieces[0];
66
- values[count] = PApplet.parseFloat(pieces[1]);
67
- indices.put(pieces[0], count);
68
- count++;
69
- }
70
- }
71
- }
72
-
73
-
74
- /**
75
- * @nowebref
76
- */
77
- public DoubleDict(String[] keys, double[] values) {
78
- if (keys.length != values.length) {
79
- throw new IllegalArgumentException("key and value arrays must be the same length");
80
- }
81
- this.keys = keys;
82
- this.values = values;
83
- count = keys.length;
84
- for (int i = 0; i < count; i++) {
85
- indices.put(keys[i], i);
86
- }
87
- }
88
-
89
-
90
- /**
91
- * Constructor to allow (more intuitive) inline initialization, e.g.:
92
- * <pre>
93
- * new FloatDict(new Object[][] {
94
- * { "key1", 1 },
95
- * { "key2", 2 }
96
- * });
97
- * </pre>
98
- */
99
- public DoubleDict(Object[][] pairs) {
100
- count = pairs.length;
101
- this.keys = new String[count];
102
- this.values = new double[count];
103
- for (int i = 0; i < count; i++) {
104
- keys[i] = (String) pairs[i][0];
105
- values[i] = (Float) pairs[i][1];
106
- indices.put(keys[i], i);
107
- }
108
- }
109
-
110
-
111
- public DoubleDict(Map<String, Double> incoming) {
112
- count = incoming.size();
113
- keys = new String[count];
114
- values = new double[count];
115
- int index = 0;
116
- for (Map.Entry<String, Double> e : incoming.entrySet()) {
117
- keys[index] = e.getKey();
118
- values[index] = e.getValue();
119
- indices.put(keys[index], index);
120
- index++;
121
- }
122
- }
123
-
124
-
125
- /**
126
- * @webref doubledict:method
127
- * @brief Returns the number of key/value pairs
128
- */
129
- public int size() {
130
- return count;
131
- }
132
-
133
-
134
- /**
135
- * Resize the internal data, this can only be used to shrink the list.
136
- * Helpful for situations like sorting and then grabbing the top 50 entries.
137
- */
138
- public void resize(int length) {
139
- if (length == count) return;
140
-
141
- if (length > count) {
142
- throw new IllegalArgumentException("resize() can only be used to shrink the dictionary");
143
- }
144
- if (length < 1) {
145
- throw new IllegalArgumentException("resize(" + length + ") is too small, use 1 or higher");
146
- }
147
-
148
- String[] newKeys = new String[length];
149
- double[] newValues = new double[length];
150
- PApplet.arrayCopy(keys, newKeys, length);
151
- PApplet.arrayCopy(values, newValues, length);
152
- keys = newKeys;
153
- values = newValues;
154
- count = length;
155
- resetIndices();
156
- }
157
-
158
-
159
- /**
160
- * Remove all entries.
161
- *
162
- * @webref doubledict:method
163
- * @brief Remove all entries
164
- */
165
- public void clear() {
166
- count = 0;
167
- indices = new HashMap<>();
168
- }
169
-
170
-
171
- private void resetIndices() {
172
- indices = new HashMap<>(count);
173
- for (int i = 0; i < count; i++) {
174
- indices.put(keys[i], i);
175
- }
176
- }
177
-
178
-
179
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
180
-
181
-
182
- public class Entry {
183
- public String key;
184
- public double value;
185
-
186
- Entry(String key, double value) {
187
- this.key = key;
188
- this.value = value;
189
- }
190
- }
191
-
192
-
193
- public Iterable<Entry> entries() {
194
- return new Iterable<Entry>() {
195
-
196
- public Iterator<Entry> iterator() {
197
- return entryIterator();
198
- }
199
- };
200
- }
201
-
202
-
203
- public Iterator<Entry> entryIterator() {
204
- return new Iterator<Entry>() {
205
- int index = -1;
206
-
207
- public void remove() {
208
- removeIndex(index);
209
- index--;
210
- }
211
-
212
- public Entry next() {
213
- ++index;
214
- Entry e = new Entry(keys[index], values[index]);
215
- return e;
216
- }
217
-
218
- public boolean hasNext() {
219
- return index+1 < size();
220
- }
221
- };
222
- }
223
-
224
-
225
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
226
-
227
-
228
- public String key(int index) {
229
- return keys[index];
230
- }
231
-
232
-
233
- protected void crop() {
234
- if (count != keys.length) {
235
- keys = PApplet.subset(keys, 0, count);
236
- values = PApplet.subset(values, 0, count);
237
- }
238
- }
239
-
240
-
241
- public Iterable<String> keys() {
242
- return new Iterable<String>() {
243
-
244
- @Override
245
- public Iterator<String> iterator() {
246
- return keyIterator();
247
- }
248
- };
249
- }
250
-
251
-
252
- // Use this to iterate when you want to be able to remove elements along the way
253
- public Iterator<String> keyIterator() {
254
- return new Iterator<String>() {
255
- int index = -1;
256
-
257
- public void remove() {
258
- removeIndex(index);
259
- index--;
260
- }
261
-
262
- public String next() {
263
- return key(++index);
264
- }
265
-
266
- public boolean hasNext() {
267
- return index+1 < size();
268
- }
269
- };
270
- }
271
-
272
-
273
- /**
274
- * Return a copy of the internal keys array. This array can be modified.
275
- *
276
- * @webref doubledict:method
277
- * @brief Return a copy of the internal keys array
278
- */
279
- public String[] keyArray() {
280
- crop();
281
- return keyArray(null);
282
- }
283
-
284
-
285
- public String[] keyArray(String[] outgoing) {
286
- if (outgoing == null || outgoing.length != count) {
287
- outgoing = new String[count];
288
- }
289
- System.arraycopy(keys, 0, outgoing, 0, count);
290
- return outgoing;
291
- }
292
-
293
-
294
- public double value(int index) {
295
- return values[index];
296
- }
297
-
298
-
299
- /**
300
- * @webref doubledict:method
301
- * @brief Return the internal array being used to store the values
302
- */
303
- public Iterable<Double> values() {
304
- return new Iterable<Double>() {
305
-
306
- @Override
307
- public Iterator<Double> iterator() {
308
- return valueIterator();
309
- }
310
- };
311
- }
312
-
313
-
314
- public Iterator<Double> valueIterator() {
315
- return new Iterator<Double>() {
316
- int index = -1;
317
-
318
- public void remove() {
319
- removeIndex(index);
320
- index--;
321
- }
322
-
323
- public Double next() {
324
- return value(++index);
325
- }
326
-
327
- public boolean hasNext() {
328
- return index+1 < size();
329
- }
330
- };
331
- }
332
-
333
-
334
- /**
335
- * Create a new array and copy each of the values into it.
336
- *
337
- * @webref doubledict:method
338
- * @brief Create a new array and copy each of the values into it
339
- */
340
- public double[] valueArray() {
341
- crop();
342
- return valueArray(null);
343
- }
344
-
345
-
346
- /**
347
- * Fill an already-allocated array with the values (more efficient than
348
- * creating a new array each time). If 'array' is null, or not the same
349
- * size as the number of values, a new array will be allocated and returned.
350
- */
351
- public double[] valueArray(double[] array) {
352
- if (array == null || array.length != size()) {
353
- array = new double[count];
354
- }
355
- System.arraycopy(values, 0, array, 0, count);
356
- return array;
357
- }
358
-
359
-
360
- /**
361
- * Return a value for the specified key.
362
- *
363
- * @webref doubledict:method
364
- * @brief Return a value for the specified key
365
- */
366
- public double get(String key) {
367
- int index = index(key);
368
- if (index == -1) {
369
- throw new IllegalArgumentException("No key named '" + key + "'");
370
- }
371
- return values[index];
372
- }
373
-
374
-
375
- public double get(String key, double alternate) {
376
- int index = index(key);
377
- if (index == -1) {
378
- return alternate;
379
- }
380
- return values[index];
381
- }
382
-
383
-
384
- /**
385
- * @webref doubledict:method
386
- * @brief Create a new key/value pair or change the value of one
387
- */
388
- public void set(String key, double amount) {
389
- int index = index(key);
390
- if (index == -1) {
391
- create(key, amount);
392
- } else {
393
- values[index] = amount;
394
- }
395
- }
396
-
397
-
398
- public void setIndex(int index, String key, double value) {
399
- if (index < 0 || index >= count) {
400
- throw new ArrayIndexOutOfBoundsException(index);
401
- }
402
- keys[index] = key;
403
- values[index] = value;
404
- }
405
-
406
-
407
- /**
408
- * @webref doubledict:method
409
- * @brief Check if a key is a part of the data structure
410
- */
411
- public boolean hasKey(String key) {
412
- return index(key) != -1;
413
- }
414
-
415
-
416
- /**
417
- * @webref doubledict:method
418
- * @brief Add to a value
419
- */
420
- public void add(String key, double amount) {
421
- int index = index(key);
422
- if (index == -1) {
423
- create(key, amount);
424
- } else {
425
- values[index] += amount;
426
- }
427
- }
428
-
429
-
430
- /**
431
- * @webref doubledict:method
432
- * @brief Subtract from a value
433
- */
434
- public void sub(String key, double amount) {
435
- add(key, -amount);
436
- }
437
-
438
-
439
- /**
440
- * @webref doubledict:method
441
- * @brief Multiply a value
442
- */
443
- public void mult(String key, double amount) {
444
- int index = index(key);
445
- if (index != -1) {
446
- values[index] *= amount;
447
- }
448
- }
449
-
450
-
451
- /**
452
- * @webref doubledict:method
453
- * @brief Divide a value
454
- */
455
- public void div(String key, double amount) {
456
- int index = index(key);
457
- if (index != -1) {
458
- values[index] /= amount;
459
- }
460
- }
461
-
462
-
463
- private void checkMinMax(String functionName) {
464
- if (count == 0) {
465
- String msg =
466
- String.format("Cannot use %s() on an empty %s.",
467
- functionName, getClass().getSimpleName());
468
- throw new RuntimeException(msg);
469
- }
470
- }
471
-
472
-
473
- /**
474
- * @webref doublelist:method
475
- * @brief Return the smallest value
476
- */
477
- public int minIndex() {
478
- //checkMinMax("minIndex");
479
- if (count == 0) return -1;
480
-
481
- // Will still return NaN if there are 1 or more entries, and they're all NaN
482
- double m = Float.NaN;
483
- int mi = -1;
484
- for (int i = 0; i < count; i++) {
485
- // find one good value to start
486
- if (values[i] == values[i]) {
487
- m = values[i];
488
- mi = i;
489
-
490
- // calculate the rest
491
- for (int j = i+1; j < count; j++) {
492
- double d = values[j];
493
- if ((d == d) && (d < m)) {
494
- m = values[j];
495
- mi = j;
496
- }
497
- }
498
- break;
499
- }
500
- }
501
- return mi;
502
- }
503
-
504
-
505
- // return the key for the minimum value
506
- public String minKey() {
507
- checkMinMax("minKey");
508
- int index = minIndex();
509
- if (index == -1) {
510
- return null;
511
- }
512
- return keys[index];
513
- }
514
-
515
-
516
- // return the minimum value, or throw an error if there are no values
517
- public double minValue() {
518
- checkMinMax("minValue");
519
- int index = minIndex();
520
- if (index == -1) {
521
- return Float.NaN;
522
- }
523
- return values[index];
524
- }
525
-
526
-
527
- /**
528
- * @webref doublelist:method
529
- * @brief Return the largest value
530
- */
531
- // The index of the entry that has the max value. Reference above is incorrect.
532
- public int maxIndex() {
533
- //checkMinMax("maxIndex");
534
- if (count == 0) {
535
- return -1;
536
- }
537
- // Will still return NaN if there is 1 or more entries, and they're all NaN
538
- double m = Double.NaN;
539
- int mi = -1;
540
- for (int i = 0; i < count; i++) {
541
- // find one good value to start
542
- if (values[i] == values[i]) {
543
- m = values[i];
544
- mi = i;
545
-
546
- // calculate the rest
547
- for (int j = i+1; j < count; j++) {
548
- double d = values[j];
549
- if (!Double.isNaN(d) && (d > m)) {
550
- m = values[j];
551
- mi = j;
552
- }
553
- }
554
- break;
555
- }
556
- }
557
- return mi;
558
- }
559
-
560
-
561
- /** The key for a max value; null if empty or everything is NaN (no max). */
562
- public String maxKey() {
563
- //checkMinMax("maxKey");
564
- int index = maxIndex();
565
- if (index == -1) {
566
- return null;
567
- }
568
- return keys[index];
569
- }
570
-
571
-
572
- /** The max value. (Or NaN if no entries or they're all NaN.) */
573
- public double maxValue() {
574
- //checkMinMax("maxValue");
575
- int index = maxIndex();
576
- if (index == -1) {
577
- return Float.NaN;
578
- }
579
- return values[index];
580
- }
581
-
582
-
583
- public double sum() {
584
- double sum = 0;
585
- for (int i = 0; i < count; i++) {
586
- sum += values[i];
587
- }
588
- return sum;
589
- }
590
-
591
-
592
- public int index(String what) {
593
- Integer found = indices.get(what);
594
- return (found == null) ? -1 : found.intValue();
595
- }
596
-
597
-
598
- protected void create(String what, double much) {
599
- if (count == keys.length) {
600
- keys = PApplet.expand(keys);
601
- values = PApplet.expand(values);
602
- }
603
- indices.put(what, Integer.valueOf(count));
604
- keys[count] = what;
605
- values[count] = much;
606
- count++;
607
- }
608
-
609
-
610
- /**
611
- * @webref doubledict:method
612
- * @brief Remove a key/value pair
613
- */
614
- public double remove(String key) {
615
- int index = index(key);
616
- if (index == -1) {
617
- throw new NoSuchElementException("'" + key + "' not found");
618
- }
619
- double value = values[index];
620
- removeIndex(index);
621
- return value;
622
- }
623
-
624
-
625
- public double removeIndex(int index) {
626
- if (index < 0 || index >= count) {
627
- throw new ArrayIndexOutOfBoundsException(index);
628
- }
629
- double value = values[index];
630
- indices.remove(keys[index]);
631
- for (int i = index; i < count-1; i++) {
632
- keys[i] = keys[i+1];
633
- values[i] = values[i+1];
634
- indices.put(keys[i], i);
635
- }
636
- count--;
637
- keys[count] = null;
638
- values[count] = 0;
639
- return value;
640
- }
641
-
642
-
643
- public void swap(int a, int b) {
644
- String tkey = keys[a];
645
- double tvalue = values[a];
646
- keys[a] = keys[b];
647
- values[a] = values[b];
648
- keys[b] = tkey;
649
- values[b] = tvalue;
650
-
651
- // indices.put(keys[a], Integer.valueOf(a));
652
- // indices.put(keys[b], Integer.valueOf(b));
653
- }
654
-
655
-
656
- /**
657
- * Sort the keys alphabetically (ignoring case). Uses the value as a
658
- * tie-breaker (only really possible with a key that has a case change).
659
- *
660
- * @webref doubledict:method
661
- * @brief Sort the keys alphabetically
662
- */
663
- public void sortKeys() {
664
- sortImpl(true, false, true);
665
- }
666
-
667
-
668
- /**
669
- * @webref doubledict:method
670
- * @brief Sort the keys alphabetically in reverse
671
- */
672
- public void sortKeysReverse() {
673
- sortImpl(true, true, true);
674
- }
675
-
676
-
677
- /**
678
- * Sort by values in descending order (largest value will be at [0]).
679
- *
680
- * @webref doubledict:method
681
- * @brief Sort by values in ascending order
682
- */
683
- public void sortValues() {
684
- sortValues(true);
685
- }
686
-
687
-
688
- /**
689
- * Set true to ensure that the order returned is identical. Slightly
690
- * slower because the tie-breaker for identical values compares the keys.
691
- * @param stable
692
- */
693
- public void sortValues(boolean stable) {
694
- sortImpl(false, false, stable);
695
- }
696
-
697
-
698
- /**
699
- * @webref doubledict:method
700
- * @brief Sort by values in descending order
701
- */
702
- public void sortValuesReverse() {
703
- sortValuesReverse(true);
704
- }
705
-
706
-
707
- public void sortValuesReverse(boolean stable) {
708
- sortImpl(false, true, stable);
709
- }
710
-
711
-
712
- protected void sortImpl(final boolean useKeys, final boolean reverse,
713
- final boolean stable) {
714
- Sort s = new Sort() {
715
- @Override
716
- public int size() {
717
- if (useKeys) {
718
- return count; // don't worry about NaN values
719
-
720
- } else if (count == 0) { // skip the NaN check, it'll AIOOBE
721
- return 0;
722
-
723
- } else { // first move NaN values to the end of the list
724
- int right = count - 1;
725
- while (values[right] != values[right]) {
726
- right--;
727
- if (right == -1) {
728
- return 0; // all values are NaN
729
- }
730
- }
731
- for (int i = right; i >= 0; --i) {
732
- if (Double.isNaN(values[i])) {
733
- swap(i, right);
734
- --right;
735
- }
736
- }
737
- return right + 1;
738
- }
739
- }
740
-
741
- @Override
742
- public int compare(int a, int b) {
743
- double diff = 0;
744
- if (useKeys) {
745
- diff = keys[a].compareToIgnoreCase(keys[b]);
746
- if (diff == 0) {
747
- diff = values[a] - values[b];
748
- }
749
- } else { // sort values
750
- diff = values[a] - values[b];
751
- if (diff == 0 && stable) {
752
- diff = keys[a].compareToIgnoreCase(keys[b]);
753
- }
754
- }
755
- if (diff == 0) {
756
- return 0;
757
- } else if (reverse) {
758
- return diff < 0 ? 1 : -1;
759
- } else {
760
- return diff < 0 ? -1 : 1;
761
- }
762
- }
763
-
764
- @Override
765
- public void swap(int a, int b) {
766
- DoubleDict.this.swap(a, b);
767
- }
768
- };
769
- s.run();
770
-
771
- // Set the indices after sort/swaps (performance fix 160411)
772
- resetIndices();
773
- }
774
-
775
-
776
- /**
777
- * Sum all of the values in this dictionary, then return a new FloatDict of
778
- * each key, divided by the total sum. The total for all values will be ~1.0.
779
- * @return a FloatDict with the original keys, mapped to their pct of the total
780
- */
781
- public DoubleDict getPercent() {
782
- double sum = sum();
783
- DoubleDict outgoing = new DoubleDict();
784
- for (int i = 0; i < size(); i++) {
785
- double percent = value(i) / sum;
786
- outgoing.set(key(i), percent);
787
- }
788
- return outgoing;
789
- }
790
-
791
-
792
- /** Returns a duplicate copy of this object. */
793
- public DoubleDict copy() {
794
- DoubleDict outgoing = new DoubleDict(count);
795
- System.arraycopy(keys, 0, outgoing.keys, 0, count);
796
- System.arraycopy(values, 0, outgoing.values, 0, count);
797
- for (int i = 0; i < count; i++) {
798
- outgoing.indices.put(keys[i], i);
799
- }
800
- outgoing.count = count;
801
- return outgoing;
802
- }
803
-
804
-
805
- public void print() {
806
- for (int i = 0; i < size(); i++) {
807
- System.out.println(keys[i] + " = " + values[i]);
808
- }
809
- }
810
-
811
-
812
- /**
813
- * Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
814
- */
815
- public void save(File file) {
816
- PrintWriter writer = PApplet.createWriter(file);
817
- write(writer);
818
- writer.close();
819
- }
820
-
821
-
822
- /**
823
- * Write tab-delimited entries out to
824
- * @param writer
825
- */
826
- public void write(PrintWriter writer) {
827
- for (int i = 0; i < count; i++) {
828
- writer.println(keys[i] + "\t" + values[i]);
829
- }
830
- writer.flush();
831
- }
832
-
833
-
834
- /**
835
- * Return this dictionary as a String in JSON format.
836
- */
837
- public String toJSON() {
838
- StringList items = new StringList();
839
- for (int i = 0; i < count; i++) {
840
- items.append(JSONObject.quote(keys[i])+ ": " + values[i]);
841
- }
842
- return "{ " + items.join(", ") + " }";
843
- }
844
-
845
-
846
- @Override
847
- public String toString() {
848
- return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
849
- }
850
- }