propane 3.6.0-java → 3.10.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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +5 -1
  5. data/README.md +6 -13
  6. data/Rakefile +7 -6
  7. data/lib/java/japplemenubar/JAppleMenuBar.java +88 -0
  8. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  9. data/lib/java/monkstone/ColorUtil.java +127 -0
  10. data/lib/java/monkstone/MathToolModule.java +287 -0
  11. data/lib/java/monkstone/PropaneLibrary.java +46 -0
  12. data/lib/java/monkstone/core/LibraryProxy.java +136 -0
  13. data/lib/java/monkstone/fastmath/DegLutTables.java +111 -0
  14. data/lib/java/monkstone/fastmath/Deglut.java +71 -0
  15. data/lib/java/monkstone/fastmath/package-info.java +6 -0
  16. data/lib/java/monkstone/filechooser/Chooser.java +39 -0
  17. data/lib/java/monkstone/noise/FastTerrain.java +874 -0
  18. data/lib/java/monkstone/noise/Noise.java +90 -0
  19. data/lib/java/monkstone/noise/NoiseGenerator.java +75 -0
  20. data/lib/java/monkstone/noise/NoiseMode.java +28 -0
  21. data/lib/java/monkstone/noise/OpenSimplex2F.java +881 -0
  22. data/lib/java/monkstone/noise/OpenSimplex2S.java +1106 -0
  23. data/lib/java/monkstone/noise/SmoothTerrain.java +1099 -0
  24. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +164 -0
  25. data/lib/java/monkstone/slider/CustomVerticalSlider.java +178 -0
  26. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +145 -0
  27. data/lib/java/monkstone/slider/SimpleSlider.java +166 -0
  28. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +157 -0
  29. data/lib/java/monkstone/slider/Slider.java +61 -0
  30. data/lib/java/monkstone/slider/SliderBar.java +245 -0
  31. data/lib/java/monkstone/slider/SliderGroup.java +56 -0
  32. data/lib/java/monkstone/slider/WheelHandler.java +35 -0
  33. data/lib/java/monkstone/vecmath/GfxRender.java +86 -0
  34. data/lib/java/monkstone/vecmath/JRender.java +56 -0
  35. data/lib/java/monkstone/vecmath/ShapeRender.java +87 -0
  36. data/lib/java/monkstone/vecmath/package-info.java +20 -0
  37. data/lib/java/monkstone/vecmath/vec2/Vec2.java +802 -0
  38. data/lib/java/monkstone/vecmath/vec2/package-info.java +6 -0
  39. data/lib/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  40. data/lib/java/monkstone/vecmath/vec3/package-info.java +6 -0
  41. data/lib/java/monkstone/videoevent/CaptureEvent.java +27 -0
  42. data/lib/java/monkstone/videoevent/MovieEvent.java +32 -0
  43. data/lib/java/monkstone/videoevent/package-info.java +20 -0
  44. data/lib/java/processing/awt/PGraphicsJava2D.java +3040 -0
  45. data/lib/java/processing/awt/PImageAWT.java +377 -0
  46. data/lib/java/processing/awt/PShapeJava2D.java +387 -0
  47. data/lib/java/processing/awt/PSurfaceAWT.java +1581 -0
  48. data/lib/java/processing/awt/ShimAWT.java +581 -0
  49. data/lib/java/processing/core/PApplet.java +15156 -0
  50. data/lib/java/processing/core/PConstants.java +523 -0
  51. data/lib/java/processing/core/PFont.java +1126 -0
  52. data/lib/java/processing/core/PGraphics.java +8600 -0
  53. data/lib/java/processing/core/PImage.java +3377 -0
  54. data/lib/java/processing/core/PMatrix.java +208 -0
  55. data/lib/java/processing/core/PMatrix2D.java +562 -0
  56. data/lib/java/processing/core/PMatrix3D.java +890 -0
  57. data/lib/java/processing/core/PShape.java +3561 -0
  58. data/lib/java/processing/core/PShapeOBJ.java +483 -0
  59. data/lib/java/processing/core/PShapeSVG.java +2016 -0
  60. data/lib/java/processing/core/PStyle.java +63 -0
  61. data/lib/java/processing/core/PSurface.java +198 -0
  62. data/lib/java/processing/core/PSurfaceNone.java +431 -0
  63. data/lib/java/processing/core/PVector.java +1066 -0
  64. data/lib/java/processing/core/ThinkDifferent.java +115 -0
  65. data/lib/java/processing/data/DoubleDict.java +850 -0
  66. data/lib/java/processing/data/DoubleList.java +928 -0
  67. data/lib/java/processing/data/FloatDict.java +847 -0
  68. data/lib/java/processing/data/FloatList.java +936 -0
  69. data/lib/java/processing/data/IntDict.java +807 -0
  70. data/lib/java/processing/data/IntList.java +936 -0
  71. data/lib/java/processing/data/JSONArray.java +1260 -0
  72. data/lib/java/processing/data/JSONObject.java +2282 -0
  73. data/lib/java/processing/data/JSONTokener.java +435 -0
  74. data/lib/java/processing/data/LongDict.java +802 -0
  75. data/lib/java/processing/data/LongList.java +937 -0
  76. data/lib/java/processing/data/Sort.java +46 -0
  77. data/lib/java/processing/data/StringDict.java +613 -0
  78. data/lib/java/processing/data/StringList.java +800 -0
  79. data/lib/java/processing/data/Table.java +4936 -0
  80. data/lib/java/processing/data/TableRow.java +198 -0
  81. data/lib/java/processing/data/XML.java +1156 -0
  82. data/lib/java/processing/dxf/RawDXF.java +404 -0
  83. data/lib/java/processing/event/Event.java +125 -0
  84. data/lib/java/processing/event/KeyEvent.java +70 -0
  85. data/lib/java/processing/event/MouseEvent.java +114 -0
  86. data/lib/java/processing/event/TouchEvent.java +57 -0
  87. data/lib/java/processing/javafx/PGraphicsFX2D.java +32 -0
  88. data/lib/java/processing/javafx/PSurfaceFX.java +173 -0
  89. data/lib/java/processing/net/Client.java +744 -0
  90. data/lib/java/processing/net/Server.java +388 -0
  91. data/lib/java/processing/opengl/FontTexture.java +378 -0
  92. data/lib/java/processing/opengl/FrameBuffer.java +513 -0
  93. data/lib/java/processing/opengl/LinePath.java +627 -0
  94. data/lib/java/processing/opengl/LineStroker.java +681 -0
  95. data/lib/java/processing/opengl/PGL.java +3483 -0
  96. data/lib/java/processing/opengl/PGraphics2D.java +615 -0
  97. data/lib/java/processing/opengl/PGraphics3D.java +281 -0
  98. data/lib/java/processing/opengl/PGraphicsOpenGL.java +13753 -0
  99. data/lib/java/processing/opengl/PJOGL.java +2008 -0
  100. data/lib/java/processing/opengl/PShader.java +1484 -0
  101. data/lib/java/processing/opengl/PShapeOpenGL.java +5269 -0
  102. data/lib/java/processing/opengl/PSurfaceJOGL.java +1385 -0
  103. data/lib/java/processing/opengl/Texture.java +1696 -0
  104. data/lib/java/processing/opengl/VertexBuffer.java +88 -0
  105. data/lib/java/processing/opengl/cursors/arrow.png +0 -0
  106. data/lib/java/processing/opengl/cursors/cross.png +0 -0
  107. data/lib/java/processing/opengl/cursors/hand.png +0 -0
  108. data/lib/java/processing/opengl/cursors/license.txt +27 -0
  109. data/lib/java/processing/opengl/cursors/move.png +0 -0
  110. data/lib/java/processing/opengl/cursors/text.png +0 -0
  111. data/lib/java/processing/opengl/cursors/wait.png +0 -0
  112. data/lib/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  113. data/lib/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  114. data/lib/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  115. data/lib/java/processing/opengl/shaders/LightVert.glsl +151 -0
  116. data/lib/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  117. data/lib/java/processing/opengl/shaders/LineVert.glsl +100 -0
  118. data/lib/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  119. data/lib/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  120. data/lib/java/processing/opengl/shaders/PointVert.glsl +56 -0
  121. data/lib/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  122. data/lib/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  123. data/lib/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  124. data/lib/java/processing/opengl/shaders/TexVert.glsl +38 -0
  125. data/lib/java/processing/pdf/PGraphicsPDF.java +581 -0
  126. data/lib/java/processing/svg/PGraphicsSVG.java +378 -0
  127. data/lib/propane/app.rb +9 -10
  128. data/lib/propane/runner.rb +10 -12
  129. data/lib/propane/version.rb +1 -1
  130. data/library/pdf/pdf.rb +7 -0
  131. data/library/svg/svg.rb +7 -0
  132. data/mvnw +3 -3
  133. data/mvnw.cmd +2 -2
  134. data/pom.rb +30 -3
  135. data/pom.xml +54 -3
  136. data/propane.gemspec +7 -3
  137. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  138. data/src/main/java/monkstone/MathToolModule.java +30 -30
  139. data/src/main/java/monkstone/PropaneLibrary.java +2 -0
  140. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  141. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  142. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  143. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  144. data/src/main/java/monkstone/noise/OpenSimplex2F.java +813 -0
  145. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
  146. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  147. data/src/main/java/monkstone/vecmath/JRender.java +6 -6
  148. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +20 -19
  149. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +12 -12
  150. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -3
  151. data/src/main/java/processing/core/PApplet.java +13242 -13374
  152. data/src/main/java/processing/core/PConstants.java +155 -163
  153. data/src/main/java/processing/core/PGraphics.java +118 -111
  154. data/src/main/java/processing/opengl/PJOGL.java +6 -5
  155. data/src/main/java/processing/pdf/PGraphicsPDF.java +581 -0
  156. data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
  157. data/test/deglut_spec_test.rb +2 -2
  158. data/vendors/Rakefile +1 -1
  159. metadata +146 -17
  160. data/library/simplex_noise/simplex_noise.rb +0 -5
  161. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -436
