picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- 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/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,623 @@
|
|
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
|
+
* @see LinePath#moveTo
|
223
|
+
*/
|
224
|
+
public final void moveTo(float x, float y, int c) {
|
225
|
+
if (numTypes > 0 && pointTypes[numTypes - 1] == SEG_MOVETO) {
|
226
|
+
floatCoords[numCoords - 2] = x;
|
227
|
+
floatCoords[numCoords - 1] = y;
|
228
|
+
pointColors[numCoords/2-1] = c;
|
229
|
+
} else {
|
230
|
+
needRoom(false, 1);
|
231
|
+
pointTypes[numTypes++] = SEG_MOVETO;
|
232
|
+
floatCoords[numCoords++] = x;
|
233
|
+
floatCoords[numCoords++] = y;
|
234
|
+
pointColors[numCoords/2-1] = c;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Adds a point to the path by drawing a straight line from the current
|
241
|
+
* coordinates to the new specified coordinates specified in float precision.
|
242
|
+
* <p>
|
243
|
+
* This method provides a single precision variant of the double precision
|
244
|
+
* {@code lineTo()} method on the base {@code LinePath} class.
|
245
|
+
*
|
246
|
+
* @param x
|
247
|
+
* the specified X coordinate
|
248
|
+
* @param y
|
249
|
+
* the specified Y coordinate
|
250
|
+
* @see LinePath#lineTo
|
251
|
+
*/
|
252
|
+
public final void lineTo(float x, float y, int c) {
|
253
|
+
needRoom(true, 1);
|
254
|
+
pointTypes[numTypes++] = SEG_LINETO;
|
255
|
+
floatCoords[numCoords++] = x;
|
256
|
+
floatCoords[numCoords++] = y;
|
257
|
+
pointColors[numCoords/2-1] = c;
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
/**
|
262
|
+
* The iterator for this class is not multi-threaded safe, which means that
|
263
|
+
* the {@code LinePath} class does not guarantee that modifications to the
|
264
|
+
* geometry of this {@code LinePath} object do not affect any iterations of that
|
265
|
+
* geometry that are already in process.
|
266
|
+
*/
|
267
|
+
public PathIterator getPathIterator() {
|
268
|
+
return new PathIterator(this);
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
/**
|
273
|
+
* Closes the current subpath by drawing a straight line back to the
|
274
|
+
* coordinates of the last {@code moveTo}. If the path is already closed then
|
275
|
+
* this method has no effect.
|
276
|
+
*/
|
277
|
+
public final void closePath() {
|
278
|
+
if (numTypes == 0 || pointTypes[numTypes - 1] != SEG_CLOSE) {
|
279
|
+
needRoom(false, 0);
|
280
|
+
pointTypes[numTypes++] = SEG_CLOSE;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Returns the fill style winding rule.
|
287
|
+
*
|
288
|
+
* @return an integer representing the current winding rule.
|
289
|
+
* @see #WIND_EVEN_ODD
|
290
|
+
* @see #WIND_NON_ZERO
|
291
|
+
* @see #setWindingRule
|
292
|
+
*/
|
293
|
+
public final int getWindingRule() {
|
294
|
+
return windingRule;
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Sets the winding rule for this path to the specified value.
|
300
|
+
*
|
301
|
+
* @param rule
|
302
|
+
* an integer representing the specified winding rule
|
303
|
+
* @exception IllegalArgumentException
|
304
|
+
* if {@code rule} is not either {@link #WIND_EVEN_ODD} or
|
305
|
+
* {@link #WIND_NON_ZERO}
|
306
|
+
* @see #getWindingRule
|
307
|
+
*/
|
308
|
+
public final void setWindingRule(int rule) {
|
309
|
+
if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) {
|
310
|
+
throw new IllegalArgumentException("winding rule must be "
|
311
|
+
+ "WIND_EVEN_ODD or " + "WIND_NON_ZERO");
|
312
|
+
}
|
313
|
+
windingRule = rule;
|
314
|
+
}
|
315
|
+
|
316
|
+
|
317
|
+
/**
|
318
|
+
* Resets the path to empty. The append position is set back to the beginning
|
319
|
+
* of the path and all coordinates and point types are forgotten.
|
320
|
+
*/
|
321
|
+
public final void reset() {
|
322
|
+
numTypes = numCoords = 0;
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
static public class PathIterator {
|
327
|
+
float floatCoords[];
|
328
|
+
|
329
|
+
int typeIdx;
|
330
|
+
|
331
|
+
int pointIdx;
|
332
|
+
|
333
|
+
int colorIdx;
|
334
|
+
|
335
|
+
LinePath path;
|
336
|
+
|
337
|
+
static final int curvecoords[] = { 2, 2, 0 };
|
338
|
+
|
339
|
+
PathIterator(LinePath p2df) {
|
340
|
+
this.path = p2df;
|
341
|
+
this.floatCoords = p2df.floatCoords;
|
342
|
+
pointIdx = 0;
|
343
|
+
colorIdx = 0;
|
344
|
+
}
|
345
|
+
|
346
|
+
public int currentSegment(float[] coords) {
|
347
|
+
int type = path.pointTypes[typeIdx];
|
348
|
+
int numCoords = curvecoords[type];
|
349
|
+
if (numCoords > 0) {
|
350
|
+
System.arraycopy(floatCoords, pointIdx, coords, 0, numCoords);
|
351
|
+
int color = path.pointColors[colorIdx];
|
352
|
+
coords[numCoords + 0] = (color >> 24) & 0xFF;
|
353
|
+
coords[numCoords + 1] = (color >> 16) & 0xFF;
|
354
|
+
coords[numCoords + 2] = (color >> 8) & 0xFF;
|
355
|
+
coords[numCoords + 3] = (color >> 0) & 0xFF;
|
356
|
+
}
|
357
|
+
return type;
|
358
|
+
}
|
359
|
+
|
360
|
+
public int currentSegment(double[] coords) {
|
361
|
+
int type = path.pointTypes[typeIdx];
|
362
|
+
int numCoords = curvecoords[type];
|
363
|
+
if (numCoords > 0) {
|
364
|
+
for (int i = 0; i < numCoords; i++) {
|
365
|
+
coords[i] = floatCoords[pointIdx + i];
|
366
|
+
}
|
367
|
+
int color = path.pointColors[colorIdx];
|
368
|
+
coords[numCoords + 0] = (color >> 24) & 0xFF;
|
369
|
+
coords[numCoords + 1] = (color >> 16) & 0xFF;
|
370
|
+
coords[numCoords + 2] = (color >> 8) & 0xFF;
|
371
|
+
coords[numCoords + 3] = (color >> 0) & 0xFF;
|
372
|
+
}
|
373
|
+
return type;
|
374
|
+
}
|
375
|
+
|
376
|
+
public int getWindingRule() {
|
377
|
+
return path.getWindingRule();
|
378
|
+
}
|
379
|
+
|
380
|
+
public boolean isDone() {
|
381
|
+
return (typeIdx >= path.numTypes);
|
382
|
+
}
|
383
|
+
|
384
|
+
public void next() {
|
385
|
+
int type = path.pointTypes[typeIdx++];
|
386
|
+
if (0 < curvecoords[type]) {
|
387
|
+
pointIdx += curvecoords[type];
|
388
|
+
colorIdx++;
|
389
|
+
}
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
/////////////////////////////////////////////////////////////////////////////
|
395
|
+
//
|
396
|
+
// Stroked path methods
|
397
|
+
|
398
|
+
|
399
|
+
static public LinePath createStrokedPath(LinePath src, float weight,
|
400
|
+
int caps, int join) {
|
401
|
+
return createStrokedPath(src, weight, caps, join, defaultMiterlimit, null);
|
402
|
+
}
|
403
|
+
|
404
|
+
|
405
|
+
static public LinePath createStrokedPath(LinePath src, float weight,
|
406
|
+
int caps, int join, float miterlimit) {
|
407
|
+
return createStrokedPath(src, weight, caps, join, miterlimit, null);
|
408
|
+
}
|
409
|
+
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Constructs a solid <code>LinePath</code> with the specified attributes.
|
413
|
+
*
|
414
|
+
* @param src
|
415
|
+
* the original path to be stroked
|
416
|
+
* @param weight
|
417
|
+
* the weight of the stroked path
|
418
|
+
* @param caps
|
419
|
+
* the decoration of the ends of the segments in the path
|
420
|
+
* @param join
|
421
|
+
* the decoration applied where path segments meet
|
422
|
+
* @param miterlimit
|
423
|
+
* @param transform
|
424
|
+
*
|
425
|
+
*/
|
426
|
+
static public LinePath createStrokedPath(LinePath src, float weight,
|
427
|
+
int caps, int join,
|
428
|
+
float miterlimit, PMatrix2D transform) {
|
429
|
+
final LinePath dest = new LinePath();
|
430
|
+
|
431
|
+
strokeTo(src, weight, caps, join, miterlimit, transform, new LineStroker() {
|
432
|
+
@Override
|
433
|
+
public void moveTo(int x0, int y0, int c0) {
|
434
|
+
dest.moveTo(S15_16ToFloat(x0), S15_16ToFloat(y0), c0);
|
435
|
+
}
|
436
|
+
|
437
|
+
@Override
|
438
|
+
public void lineJoin() {
|
439
|
+
}
|
440
|
+
|
441
|
+
@Override
|
442
|
+
public void lineTo(int x1, int y1, int c1) {
|
443
|
+
dest.lineTo(S15_16ToFloat(x1), S15_16ToFloat(y1), c1);
|
444
|
+
}
|
445
|
+
|
446
|
+
@Override
|
447
|
+
public void close() {
|
448
|
+
dest.closePath();
|
449
|
+
}
|
450
|
+
|
451
|
+
@Override
|
452
|
+
public void end() {
|
453
|
+
}
|
454
|
+
});
|
455
|
+
|
456
|
+
return dest;
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
private static void strokeTo(LinePath src, float width, int caps, int join,
|
461
|
+
float miterlimit, PMatrix2D transform,
|
462
|
+
LineStroker lsink) {
|
463
|
+
lsink = new LineStroker(lsink, FloatToS15_16(width), caps, join,
|
464
|
+
FloatToS15_16(miterlimit),
|
465
|
+
transform == null ? identity : transform);
|
466
|
+
|
467
|
+
PathIterator pi = src.getPathIterator();
|
468
|
+
pathTo(pi, lsink);
|
469
|
+
}
|
470
|
+
|
471
|
+
|
472
|
+
private static void pathTo(PathIterator pi, LineStroker lsink) {
|
473
|
+
float coords[] = new float[6];
|
474
|
+
while (!pi.isDone()) {
|
475
|
+
int color;
|
476
|
+
switch (pi.currentSegment(coords)) {
|
477
|
+
case SEG_MOVETO:
|
478
|
+
color = ((int)coords[2]<<24) |
|
479
|
+
((int)coords[3]<<16) |
|
480
|
+
((int)coords[4]<< 8) |
|
481
|
+
(int)coords[5];
|
482
|
+
lsink.moveTo(FloatToS15_16(coords[0]), FloatToS15_16(coords[1]), color);
|
483
|
+
break;
|
484
|
+
case SEG_LINETO:
|
485
|
+
color = ((int)coords[2]<<24) |
|
486
|
+
((int)coords[3]<<16) |
|
487
|
+
((int)coords[4]<< 8) |
|
488
|
+
(int)coords[5];
|
489
|
+
lsink.lineJoin();
|
490
|
+
lsink.lineTo(FloatToS15_16(coords[0]), FloatToS15_16(coords[1]), color);
|
491
|
+
break;
|
492
|
+
case SEG_CLOSE:
|
493
|
+
lsink.lineJoin();
|
494
|
+
lsink.close();
|
495
|
+
break;
|
496
|
+
default:
|
497
|
+
throw new InternalError("unknown flattened segment type");
|
498
|
+
}
|
499
|
+
pi.next();
|
500
|
+
}
|
501
|
+
lsink.end();
|
502
|
+
}
|
503
|
+
|
504
|
+
|
505
|
+
/////////////////////////////////////////////////////////////////////////////
|
506
|
+
//
|
507
|
+
// Utility methods
|
508
|
+
|
509
|
+
|
510
|
+
public static float[] copyOf(float[] source, int length) {
|
511
|
+
float[] target = new float[length];
|
512
|
+
for (int i = 0; i < target.length; i++) {
|
513
|
+
if (i > source.length - 1)
|
514
|
+
target[i] = 0f;
|
515
|
+
else
|
516
|
+
target[i] = source[i];
|
517
|
+
}
|
518
|
+
return target;
|
519
|
+
}
|
520
|
+
|
521
|
+
|
522
|
+
public static byte[] copyOf(byte[] source, int length) {
|
523
|
+
byte[] target = new byte[length];
|
524
|
+
for (int i = 0; i < target.length; i++) {
|
525
|
+
if (i > source.length - 1)
|
526
|
+
target[i] = 0;
|
527
|
+
else
|
528
|
+
target[i] = source[i];
|
529
|
+
}
|
530
|
+
return target;
|
531
|
+
}
|
532
|
+
|
533
|
+
|
534
|
+
public static int[] copyOf(int[] source, int length) {
|
535
|
+
int[] target = new int[length];
|
536
|
+
for (int i = 0; i < target.length; i++) {
|
537
|
+
if (i > source.length - 1)
|
538
|
+
target[i] = 0;
|
539
|
+
else
|
540
|
+
target[i] = source[i];
|
541
|
+
}
|
542
|
+
return target;
|
543
|
+
}
|
544
|
+
|
545
|
+
|
546
|
+
// From Ken Turkowski, _Fixed-Point Square Root_, In Graphics Gems V
|
547
|
+
public static int isqrt(int x) {
|
548
|
+
int fracbits = 16;
|
549
|
+
|
550
|
+
int root = 0;
|
551
|
+
int remHi = 0;
|
552
|
+
int remLo = x;
|
553
|
+
int count = 15 + fracbits / 2;
|
554
|
+
|
555
|
+
do {
|
556
|
+
remHi = (remHi << 2) | (remLo >>> 30); // N.B. - unsigned shift R
|
557
|
+
remLo <<= 2;
|
558
|
+
root <<= 1;
|
559
|
+
int testdiv = (root << 1) + 1;
|
560
|
+
if (remHi >= testdiv) {
|
561
|
+
remHi -= testdiv;
|
562
|
+
root++;
|
563
|
+
}
|
564
|
+
} while (count-- != 0);
|
565
|
+
|
566
|
+
return root;
|
567
|
+
}
|
568
|
+
|
569
|
+
|
570
|
+
public static long lsqrt(long x) {
|
571
|
+
int fracbits = 16;
|
572
|
+
|
573
|
+
long root = 0;
|
574
|
+
long remHi = 0;
|
575
|
+
long remLo = x;
|
576
|
+
int count = 31 + fracbits / 2;
|
577
|
+
|
578
|
+
do {
|
579
|
+
remHi = (remHi << 2) | (remLo >>> 62); // N.B. - unsigned shift R
|
580
|
+
remLo <<= 2;
|
581
|
+
root <<= 1;
|
582
|
+
long testDiv = (root << 1) + 1;
|
583
|
+
if (remHi >= testDiv) {
|
584
|
+
remHi -= testDiv;
|
585
|
+
root++;
|
586
|
+
}
|
587
|
+
} while (count-- != 0);
|
588
|
+
|
589
|
+
return root;
|
590
|
+
}
|
591
|
+
|
592
|
+
|
593
|
+
public static double hypot(double x, double y) {
|
594
|
+
return Math.sqrt(x * x + y * y);
|
595
|
+
}
|
596
|
+
|
597
|
+
|
598
|
+
public static int hypot(int x, int y) {
|
599
|
+
return (int) ((lsqrt((long) x * x + (long) y * y) + 128) >> 8);
|
600
|
+
}
|
601
|
+
|
602
|
+
|
603
|
+
public static long hypot(long x, long y) {
|
604
|
+
return (lsqrt(x * x + y * y) + 128) >> 8;
|
605
|
+
}
|
606
|
+
|
607
|
+
|
608
|
+
static int FloatToS15_16(float flt) {
|
609
|
+
flt = flt * 65536f + 0.5f;
|
610
|
+
if (flt <= -(65536f * 65536f)) {
|
611
|
+
return Integer.MIN_VALUE;
|
612
|
+
} else if (flt >= (65536f * 65536f)) {
|
613
|
+
return Integer.MAX_VALUE;
|
614
|
+
} else {
|
615
|
+
return (int) Math.floor(flt);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
|
619
|
+
|
620
|
+
static float S15_16ToFloat(int fix) {
|
621
|
+
return (fix / 65536f);
|
622
|
+
}
|
623
|
+
}
|