geomerative 0.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/LICENSE +662 -0
- data/LICENSE.md +9 -0
- data/README.md +2 -0
- data/Rakefile +37 -0
- data/examples/README.md +7 -0
- data/examples/data/FreeSans.ttf +0 -0
- data/examples/data/ReplicaBold.ttf +0 -0
- data/examples/data/bot1.svg +160 -0
- data/examples/hello_svg_to_pdf.rb +26 -0
- data/examples/hello_world.rb +23 -0
- data/examples/physics_type.rb +77 -0
- data/examples/rotate_first_letter.rb +28 -0
- data/geomerative.gemspec +32 -0
- data/lib/geomerative.rb +12 -0
- data/lib/geomerative/version.rb +3 -0
- data/pom.xml +110 -0
- data/src/geomerative/FastRClip.java +2715 -0
- data/src/geomerative/RClip.java +2892 -0
- data/src/geomerative/RClosest.java +64 -0
- data/src/geomerative/RCommand.java +1941 -0
- data/src/geomerative/RContour.java +348 -0
- data/src/geomerative/RFont.java +583 -0
- data/src/geomerative/RG.java +753 -0
- data/src/geomerative/RGeomElem.java +1075 -0
- data/src/geomerative/RGroup.java +888 -0
- data/src/geomerative/RMatrix.java +401 -0
- data/src/geomerative/RMesh.java +420 -0
- data/src/geomerative/RPath.java +1095 -0
- data/src/geomerative/RPoint.java +419 -0
- data/src/geomerative/RPolygon.java +1110 -0
- data/src/geomerative/RRectangle.java +91 -0
- data/src/geomerative/RSVG.java +976 -0
- data/src/geomerative/RShape.java +2045 -0
- data/src/geomerative/RStrip.java +221 -0
- data/src/geomerative/RStyle.java +469 -0
- data/src/org/apache/batik/svggen/font/.SVGFont.java.swp +0 -0
- data/src/org/apache/batik/svggen/font/Font.java +188 -0
- data/src/org/apache/batik/svggen/font/Glyph.java +113 -0
- data/src/org/apache/batik/svggen/font/Messages.java.bak +72 -0
- data/src/org/apache/batik/svggen/font/Point.java +38 -0
- data/src/org/apache/batik/svggen/font/RandomAccessFileEmulator.java +15 -0
- data/src/org/apache/batik/svggen/font/table/ClassDef.java +42 -0
- data/src/org/apache/batik/svggen/font/table/ClassDefFormat1.java +55 -0
- data/src/org/apache/batik/svggen/font/table/ClassDefFormat2.java +49 -0
- data/src/org/apache/batik/svggen/font/table/CmapFormat.java +81 -0
- data/src/org/apache/batik/svggen/font/table/CmapFormat0.java +60 -0
- data/src/org/apache/batik/svggen/font/table/CmapFormat2.java +48 -0
- data/src/org/apache/batik/svggen/font/table/CmapFormat4.java +147 -0
- data/src/org/apache/batik/svggen/font/table/CmapFormat6.java +60 -0
- data/src/org/apache/batik/svggen/font/table/CmapIndexEntry.java +84 -0
- data/src/org/apache/batik/svggen/font/table/CmapTable.java +87 -0
- data/src/org/apache/batik/svggen/font/table/Coverage.java +50 -0
- data/src/org/apache/batik/svggen/font/table/CoverageFormat1.java +59 -0
- data/src/org/apache/batik/svggen/font/table/CoverageFormat2.java +56 -0
- data/src/org/apache/batik/svggen/font/table/CvtTable.java +48 -0
- data/src/org/apache/batik/svggen/font/table/Device.java +63 -0
- data/src/org/apache/batik/svggen/font/table/DirectoryEntry.java +73 -0
- data/src/org/apache/batik/svggen/font/table/Feature.java +56 -0
- data/src/org/apache/batik/svggen/font/table/FeatureList.java +70 -0
- data/src/org/apache/batik/svggen/font/table/FeatureRecord.java +52 -0
- data/src/org/apache/batik/svggen/font/table/FeatureTags.java +30 -0
- data/src/org/apache/batik/svggen/font/table/FpgmTable.java +38 -0
- data/src/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +165 -0
- data/src/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +160 -0
- data/src/org/apache/batik/svggen/font/table/GlyfDescript.java +79 -0
- data/src/org/apache/batik/svggen/font/table/GlyfSimpleDescript.java +155 -0
- data/src/org/apache/batik/svggen/font/table/GlyfTable.java +111 -0
- data/src/org/apache/batik/svggen/font/table/GlyphDescription.java +39 -0
- data/src/org/apache/batik/svggen/font/table/GposTable.java +80 -0
- data/src/org/apache/batik/svggen/font/table/GsubTable.java +118 -0
- data/src/org/apache/batik/svggen/font/table/HeadTable.java +159 -0
- data/src/org/apache/batik/svggen/font/table/HheaTable.java +109 -0
- data/src/org/apache/batik/svggen/font/table/HmtxTable.java +99 -0
- data/src/org/apache/batik/svggen/font/table/KernSubtable.java +58 -0
- data/src/org/apache/batik/svggen/font/table/KernSubtableFormat0.java +65 -0
- data/src/org/apache/batik/svggen/font/table/KernSubtableFormat2.java +56 -0
- data/src/org/apache/batik/svggen/font/table/KernTable.java +64 -0
- data/src/org/apache/batik/svggen/font/table/KerningPair.java +53 -0
- data/src/org/apache/batik/svggen/font/table/LangSys.java +58 -0
- data/src/org/apache/batik/svggen/font/table/LangSysRecord.java +52 -0
- data/src/org/apache/batik/svggen/font/table/Ligature.java +57 -0
- data/src/org/apache/batik/svggen/font/table/LigatureSet.java +55 -0
- data/src/org/apache/batik/svggen/font/table/LigatureSubst.java +40 -0
- data/src/org/apache/batik/svggen/font/table/LigatureSubstFormat1.java +63 -0
- data/src/org/apache/batik/svggen/font/table/LocaTable.java +72 -0
- data/src/org/apache/batik/svggen/font/table/Lookup.java +77 -0
- data/src/org/apache/batik/svggen/font/table/LookupList.java +68 -0
- data/src/org/apache/batik/svggen/font/table/LookupSubtable.java +27 -0
- data/src/org/apache/batik/svggen/font/table/LookupSubtableFactory.java +31 -0
- data/src/org/apache/batik/svggen/font/table/MaxpTable.java +124 -0
- data/src/org/apache/batik/svggen/font/table/NameRecord.java +98 -0
- data/src/org/apache/batik/svggen/font/table/NameTable.java +67 -0
- data/src/org/apache/batik/svggen/font/table/Os2Table.java +232 -0
- data/src/org/apache/batik/svggen/font/table/Panose.java +108 -0
- data/src/org/apache/batik/svggen/font/table/PostTable.java +379 -0
- data/src/org/apache/batik/svggen/font/table/PrepTable.java +38 -0
- data/src/org/apache/batik/svggen/font/table/Program.java +49 -0
- data/src/org/apache/batik/svggen/font/table/RangeRecord.java +57 -0
- data/src/org/apache/batik/svggen/font/table/Script.java +72 -0
- data/src/org/apache/batik/svggen/font/table/ScriptList.java +78 -0
- data/src/org/apache/batik/svggen/font/table/ScriptRecord.java +52 -0
- data/src/org/apache/batik/svggen/font/table/ScriptTags.java +28 -0
- data/src/org/apache/batik/svggen/font/table/SingleSubst.java +47 -0
- data/src/org/apache/batik/svggen/font/table/SingleSubstFormat1.java +67 -0
- data/src/org/apache/batik/svggen/font/table/SingleSubstFormat2.java +67 -0
- data/src/org/apache/batik/svggen/font/table/Table.java +204 -0
- data/src/org/apache/batik/svggen/font/table/TableDirectory.java +94 -0
- data/src/org/apache/batik/svggen/font/table/TableFactory.java +121 -0
- metadata +206 -0
@@ -0,0 +1,753 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
|
3
|
+
*
|
4
|
+
* This file is part of Geomerative.
|
5
|
+
*
|
6
|
+
* Geomerative is free software: you can redistribute it and/or modify it under
|
7
|
+
* the terms of the GNU General Public License as published by the Free Software
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later
|
9
|
+
* version.
|
10
|
+
*
|
11
|
+
* Geomerative is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14
|
+
* details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public License along with
|
17
|
+
* Geomerative. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
package geomerative;
|
20
|
+
|
21
|
+
import processing.core.*;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* RG is a static class containing all the states, modes, etc.. Geomerative is
|
25
|
+
* mostly used by calling RG methods. e.g. RShape s = RG.getEllipse(30, 40, 80,
|
26
|
+
* 80)
|
27
|
+
*/
|
28
|
+
public class RG implements PConstants {
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @invisible
|
32
|
+
*/
|
33
|
+
private static boolean initialized = false;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @invisible
|
37
|
+
*/
|
38
|
+
private static PApplet parent;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @invisible
|
42
|
+
*/
|
43
|
+
public static boolean ignoreStyles = false;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @invisible
|
47
|
+
*/
|
48
|
+
public static boolean useFastClip = true;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* The adaptor adapts the shape to a particular shape by adapting each of
|
52
|
+
* the groups points. This can cause deformations of the individual elements
|
53
|
+
* in the group.
|
54
|
+
*/
|
55
|
+
public final static int BYPOINT = 0;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* The adaptor adapts the shape to a particular shape by adapting each of
|
59
|
+
* the groups elements positions. This mantains the proportions of the
|
60
|
+
* shapes.
|
61
|
+
*/
|
62
|
+
public final static int BYELEMENTPOSITION = 1;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* The adaptor adapts the shape to a particular shape by adapting each of
|
66
|
+
* the groups elements indices. This mantains the proportions of the shapes.
|
67
|
+
*/
|
68
|
+
public final static int BYELEMENTINDEX = 2;
|
69
|
+
|
70
|
+
/**
|
71
|
+
* @invisible
|
72
|
+
*/
|
73
|
+
static int adaptorType = BYELEMENTPOSITION;
|
74
|
+
|
75
|
+
/**
|
76
|
+
* @invisible
|
77
|
+
*/
|
78
|
+
static float adaptorScale = 1F;
|
79
|
+
|
80
|
+
/**
|
81
|
+
* @invisible
|
82
|
+
*/
|
83
|
+
static float adaptorLengthOffset = 0F;
|
84
|
+
|
85
|
+
/**
|
86
|
+
* ADAPTATIVE segmentator minimizes the number of segments avoiding
|
87
|
+
* perceptual artifacts like angles or cusps. Use this in order to have
|
88
|
+
* polygons and meshes with the fewest possible vertices.
|
89
|
+
*/
|
90
|
+
public static int ADAPTATIVE = RCommand.ADAPTATIVE;
|
91
|
+
|
92
|
+
/**
|
93
|
+
* UNIFORMLENGTH segmentator is the slowest segmentator and it segments the
|
94
|
+
* curve on segments of equal length. This can be useful for very specific
|
95
|
+
* applications when for example drawing incrementaly a shape with a uniform
|
96
|
+
* speed.
|
97
|
+
*/
|
98
|
+
public static int UNIFORMLENGTH = RCommand.UNIFORMLENGTH;
|
99
|
+
|
100
|
+
/**
|
101
|
+
* UNIFORMSTEP segmentator is the fastest segmentator and it segments the
|
102
|
+
* curve based on a constant value of the step of the curve parameter, or on
|
103
|
+
* the number of segments wanted. This can be useful when segmpointsentating
|
104
|
+
* very often a Shape or when we know the amount of segments necessary for
|
105
|
+
* our specific application.
|
106
|
+
*/
|
107
|
+
public static int UNIFORMSTEP = RCommand.UNIFORMSTEP;
|
108
|
+
|
109
|
+
static int dpi = 72;
|
110
|
+
|
111
|
+
/**
|
112
|
+
* @invisible
|
113
|
+
*/
|
114
|
+
public static class LibraryNotInitializedException extends NullPointerException {
|
115
|
+
|
116
|
+
private static final long serialVersionUID = -3710605630786298671L;
|
117
|
+
|
118
|
+
LibraryNotInitializedException() {
|
119
|
+
super("Must call RG.init(this); before using this library.");
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* @invisible
|
125
|
+
*/
|
126
|
+
public static class FontNotLoadedException extends NullPointerException {
|
127
|
+
|
128
|
+
private static final long serialVersionUID = -3710605630786298672L;
|
129
|
+
|
130
|
+
FontNotLoadedException() {
|
131
|
+
super("Use RG.loadFont(filename) and RG.textFont(font, size) to load and set fonts first.");
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* @invisible
|
137
|
+
*/
|
138
|
+
public static class NoPathInitializedException extends NullPointerException {
|
139
|
+
|
140
|
+
private static final long serialVersionUID = -3710605630786298673L;
|
141
|
+
|
142
|
+
NoPathInitializedException() {
|
143
|
+
super("Must initialize a path by calling RG.beginShape() first.");
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
static RShape shape;
|
148
|
+
|
149
|
+
static RFont fntLoader = null;
|
150
|
+
|
151
|
+
// Font methods
|
152
|
+
/**
|
153
|
+
* Load and get the font object that can be used in the textFont method.
|
154
|
+
*
|
155
|
+
* @eexample loadFont
|
156
|
+
* @param fontFile the filename of the font to be loaded
|
157
|
+
* @return RFont, the font object
|
158
|
+
*/
|
159
|
+
public static RFont loadFont(String fontFile) {
|
160
|
+
RFont newFntLoader = new RFont(fontFile);
|
161
|
+
if (fntLoader == null) {
|
162
|
+
fntLoader = newFntLoader;
|
163
|
+
}
|
164
|
+
return newFntLoader;
|
165
|
+
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Draw text to the screen using the font set using the textFont method.
|
170
|
+
*
|
171
|
+
* @eexample text
|
172
|
+
* @param text the string to be drawn on the screen
|
173
|
+
*/
|
174
|
+
public static void text(String text) {
|
175
|
+
RShape grp = getText(text);
|
176
|
+
grp.draw();
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Set the font object to be used in all text calls.
|
181
|
+
*
|
182
|
+
* @eexample textFont
|
183
|
+
* @param font the font object to be set
|
184
|
+
* @param size the size of the font
|
185
|
+
*/
|
186
|
+
public static void textFont(RFont font, int size) {
|
187
|
+
font.setSize(size);
|
188
|
+
fntLoader = font;
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Get the shape corresponding to a text. Use the textFont method to select
|
193
|
+
* the font and size.
|
194
|
+
*
|
195
|
+
* @eexample getText
|
196
|
+
* @param font the filename of the font to be loaded
|
197
|
+
* @param text the string to be created
|
198
|
+
* @param size the size of the font to be used
|
199
|
+
* @param align the alignment. Use RG.CENTER, RG.LEFT or RG.RIGHT
|
200
|
+
* @return RShape, the shape created
|
201
|
+
*/
|
202
|
+
public static RShape getText(String text, String font, int size, int align) {
|
203
|
+
RFont tempFntLoader = new RFont(font, size, align);
|
204
|
+
return tempFntLoader.toShape(text);
|
205
|
+
}
|
206
|
+
|
207
|
+
public static RShape getText(String text) {
|
208
|
+
if (fntLoader == null) {
|
209
|
+
throw new FontNotLoadedException();
|
210
|
+
}
|
211
|
+
|
212
|
+
return fntLoader.toShape(text);
|
213
|
+
}
|
214
|
+
|
215
|
+
// Shape methods
|
216
|
+
/**
|
217
|
+
* Draw a shape to a given position on the screen.
|
218
|
+
*
|
219
|
+
* @eexample shape
|
220
|
+
* @param shp the shape to be drawn
|
221
|
+
* @param x the horizontal coordinate
|
222
|
+
* @param y the vertical coordinate
|
223
|
+
* @param w the width with which we draw the shape
|
224
|
+
* @param h the height with which we draw the shape
|
225
|
+
*/
|
226
|
+
public static void shape(RShape shp, float x, float y, float w, float h) {
|
227
|
+
RShape tshp = new RShape(shp);
|
228
|
+
|
229
|
+
RMatrix transf = new RMatrix();
|
230
|
+
transf.translate(x, y);
|
231
|
+
transf.scale(w / tshp.getOrigWidth(), h / tshp.getOrigHeight());
|
232
|
+
tshp.transform(transf);
|
233
|
+
|
234
|
+
tshp.draw();
|
235
|
+
}
|
236
|
+
|
237
|
+
public static void shape(RShape shp, float x, float y) {
|
238
|
+
RShape tshp = new RShape(shp);
|
239
|
+
|
240
|
+
RMatrix transf = new RMatrix();
|
241
|
+
transf.translate(x, y);
|
242
|
+
tshp.transform(transf);
|
243
|
+
|
244
|
+
tshp.draw();
|
245
|
+
}
|
246
|
+
|
247
|
+
public static void shape(RShape shp) {
|
248
|
+
shp.draw();
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Create a shape from an array of point arrays.
|
253
|
+
*
|
254
|
+
* @param points
|
255
|
+
* @return
|
256
|
+
* @eexample createShape
|
257
|
+
*/
|
258
|
+
public static RShape createShape(RPoint[][] points) {
|
259
|
+
return new RShape(points);
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Load a shape object from a file.
|
264
|
+
*
|
265
|
+
* @return
|
266
|
+
* @eexample loadShape
|
267
|
+
* @param filename the SVG file to be loaded. Must be in the data directory
|
268
|
+
*/
|
269
|
+
public static RShape loadShape(String filename) {
|
270
|
+
RSVG svgLoader = new RSVG();
|
271
|
+
return svgLoader.toShape(filename);
|
272
|
+
}
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Save a shape object to a file.
|
276
|
+
*
|
277
|
+
* @eexample saveShape
|
278
|
+
* @param filename the SVG file to be saved.
|
279
|
+
* @param shape the shape to be saved.
|
280
|
+
*/
|
281
|
+
public static void saveShape(String filename, RShape shape) {
|
282
|
+
RSVG svgSaver = new RSVG();
|
283
|
+
String str = svgSaver.fromShape(shape);
|
284
|
+
String[] strs = PApplet.split(str, "\n");
|
285
|
+
RG.parent().saveStrings(filename, strs);
|
286
|
+
}
|
287
|
+
|
288
|
+
// Methods to create shapes
|
289
|
+
/**
|
290
|
+
* Begin to create a shape.
|
291
|
+
*
|
292
|
+
* @eexample createShape
|
293
|
+
*/
|
294
|
+
public static void beginShape() {
|
295
|
+
shape = new RShape();
|
296
|
+
}
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Begin a new path in the current shape. Can only be called inside
|
300
|
+
* beginShape() and endShape().
|
301
|
+
*
|
302
|
+
* @param endMode if called with RG.CLOSE it closes the current path before
|
303
|
+
* starting the new one.
|
304
|
+
* @eexample createShape
|
305
|
+
*/
|
306
|
+
public static void breakShape(int endMode) {
|
307
|
+
if (endMode == CLOSE) {
|
308
|
+
shape.addClose();
|
309
|
+
}
|
310
|
+
|
311
|
+
shape.updateOrigParams();
|
312
|
+
|
313
|
+
breakShape();
|
314
|
+
}
|
315
|
+
|
316
|
+
public static void breakShape() {
|
317
|
+
shape.addPath();
|
318
|
+
}
|
319
|
+
|
320
|
+
/**
|
321
|
+
* Add a vertex to the shape. Can only be called inside beginShape() and
|
322
|
+
* endShape().
|
323
|
+
*
|
324
|
+
* @eexample createShape
|
325
|
+
* @param x the x coordinate of the vertex
|
326
|
+
* @param y the y coordinate of the vertex
|
327
|
+
*/
|
328
|
+
public static void vertex(float x, float y) {
|
329
|
+
if (shape.countPaths() == 0) {
|
330
|
+
shape.addMoveTo(x, y);
|
331
|
+
} else {
|
332
|
+
shape.addLineTo(x, y);
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
/**
|
337
|
+
* Add a bezierVertex to the shape. Can only be called inside beginShape()
|
338
|
+
* and endShape().
|
339
|
+
*
|
340
|
+
* @eexample createShape
|
341
|
+
* @param cx1 the x coordinate of the first control point
|
342
|
+
* @param cy1 the y coordinate of the first control point
|
343
|
+
* @param cx2 the x coordinate of the second control point
|
344
|
+
* @param cy2 the y coordinate of the second control point
|
345
|
+
* @param x the x coordinate of the end point
|
346
|
+
* @param y the y coordinate of the end point
|
347
|
+
*/
|
348
|
+
public static void bezierVertex(float cx1, float cy1, float cx2, float cy2, float x, float y) {
|
349
|
+
if (shape.countPaths() == 0) {
|
350
|
+
throw new NoPathInitializedException();
|
351
|
+
} else {
|
352
|
+
shape.addBezierTo(cx1, cy1, cx2, cy2, x, y);
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
/**
|
357
|
+
* End the shape being created and draw it to the screen or the PGraphics
|
358
|
+
* passed as parameter.
|
359
|
+
*
|
360
|
+
* @eexample createShape
|
361
|
+
* @param g the canvas on which to draw. By default it draws on the screen
|
362
|
+
*/
|
363
|
+
public static void endShape(PGraphics g) {
|
364
|
+
shape.draw(g);
|
365
|
+
shape = null;
|
366
|
+
}
|
367
|
+
|
368
|
+
public static void endShape() {
|
369
|
+
shape.draw();
|
370
|
+
shape = null;
|
371
|
+
}
|
372
|
+
|
373
|
+
/**
|
374
|
+
* End the shape being created and get it as an object.
|
375
|
+
*
|
376
|
+
* @return
|
377
|
+
* @eexample getShape
|
378
|
+
*/
|
379
|
+
public static RShape getShape() {
|
380
|
+
RShape returningGroup = new RShape();
|
381
|
+
returningGroup.addChild(shape);
|
382
|
+
|
383
|
+
shape = null;
|
384
|
+
|
385
|
+
returningGroup.updateOrigParams();
|
386
|
+
|
387
|
+
return returningGroup;
|
388
|
+
}
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Get an ellipse as a shape object.
|
392
|
+
*
|
393
|
+
* @eexample getEllipse
|
394
|
+
* @param x x coordinate of the center of the shape
|
395
|
+
* @param y y coordinate of the center of the shape
|
396
|
+
* @param w width of the ellipse
|
397
|
+
* @param h height of the ellipse
|
398
|
+
* @return RShape, the shape created
|
399
|
+
*/
|
400
|
+
public static RShape getEllipse(float x, float y, float w, float h) {
|
401
|
+
return RShape.createEllipse(x, y, w, h);
|
402
|
+
}
|
403
|
+
|
404
|
+
public static RShape getEllipse(float x, float y, float w) {
|
405
|
+
return getEllipse(x, y, w, w);
|
406
|
+
}
|
407
|
+
|
408
|
+
/**
|
409
|
+
* Get a line as a shape object.
|
410
|
+
*
|
411
|
+
* @eexample getLine
|
412
|
+
* @param x1 x coordinate of the first point of the line
|
413
|
+
* @param y1 y coordinate of the first point of the line
|
414
|
+
* @param x2 x coordinate of the last point of the line
|
415
|
+
* @param y2 y coordinate of the last point of the line
|
416
|
+
* @return RShape, the shape created
|
417
|
+
*/
|
418
|
+
public static RShape getLine(float x1, float y1, float x2, float y2) {
|
419
|
+
return RShape.createLine(x1, y1, x2, y2);
|
420
|
+
}
|
421
|
+
|
422
|
+
/**
|
423
|
+
* Get an rectangle as a shape object.
|
424
|
+
*
|
425
|
+
* @eexample getRect
|
426
|
+
* @param x x coordinate of the top left corner of the shape
|
427
|
+
* @param y y coordinate of the top left of the shape
|
428
|
+
* @param w width of the rectangle
|
429
|
+
* @param h height of the rectangle
|
430
|
+
* @return RShape, the shape created
|
431
|
+
*/
|
432
|
+
public static RShape getRect(float x, float y, float w, float h) {
|
433
|
+
return RShape.createRectangle(x, y, w, h);
|
434
|
+
}
|
435
|
+
|
436
|
+
public static RShape getRect(float x, float y, float w) {
|
437
|
+
return getRect(x, y, w, w);
|
438
|
+
}
|
439
|
+
|
440
|
+
/**
|
441
|
+
* Get a star as a shape object.
|
442
|
+
*
|
443
|
+
* @eexample getStar
|
444
|
+
* @param x x coordinate of the center of the shape
|
445
|
+
* @param y y coordinate of the center of the shape
|
446
|
+
* @param widthBig the outter width of the star polygon
|
447
|
+
* @param widthSmall the inner width of the star polygon
|
448
|
+
* @param spikes the amount of spikes on the star polygon
|
449
|
+
* @return RShape, the shape created
|
450
|
+
*/
|
451
|
+
public static RShape getStar(float x, float y, float widthBig, float widthSmall, int spikes) {
|
452
|
+
return RShape.createStar(x, y, widthBig, widthSmall, spikes);
|
453
|
+
}
|
454
|
+
|
455
|
+
/**
|
456
|
+
* Get a ring as a shape object.
|
457
|
+
*
|
458
|
+
* @eexample getRing
|
459
|
+
* @param x x coordinate of the center of the shape
|
460
|
+
* @param y y coordinate of the center of the shape
|
461
|
+
* @param widthBig the outter width of the ring polygon
|
462
|
+
* @param widthSmall the inner width of the ring polygon
|
463
|
+
* @return RShape, the shape created
|
464
|
+
*/
|
465
|
+
public static RShape getRing(float x, float y, float widthBig, float widthSmall) {
|
466
|
+
return RShape.createRing(x, y, widthBig, widthSmall);
|
467
|
+
}
|
468
|
+
|
469
|
+
// Transformation methods
|
470
|
+
public static RShape centerIn(RShape grp, PGraphics g, float margin) {
|
471
|
+
RShape ret = new RShape(grp);
|
472
|
+
ret.centerIn(g, margin);
|
473
|
+
return ret;
|
474
|
+
}
|
475
|
+
|
476
|
+
public static RShape centerIn(RShape grp, PGraphics g) {
|
477
|
+
return centerIn(grp, g, 0);
|
478
|
+
}
|
479
|
+
|
480
|
+
/**
|
481
|
+
* Split a shape along the curve length in two parts.
|
482
|
+
*
|
483
|
+
* @eexample split
|
484
|
+
* @param shp the shape to be splited
|
485
|
+
* @param t the proportion (a value from 0 to 1) along the curve where to
|
486
|
+
* split
|
487
|
+
* @return RShape[], an array of shapes with two elements, one for each side
|
488
|
+
* of the split
|
489
|
+
*/
|
490
|
+
public static RShape[] split(RShape shp, float t) {
|
491
|
+
return shp.split(t);
|
492
|
+
}
|
493
|
+
|
494
|
+
/**
|
495
|
+
* Adapt a shape along the curve of another shape.
|
496
|
+
*
|
497
|
+
* @eexample split
|
498
|
+
* @param shp the shape to be adapted
|
499
|
+
* @param path the shape which curve will be followed
|
500
|
+
* @return RShape the adapted shape
|
501
|
+
* @related setAdaptor ( )
|
502
|
+
*/
|
503
|
+
public static RShape adapt(RShape shp, RShape path) {
|
504
|
+
RShape ret = new RShape(shp);
|
505
|
+
ret.adapt(path);
|
506
|
+
return ret;
|
507
|
+
}
|
508
|
+
|
509
|
+
/**
|
510
|
+
* Polygonize a shape.
|
511
|
+
*
|
512
|
+
* @eexample split
|
513
|
+
* @param shp the shape to be polygonized
|
514
|
+
* @return RShape, the polygonized shape
|
515
|
+
* @related setPolygonizer ( )
|
516
|
+
*/
|
517
|
+
public static RShape polygonize(RShape shp) {
|
518
|
+
RShape ret = new RShape(shp);
|
519
|
+
ret.polygonize();
|
520
|
+
return ret;
|
521
|
+
}
|
522
|
+
|
523
|
+
// State methods
|
524
|
+
/**
|
525
|
+
* Initialize the library. Must be called before any call to Geomerative
|
526
|
+
* methods. Must be called by passing the PApplet. e.g. RG.init(this)
|
527
|
+
*
|
528
|
+
* @param _parent
|
529
|
+
*/
|
530
|
+
public static void init(PApplet _parent) {
|
531
|
+
parent = _parent;
|
532
|
+
initialized = true;
|
533
|
+
}
|
534
|
+
|
535
|
+
/**
|
536
|
+
* @return @invisible
|
537
|
+
*/
|
538
|
+
public static boolean initialized() {
|
539
|
+
return initialized;
|
540
|
+
}
|
541
|
+
|
542
|
+
/**
|
543
|
+
* @return @invisible
|
544
|
+
*/
|
545
|
+
protected static PApplet parent() {
|
546
|
+
if (parent == null) {
|
547
|
+
throw new LibraryNotInitializedException();
|
548
|
+
}
|
549
|
+
|
550
|
+
return parent;
|
551
|
+
}
|
552
|
+
|
553
|
+
/**
|
554
|
+
* @return @invisible
|
555
|
+
*/
|
556
|
+
protected static int dpi() {
|
557
|
+
return dpi;
|
558
|
+
}
|
559
|
+
|
560
|
+
/**
|
561
|
+
* Use this to set the resolution of the display. This specifies the Dots
|
562
|
+
* Per Inch of the display.
|
563
|
+
*
|
564
|
+
* @param _dpi the dots per inch of the display
|
565
|
+
*
|
566
|
+
*/
|
567
|
+
public static void setDpi(int _dpi) {
|
568
|
+
dpi = _dpi;
|
569
|
+
}
|
570
|
+
|
571
|
+
/**
|
572
|
+
* Binary difference between two shapes.
|
573
|
+
*
|
574
|
+
* @eexample binaryOps
|
575
|
+
* @param a first shape to operate on
|
576
|
+
* @param b second shape to operate on
|
577
|
+
* @return RShape, the result of the operation
|
578
|
+
* @related diff ( )
|
579
|
+
* @related union ( )
|
580
|
+
* @related intersection ( )
|
581
|
+
* @related xor ( )
|
582
|
+
*/
|
583
|
+
public static RShape diff(RShape a, RShape b) {
|
584
|
+
return a.diff(b);
|
585
|
+
}
|
586
|
+
|
587
|
+
/**
|
588
|
+
* Binary union between two shapes.
|
589
|
+
*
|
590
|
+
* @eexample binaryOps
|
591
|
+
* @param a first shape to operate on
|
592
|
+
* @param b second shape to operate on
|
593
|
+
* @return RShape, the result of the operation
|
594
|
+
* @related diff ( )
|
595
|
+
* @related union ( )
|
596
|
+
* @related intersection ( )
|
597
|
+
* @related xor ( )
|
598
|
+
*/
|
599
|
+
public static RShape union(RShape a, RShape b) {
|
600
|
+
return a.union(b);
|
601
|
+
}
|
602
|
+
|
603
|
+
/**
|
604
|
+
* Binary intersection between two shapes.
|
605
|
+
*
|
606
|
+
* @eexample binaryOps
|
607
|
+
* @param a first shape to operate on
|
608
|
+
* @param b second shape to operate on
|
609
|
+
* @return RShape, the result of the operation
|
610
|
+
* @related diff ( )
|
611
|
+
* @related union ( )
|
612
|
+
* @related intersection ( )
|
613
|
+
* @related xor ( )
|
614
|
+
*/
|
615
|
+
public static RShape intersection(RShape a, RShape b) {
|
616
|
+
return a.intersection(b);
|
617
|
+
}
|
618
|
+
|
619
|
+
/**
|
620
|
+
* Binary xor between two shapes.
|
621
|
+
*
|
622
|
+
* @eexample binaryOps
|
623
|
+
* @param a first shape to operate on
|
624
|
+
* @param b second shape to operate on
|
625
|
+
* @return RShape, the result of the operation
|
626
|
+
* @related diff ( )
|
627
|
+
* @related union ( )
|
628
|
+
* @related intersection ( )
|
629
|
+
* @related xor ( )
|
630
|
+
*/
|
631
|
+
public static RShape xor(RShape a, RShape b) {
|
632
|
+
return a.xor(b);
|
633
|
+
}
|
634
|
+
|
635
|
+
/**
|
636
|
+
* Ignore the styles of the shapes when drawing and use the Processing style
|
637
|
+
* methods.
|
638
|
+
*
|
639
|
+
* @eexample ignoreStyles
|
640
|
+
* @param value value to which the ignoreStyles state should be set
|
641
|
+
*/
|
642
|
+
public static void ignoreStyles(boolean value) {
|
643
|
+
ignoreStyles = value;
|
644
|
+
}
|
645
|
+
|
646
|
+
public static void ignoreStyles() {
|
647
|
+
ignoreStyles = true;
|
648
|
+
}
|
649
|
+
|
650
|
+
/**
|
651
|
+
* Use this to set the adaptor type.
|
652
|
+
*
|
653
|
+
* @eexample RShape_setAdaptor
|
654
|
+
* @param adptorType it can be RG.BYPOINT, RG.BYELEMENTPOSITION or
|
655
|
+
* RG.BYELEMENTINDEX
|
656
|
+
* @related BYPOINT
|
657
|
+
* @related BYELEMENTPOSITION
|
658
|
+
* @related BYELEMENTINDEX
|
659
|
+
*/
|
660
|
+
public static void setAdaptor(int adptorType) {
|
661
|
+
adaptorType = adptorType;
|
662
|
+
}
|
663
|
+
|
664
|
+
/**
|
665
|
+
* Use this to set the adaptor scaling. This scales the transformation of
|
666
|
+
* the adaptor.
|
667
|
+
*
|
668
|
+
* @eexample RShape_setAdaptor
|
669
|
+
* @param adptorScale the scaling coefficient
|
670
|
+
*/
|
671
|
+
public static void setAdaptorScale(float adptorScale) {
|
672
|
+
adaptorScale = adptorScale;
|
673
|
+
}
|
674
|
+
|
675
|
+
/**
|
676
|
+
* Use this to set the adaptor length offset. This specifies where to start
|
677
|
+
* adapting the group to the shape.
|
678
|
+
*
|
679
|
+
* @eexample RShape_setAdaptorLengthOffset
|
680
|
+
* @param adptorLengthOffset the offset along the curve of the shape. Must
|
681
|
+
* be a value between 0 and 1;
|
682
|
+
*
|
683
|
+
*/
|
684
|
+
public static void setAdaptorLengthOffset(float adptorLengthOffset) throws RuntimeException {
|
685
|
+
if (adptorLengthOffset >= 0F && adptorLengthOffset <= 1F) {
|
686
|
+
adaptorLengthOffset = adptorLengthOffset;
|
687
|
+
} else {
|
688
|
+
throw new RuntimeException("The adaptor length offset must take a value between 0 and 1.");
|
689
|
+
}
|
690
|
+
}
|
691
|
+
|
692
|
+
/**
|
693
|
+
* Use this to set the polygonizer type.
|
694
|
+
*
|
695
|
+
* @param segmenterMethod can be RG.ADAPTATIVE, RG.UNIFORMLENGTH or
|
696
|
+
* RG.UNIFORMSTEP.
|
697
|
+
*
|
698
|
+
* @eexample setPolygonizer
|
699
|
+
* @related ADAPTATIVE
|
700
|
+
* @related UNIFORMLENGTH
|
701
|
+
* @related UNIFORMSTEP
|
702
|
+
*
|
703
|
+
*/
|
704
|
+
public static void setPolygonizer(int segmenterMethod) {
|
705
|
+
RCommand.setSegmentator(segmenterMethod);
|
706
|
+
}
|
707
|
+
|
708
|
+
/**
|
709
|
+
* Use this to set the segmentator angle tolerance for the ADAPTATIVE
|
710
|
+
* segmentator and set the segmentator to ADAPTATIVE.
|
711
|
+
*
|
712
|
+
* @eexample setPolygonizerAngle
|
713
|
+
* @param angle an angle from 0 to PI/2 it defines the maximum angle between
|
714
|
+
* segments.
|
715
|
+
* @related ADAPTATIVE
|
716
|
+
*
|
717
|
+
*/
|
718
|
+
public static void setPolygonizerAngle(float angle) {
|
719
|
+
RCommand.setSegmentAngle(angle);
|
720
|
+
}
|
721
|
+
|
722
|
+
/**
|
723
|
+
* Use this to set the segmentator length for the UNIFORMLENGTH segmentator
|
724
|
+
* and set the segmentator to UNIFORMLENGTH.
|
725
|
+
*
|
726
|
+
* @eexample setPolygonizerLength
|
727
|
+
* @param length the length of each resulting segment.
|
728
|
+
* @related UNIFORMLENGTH
|
729
|
+
* @related polygonize ( )
|
730
|
+
*/
|
731
|
+
public static void setPolygonizerLength(float length) {
|
732
|
+
RCommand.setSegmentLength(length);
|
733
|
+
}
|
734
|
+
|
735
|
+
/**
|
736
|
+
* Use this to set the segmentator step for the UNIFORMSTEP segmentator and
|
737
|
+
* set the segmentator to UNIFORMSTEP.
|
738
|
+
*
|
739
|
+
* @eexample setSegmentStep
|
740
|
+
* @param step if a float from +0.0 to 1.0 is passed it's considered as the
|
741
|
+
* step, else it's considered as the number of steps. When a value of 0.0 is
|
742
|
+
* used the steps will be calculated automatically depending on an
|
743
|
+
* estimation of the length of the curve. The special value -1 is the same
|
744
|
+
* as 0.0 but also turning of the segmentation of lines (faster
|
745
|
+
* segmentation).
|
746
|
+
* @related UNIFORMSTEP
|
747
|
+
* @related polygonize ( )
|
748
|
+
*/
|
749
|
+
public static void setPolygonizerStep(float step) {
|
750
|
+
RCommand.setSegmentStep(step);
|
751
|
+
}
|
752
|
+
|
753
|
+
}
|