@@ -0,0 +1,627 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+ /*
4
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
5
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
+ *
7
+ * This code is free software; you can redistribute it and/or modify it
8
+ * under the terms of the GNU General Public License version 2 only, as
9
+ * published by the Free Software Foundation. Sun designates this
10
+ * particular file as subject to the "Classpath" exception as provided
11
+ * by Sun in the LICENSE file that accompanied this code.
12
+ *
13
+ * This code is distributed in the hope that it will be useful, but WITHOUT
14
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
+ * version 2 for more details (a copy is included in the LICENSE file that
17
+ * accompanied this code).
18
+ *
19
+ * You should have received a copy of the GNU General Public License version
20
+ * 2 along with this work; if not, write to the Free Software Foundation,
21
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22
+ *
23
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24
+ * CA 95054 USA or visit www.sun.com if you need additional information or
25
+ * have any questions.
26
+ */
27
+
28
+ package processing.opengl;
29
+
30
+ import processing.core.PMatrix2D;
31
+
32
+ /**
33
+ * The {@code LinePath} class allows to represent polygonal paths,
34
+ * potentially composed by several disjoint polygonal segments.
35
+ * It can be iterated by the {@link PathIterator} class including all
36
+ * of its segment types and winding rules
37
+ *
38
+ */
39
+ public class LinePath {
40
+ /**
41
+ * The winding rule constant for specifying an even-odd rule
42
+ * for determining the interior of a path.
43
+ * The even-odd rule specifies that a point lies inside the
44
+ * path if a ray drawn in any direction from that point to
45
+ * infinity is crossed by path segments an odd number of times.
46
+ */
47
+ public static final int WIND_EVEN_ODD = 0;
48
+
49
+ /**
50
+ * The winding rule constant for specifying a non-zero rule
51
+ * for determining the interior of a path.
52
+ * The non-zero rule specifies that a point lies inside the
53
+ * path if a ray drawn in any direction from that point to
54
+ * infinity is crossed by path segments a different number
55
+ * of times in the counter-clockwise direction than the
56
+ * clockwise direction.
57
+ */
58
+ public static final int WIND_NON_ZERO = 1;
59
+
60
+ /**
61
+ * Starts segment at a given position.
62
+ */
63
+ public static final byte SEG_MOVETO = 0;
64
+
65
+ /**
66
+ * Extends segment by adding a line to a given position.
67
+ */
68
+ public static final byte SEG_LINETO = 1;
69
+
70
+ /**
71
+ * Closes segment at current position.
72
+ */
73
+ public static final byte SEG_CLOSE = 2;
74
+
75
+ /**
76
+ * Joins path segments by extending their outside edges until they meet.
77
+ */
78
+ public final static int JOIN_MITER = 0;
79
+
80
+ /**
81
+ * Joins path segments by rounding off the corner at a radius of half the line
82
+ * width.
83
+ */
84
+ public final static int JOIN_ROUND = 1;
85
+
86
+ /**
87
+ * Joins path segments by connecting the outer corners of their wide outlines
88
+ * with a straight segment.
89
+ */
90
+ public final static int JOIN_BEVEL = 2;
91
+
92
+ /**
93
+ * Ends unclosed subpaths and dash segments with no added decoration.
94
+ */
95
+ public final static int CAP_BUTT = 0;
96
+
97
+ /**
98
+ * Ends unclosed subpaths and dash segments with a round decoration that has a
99
+ * radius equal to half of the width of the pen.
100
+ */
101
+ public final static int CAP_ROUND = 1;
102
+
103
+ /**
104
+ * Ends unclosed subpaths and dash segments with a square projection that
105
+ * extends beyond the end of the segment to a distance equal to half of the
106
+ * line width.
107
+ */
108
+ public final static int CAP_SQUARE = 2;
109
+
110
+ private static PMatrix2D identity = new PMatrix2D();
111
+
112
+ private static float defaultMiterlimit = 10.0f;
113
+
114
+ static final int INIT_SIZE = 20;
115
+
116
+ static final int EXPAND_MAX = 500;
117
+
118
+ protected byte[] pointTypes;
119
+
120
+ protected float[] floatCoords;
121
+
122
+ protected int[] pointColors;
123
+
124
+ protected int numTypes;
125
+
126
+ protected int numCoords;
127
+
128
+ protected int windingRule;
129
+
130
+
131
+ /**
132
+ * Constructs a new empty single precision {@code LinePath} object with a
133
+ * default winding rule of {@link #WIND_NON_ZERO}.
134
+ */
135
+ public LinePath() {
136
+ this(WIND_NON_ZERO, INIT_SIZE);
137
+ }
138
+
139
+
140
+ /**
141
+ * Constructs a new empty single precision {@code LinePath} object with the
142
+ * specified winding rule to control operations that require the interior of
143
+ * the path to be defined.
144
+ *
145
+ * @param rule
146
+ * the winding rule
147
+ * @see #WIND_EVEN_ODD
148
+ * @see #WIND_NON_ZERO
149
+ */
150
+ public LinePath(int rule) {
151
+ this(rule, INIT_SIZE);
152
+ }
153
+
154
+
155
+ /**
156
+ * Constructs a new {@code LinePath} object from the given specified initial
157
+ * values. This method is only intended for internal use and should not be
158
+ * made public if the other constructors for this class are ever exposed.
159
+ *
160
+ * @param rule
161
+ * the winding rule
162
+ * @param initialCapacity
163
+ * the size to make the initial array to store the path segment types
164
+ */
165
+ public LinePath(int rule, int initialCapacity) {
166
+ setWindingRule(rule);
167
+ this.pointTypes = new byte[initialCapacity];
168
+ floatCoords = new float[initialCapacity * 2];
169
+ pointColors = new int[initialCapacity];
170
+ }
171
+
172
+
173
+ void needRoom(boolean needMove, int newPoints) {
174
+ if (needMove && numTypes == 0) {
175
+ throw new RuntimeException("missing initial moveto "
176
+ + "in path definition");
177
+ }
178
+ int size = pointTypes.length;
179
+ if (numTypes >= size) {
180
+ int grow = size;
181
+ if (grow > EXPAND_MAX) {
182
+ grow = EXPAND_MAX;
183
+ }
184
+ pointTypes = copyOf(pointTypes, size + grow);
185
+ }
186
+ size = floatCoords.length;
187
+ if (numCoords + newPoints * 2 > size) {
188
+ int grow = size;
189
+ if (grow > EXPAND_MAX * 2) {
190
+ grow = EXPAND_MAX * 2;
191
+ }
192
+ if (grow < newPoints * 2) {
193
+ grow = newPoints * 2;
194
+ }
195
+ floatCoords = copyOf(floatCoords, size + grow);
196
+ }
197
+ size = pointColors.length;
198
+ if (numCoords/2 + newPoints > size) {
199
+ int grow = size;
200
+ if (grow > EXPAND_MAX) {
201
+ grow = EXPAND_MAX;
202
+ }
203
+ if (grow < newPoints) {
204
+ grow = newPoints;
205
+ }
206
+ pointColors = copyOf(pointColors, size + grow);
207
+ }
208
+ }
209
+
210
+
211
+ /**
212
+ * Adds a point to the path by moving to the specified coordinates specified
213
+ * in float precision.
214
+ * <p>
215
+ * This method provides a single precision variant of the double precision
216
+ * {@code moveTo()} method on the base {@code LinePath} class.
217
+ *
218
+ * @param x
219
+ * the specified X coordinate
220
+ * @param y
221
+ * the specified Y coordinate
222
+ * @param c
223
+ * @see LinePath#moveTo
224
+ */
225
+ public final void moveTo(float x, float y, int c) {
226
+ if (numTypes > 0 && pointTypes[numTypes - 1] == SEG_MOVETO) {
227
+ floatCoords[numCoords - 2] = x;
228
+ floatCoords[numCoords - 1] = y;
229
+ pointColors[numCoords/2-1] = c;
230
+ } else {
231
+ needRoom(false, 1);
232
+ pointTypes[numTypes++] = SEG_MOVETO;
233
+ floatCoords[numCoords++] = x;
234
+ floatCoords[numCoords++] = y;
235
+ pointColors[numCoords/2-1] = c;
236
+ }
237
+ }
238
+
239
+
240
+ /**
241
+ * Adds a point to the path by drawing a straight line from the current
242
+ * coordinates to the new specified coordinates specified in float precision.
243
+ * <p>
244
+ * This method provides a single precision variant of the double precision
245
+ * {@code lineTo()} method on the base {@code LinePath} class.
246
+ *
247
+ * @param x
248
+ * the specified X coordinate
249
+ * @param y
250
+ * the specified Y coordinate
251
+ * @param c
252
+ * @see LinePath#lineTo
253
+ */
254
+ public final void lineTo(float x, float y, int c) {
255
+ needRoom(true, 1);
256
+ pointTypes[numTypes++] = SEG_LINETO;
257
+ floatCoords[numCoords++] = x;
258
+ floatCoords[numCoords++] = y;
259
+ pointColors[numCoords/2-1] = c;
260
+ }
261
+
262
+
263
+ /**
264
+ * The iterator for this class is not multi-threaded safe, which means that
265
+ * the {@code LinePath} class does not guarantee that modifications to the
266
+ * geometry of this {@code LinePath} object do not affect any iterations of that
267
+ * geometry that are already in process.
268
+ * @return
269
+ */
270
+ public PathIterator getPathIterator() {
271
+ return new PathIterator(this);
272
+ }
273
+
274
+
275
+ /**
276
+ * Closes the current subpath by drawing a straight line back to the
277
+ * coordinates of the last {@code moveTo}. If the path is already closed then
278
+ * this method has no effect.
279
+ */
280
+ public final void closePath() {
281
+ if (numTypes == 0 || pointTypes[numTypes - 1] != SEG_CLOSE) {
282
+ needRoom(false, 0);
283
+ pointTypes[numTypes++] = SEG_CLOSE;
284
+ }
285
+ }
286
+
287
+
288
+ /**
289
+ * Returns the fill style winding rule.
290
+ *
291
+ * @return an integer representing the current winding rule.
292
+ * @see #WIND_EVEN_ODD
293
+ * @see #WIND_NON_ZERO
294
+ * @see #setWindingRule
295
+ */
296
+ public final int getWindingRule() {
297
+ return windingRule;
298
+ }
299
+
300
+
301
+ /**
302
+ * Sets the winding rule for this path to the specified value.
303
+ *
304
+ * @param rule
305
+ * an integer representing the specified winding rule
306
+ * @exception IllegalArgumentException
307
+ * if {@code rule} is not either {@link #WIND_EVEN_ODD} or
308
+ * {@link #WIND_NON_ZERO}
309
+ * @see #getWindingRule
310
+ */
311
+ public final void setWindingRule(int rule) {
312
+ if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) {
313
+ throw new IllegalArgumentException("winding rule must be "
314
+ + "WIND_EVEN_ODD or " + "WIND_NON_ZERO");
315
+ }
316
+ windingRule = rule;
317
+ }
318
+
319
+
320
+ /**
321
+ * Resets the path to empty. The append position is set back to the beginning
322
+ * of the path and all coordinates and point types are forgotten.
323
+ */
324
+ public final void reset() {
325
+ numTypes = numCoords = 0;
326
+ }
327
+
328
+
329
+ static public class PathIterator {
330
+ float[] floatCoords;
331
+
332
+ int typeIdx;
333
+
334
+ int pointIdx;
335
+
336
+ int colorIdx;
337
+
338
+ LinePath path;
339
+
340
+ static final int[] curvecoords = { 2, 2, 0 };
341
+
342
+ PathIterator(LinePath p2df) {
343
+ this.path = p2df;
344
+ this.floatCoords = p2df.floatCoords;
345
+ pointIdx = 0;
346
+ colorIdx = 0;
347
+ }
348
+
349
+ public int currentSegment(float[] coords) {
350
+ int type = path.pointTypes[typeIdx];
351
+ int numCoords = curvecoords[type];
352
+ if (numCoords > 0) {
353
+ System.arraycopy(floatCoords, pointIdx, coords, 0, numCoords);
354
+ int color = path.pointColors[colorIdx];
355
+ coords[numCoords + 0] = (color >> 24) & 0xFF;
356
+ coords[numCoords + 1] = (color >> 16) & 0xFF;
357
+ coords[numCoords + 2] = (color >> 8) & 0xFF;
358
+ coords[numCoords + 3] = (color) & 0xFF;
359
+ }
360
+ return type;
361
+ }
362
+
363
+ public int currentSegment(double[] coords) {
364
+ int type = path.pointTypes[typeIdx];
365
+ int numCoords = curvecoords[type];
366
+ if (numCoords > 0) {
367
+ for (int i = 0; i < numCoords; i++) {
368
+ coords[i] = floatCoords[pointIdx + i];
369
+ }
370
+ int color = path.pointColors[colorIdx];
371
+ coords[numCoords + 0] = (color >> 24) & 0xFF;
372
+ coords[numCoords + 1] = (color >> 16) & 0xFF;
373
+ coords[numCoords + 2] = (color >> 8) & 0xFF;
374
+ coords[numCoords + 3] = (color) & 0xFF;
375
+ }
376
+ return type;
377
+ }
378
+
379
+ public int getWindingRule() {
380
+ return path.getWindingRule();
381
+ }
382
+
383
+ public boolean isDone() {
384
+ return (typeIdx >= path.numTypes);
385
+ }
386
+
387
+ public void next() {
388
+ int type = path.pointTypes[typeIdx++];
389
+ if (0 < curvecoords[type]) {
390
+ pointIdx += curvecoords[type];
391
+ colorIdx++;
392
+ }
393
+ }
394
+ }
395
+
396
+
397
+ /////////////////////////////////////////////////////////////////////////////
398
+ //
399
+ // Stroked path methods
400
+
401
+
402
+ static public LinePath createStrokedPath(LinePath src, float weight,
403
+ int caps, int join) {
404
+ return createStrokedPath(src, weight, caps, join, defaultMiterlimit, null);
405
+ }
406
+
407
+
408
+ static public LinePath createStrokedPath(LinePath src, float weight,
409
+ int caps, int join, float miterlimit) {
410
+ return createStrokedPath(src, weight, caps, join, miterlimit, null);
411
+ }
412
+
413
+
414
+ /**
415
+ * Constructs a solid <code>LinePath</code> with the specified attributes.
416
+ *
417
+ * @param src
418
+ * the original path to be stroked
419
+ * @param weight
420
+ * the weight of the stroked path
421
+ * @param caps
422
+ * the decoration of the ends of the segments in the path
423
+ * @param join
424
+ * the decoration applied where path segments meet
425
+ * @param miterlimit
426
+ * @param transform
427
+ * @return
428
+ *
429
+ */
430
+ static public LinePath createStrokedPath(LinePath src, float weight,
431
+ int caps, int join,
432
+ float miterlimit, PMatrix2D transform) {
433
+ final LinePath dest = new LinePath();
434
+
435
+ strokeTo(src, weight, caps, join, miterlimit, transform, new LineStroker() {
436
+ @Override
437
+ public void moveTo(int x0, int y0, int c0) {
438
+ dest.moveTo(S15_16ToFloat(x0), S15_16ToFloat(y0), c0);
439
+ }
440
+
441
+ @Override
442
+ public void lineJoin() {
443
+ }
444
+
445
+ @Override
446
+ public void lineTo(int x1, int y1, int c1) {
447
+ dest.lineTo(S15_16ToFloat(x1), S15_16ToFloat(y1), c1);
448
+ }
449
+
450
+ @Override
451
+ public void close() {
452
+ dest.closePath();
453
+ }
454
+
455
+ @Override
456
+ public void end() {
457
+ }
458
+ });
459
+
460
+ return dest;
461
+ }
462
+
463
+
464
+ private static void strokeTo(LinePath src, float width, int caps, int join,
465
+ float miterlimit, PMatrix2D transform,
466
+ LineStroker lsink) {
467
+ lsink = new LineStroker(lsink, FloatToS15_16(width), caps, join,
468
+ FloatToS15_16(miterlimit),
469
+ transform == null ? identity : transform);
470
+
471
+ PathIterator pi = src.getPathIterator();
472
+ pathTo(pi, lsink);
473
+ }
474
+
475
+
476
+ private static void pathTo(PathIterator pi, LineStroker lsink) {
477
+ float[] coords = new float[6];
478
+ while (!pi.isDone()) {
479
+ int color;
480
+ switch (pi.currentSegment(coords)) {
481
+ case SEG_MOVETO:
482
+ color = ((int)coords[2]<<24) |
483
+ ((int)coords[3]<<16) |
484
+ ((int)coords[4]<< 8) |
485
+ (int)coords[5];
486
+ lsink.moveTo(FloatToS15_16(coords[0]), FloatToS15_16(coords[1]), color);
487
+ break;
488
+ case SEG_LINETO:
489
+ color = ((int)coords[2]<<24) |
490
+ ((int)coords[3]<<16) |
491
+ ((int)coords[4]<< 8) |
492
+ (int)coords[5];
493
+ lsink.lineJoin();
494
+ lsink.lineTo(FloatToS15_16(coords[0]), FloatToS15_16(coords[1]), color);
495
+ break;
496
+ case SEG_CLOSE:
497
+ lsink.lineJoin();
498
+ lsink.close();
499
+ break;
500
+ default:
501
+ throw new InternalError("unknown flattened segment type");
502
+ }
503
+ pi.next();
504
+ }
505
+ lsink.end();
506
+ }
507
+
508
+
509
+ /////////////////////////////////////////////////////////////////////////////
510
+ //
511
+ // Utility methods
512
+
513
+
514
+ public static float[] copyOf(float[] source, int length) {
515
+ float[] target = new float[length];
516
+ for (int i = 0; i < target.length; i++) {
517
+ if (i > source.length - 1)
518
+ target[i] = 0f;
519
+ else
520
+ target[i] = source[i];
521
+ }
522
+ return target;
523
+ }
524
+
525
+
526
+ public static byte[] copyOf(byte[] source, int length) {
527
+ byte[] target = new byte[length];
528
+ for (int i = 0; i < target.length; i++) {
529
+ if (i > source.length - 1)
530
+ target[i] = 0;
531
+ else
532
+ target[i] = source[i];
533
+ }
534
+ return target;
535
+ }
536
+
537
+
538
+ public static int[] copyOf(int[] source, int length) {
539
+ int[] target = new int[length];
540
+ for (int i = 0; i < target.length; i++) {
541
+ if (i > source.length - 1)
542
+ target[i] = 0;
543
+ else
544
+ target[i] = source[i];
545
+ }
546
+ return target;
547
+ }
548
+
549
+
550
+ // From Ken Turkowski, _Fixed-Point Square Root_, In Graphics Gems V
551
+ public static int isqrt(int x) {
552
+ int fracbits = 16;
553
+
554
+ int root = 0;
555
+ int remHi = 0;
556
+ int remLo = x;
557
+ int count = 15 + fracbits / 2;
558
+
559
+ do {
560
+ remHi = (remHi << 2) | (remLo >>> 30); // N.B. - unsigned shift R
561
+ remLo <<= 2;
562
+ root <<= 1;
563
+ int testdiv = (root << 1) + 1;
564
+ if (remHi >= testdiv) {
565
+ remHi -= testdiv;
566
+ root++;
567
+ }
568
+ } while (count-- != 0);
569
+
570
+ return root;
571
+ }
572
+
573
+
574
+ public static long lsqrt(long x) {
575
+ int fracbits = 16;
576
+
577
+ long root = 0;
578
+ long remHi = 0;
579
+ long remLo = x;
580
+ int count = 31 + fracbits / 2;
581
+
582
+ do {
583
+ remHi = (remHi << 2) | (remLo >>> 62); // N.B. - unsigned shift R
584
+ remLo <<= 2;
585
+ root <<= 1;
586
+ long testDiv = (root << 1) + 1;
587
+ if (remHi >= testDiv) {
588
+ remHi -= testDiv;
589
+ root++;
590
+ }
591
+ } while (count-- != 0);
592
+
593
+ return root;
594
+ }
595
+
596
+
597
+ public static double hypot(double x, double y) {
598
+ return Math.sqrt(x * x + y * y);
599
+ }
600
+
601
+
602
+ public static int hypot(int x, int y) {
603
+ return (int) ((lsqrt((long) x * x + (long) y * y) + 128) >> 8);
604
+ }
605
+
606
+
607
+ public static long hypot(long x, long y) {
608
+ return (lsqrt(x * x + y * y) + 128) >> 8;
609
+ }
610
+
611
+
612
+ static int FloatToS15_16(float flt) {
613
+ flt = flt * 65536f + 0.5f;
614
+ if (flt <= -(65536f * 65536f)) {
615
+ return Integer.MIN_VALUE;
616
+ } else if (flt >= (65536f * 65536f)) {
617
+ return Integer.MAX_VALUE;
618
+ } else {
619
+ return (int) Math.floor(flt);
620
+ }
621
+ }
622
+
623
+
624
+ static float S15_16ToFloat(int fix) {
625
+ return (fix / 65536f);
626
+ }
627
+ }