geomerative 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/LICENSE +662 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +2 -0
  6. data/Rakefile +37 -0
  7. data/examples/README.md +7 -0
  8. data/examples/data/FreeSans.ttf +0 -0
  9. data/examples/data/ReplicaBold.ttf +0 -0
  10. data/examples/data/bot1.svg +160 -0
  11. data/examples/hello_svg_to_pdf.rb +26 -0
  12. data/examples/hello_world.rb +23 -0
  13. data/examples/physics_type.rb +77 -0
  14. data/examples/rotate_first_letter.rb +28 -0
  15. data/geomerative.gemspec +32 -0
  16. data/lib/geomerative.rb +12 -0
  17. data/lib/geomerative/version.rb +3 -0
  18. data/pom.xml +110 -0
  19. data/src/geomerative/FastRClip.java +2715 -0
  20. data/src/geomerative/RClip.java +2892 -0
  21. data/src/geomerative/RClosest.java +64 -0
  22. data/src/geomerative/RCommand.java +1941 -0
  23. data/src/geomerative/RContour.java +348 -0
  24. data/src/geomerative/RFont.java +583 -0
  25. data/src/geomerative/RG.java +753 -0
  26. data/src/geomerative/RGeomElem.java +1075 -0
  27. data/src/geomerative/RGroup.java +888 -0
  28. data/src/geomerative/RMatrix.java +401 -0
  29. data/src/geomerative/RMesh.java +420 -0
  30. data/src/geomerative/RPath.java +1095 -0
  31. data/src/geomerative/RPoint.java +419 -0
  32. data/src/geomerative/RPolygon.java +1110 -0
  33. data/src/geomerative/RRectangle.java +91 -0
  34. data/src/geomerative/RSVG.java +976 -0
  35. data/src/geomerative/RShape.java +2045 -0
  36. data/src/geomerative/RStrip.java +221 -0
  37. data/src/geomerative/RStyle.java +469 -0
  38. data/src/org/apache/batik/svggen/font/.SVGFont.java.swp +0 -0
  39. data/src/org/apache/batik/svggen/font/Font.java +188 -0
  40. data/src/org/apache/batik/svggen/font/Glyph.java +113 -0
  41. data/src/org/apache/batik/svggen/font/Messages.java.bak +72 -0
  42. data/src/org/apache/batik/svggen/font/Point.java +38 -0
  43. data/src/org/apache/batik/svggen/font/RandomAccessFileEmulator.java +15 -0
  44. data/src/org/apache/batik/svggen/font/table/ClassDef.java +42 -0
  45. data/src/org/apache/batik/svggen/font/table/ClassDefFormat1.java +55 -0
  46. data/src/org/apache/batik/svggen/font/table/ClassDefFormat2.java +49 -0
  47. data/src/org/apache/batik/svggen/font/table/CmapFormat.java +81 -0
  48. data/src/org/apache/batik/svggen/font/table/CmapFormat0.java +60 -0
  49. data/src/org/apache/batik/svggen/font/table/CmapFormat2.java +48 -0
  50. data/src/org/apache/batik/svggen/font/table/CmapFormat4.java +147 -0
  51. data/src/org/apache/batik/svggen/font/table/CmapFormat6.java +60 -0
  52. data/src/org/apache/batik/svggen/font/table/CmapIndexEntry.java +84 -0
  53. data/src/org/apache/batik/svggen/font/table/CmapTable.java +87 -0
  54. data/src/org/apache/batik/svggen/font/table/Coverage.java +50 -0
  55. data/src/org/apache/batik/svggen/font/table/CoverageFormat1.java +59 -0
  56. data/src/org/apache/batik/svggen/font/table/CoverageFormat2.java +56 -0
  57. data/src/org/apache/batik/svggen/font/table/CvtTable.java +48 -0
  58. data/src/org/apache/batik/svggen/font/table/Device.java +63 -0
  59. data/src/org/apache/batik/svggen/font/table/DirectoryEntry.java +73 -0
  60. data/src/org/apache/batik/svggen/font/table/Feature.java +56 -0
  61. data/src/org/apache/batik/svggen/font/table/FeatureList.java +70 -0
  62. data/src/org/apache/batik/svggen/font/table/FeatureRecord.java +52 -0
  63. data/src/org/apache/batik/svggen/font/table/FeatureTags.java +30 -0
  64. data/src/org/apache/batik/svggen/font/table/FpgmTable.java +38 -0
  65. data/src/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +165 -0
  66. data/src/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +160 -0
  67. data/src/org/apache/batik/svggen/font/table/GlyfDescript.java +79 -0
  68. data/src/org/apache/batik/svggen/font/table/GlyfSimpleDescript.java +155 -0
  69. data/src/org/apache/batik/svggen/font/table/GlyfTable.java +111 -0
  70. data/src/org/apache/batik/svggen/font/table/GlyphDescription.java +39 -0
  71. data/src/org/apache/batik/svggen/font/table/GposTable.java +80 -0
  72. data/src/org/apache/batik/svggen/font/table/GsubTable.java +118 -0
  73. data/src/org/apache/batik/svggen/font/table/HeadTable.java +159 -0
  74. data/src/org/apache/batik/svggen/font/table/HheaTable.java +109 -0
  75. data/src/org/apache/batik/svggen/font/table/HmtxTable.java +99 -0
  76. data/src/org/apache/batik/svggen/font/table/KernSubtable.java +58 -0
  77. data/src/org/apache/batik/svggen/font/table/KernSubtableFormat0.java +65 -0
  78. data/src/org/apache/batik/svggen/font/table/KernSubtableFormat2.java +56 -0
  79. data/src/org/apache/batik/svggen/font/table/KernTable.java +64 -0
  80. data/src/org/apache/batik/svggen/font/table/KerningPair.java +53 -0
  81. data/src/org/apache/batik/svggen/font/table/LangSys.java +58 -0
  82. data/src/org/apache/batik/svggen/font/table/LangSysRecord.java +52 -0
  83. data/src/org/apache/batik/svggen/font/table/Ligature.java +57 -0
  84. data/src/org/apache/batik/svggen/font/table/LigatureSet.java +55 -0
  85. data/src/org/apache/batik/svggen/font/table/LigatureSubst.java +40 -0
  86. data/src/org/apache/batik/svggen/font/table/LigatureSubstFormat1.java +63 -0
  87. data/src/org/apache/batik/svggen/font/table/LocaTable.java +72 -0
  88. data/src/org/apache/batik/svggen/font/table/Lookup.java +77 -0
  89. data/src/org/apache/batik/svggen/font/table/LookupList.java +68 -0
  90. data/src/org/apache/batik/svggen/font/table/LookupSubtable.java +27 -0
  91. data/src/org/apache/batik/svggen/font/table/LookupSubtableFactory.java +31 -0
  92. data/src/org/apache/batik/svggen/font/table/MaxpTable.java +124 -0
  93. data/src/org/apache/batik/svggen/font/table/NameRecord.java +98 -0
  94. data/src/org/apache/batik/svggen/font/table/NameTable.java +67 -0
  95. data/src/org/apache/batik/svggen/font/table/Os2Table.java +232 -0
  96. data/src/org/apache/batik/svggen/font/table/Panose.java +108 -0
  97. data/src/org/apache/batik/svggen/font/table/PostTable.java +379 -0
  98. data/src/org/apache/batik/svggen/font/table/PrepTable.java +38 -0
  99. data/src/org/apache/batik/svggen/font/table/Program.java +49 -0
  100. data/src/org/apache/batik/svggen/font/table/RangeRecord.java +57 -0
  101. data/src/org/apache/batik/svggen/font/table/Script.java +72 -0
  102. data/src/org/apache/batik/svggen/font/table/ScriptList.java +78 -0
  103. data/src/org/apache/batik/svggen/font/table/ScriptRecord.java +52 -0
  104. data/src/org/apache/batik/svggen/font/table/ScriptTags.java +28 -0
  105. data/src/org/apache/batik/svggen/font/table/SingleSubst.java +47 -0
  106. data/src/org/apache/batik/svggen/font/table/SingleSubstFormat1.java +67 -0
  107. data/src/org/apache/batik/svggen/font/table/SingleSubstFormat2.java +67 -0
  108. data/src/org/apache/batik/svggen/font/table/Table.java +204 -0
  109. data/src/org/apache/batik/svggen/font/table/TableDirectory.java +94 -0
  110. data/src/org/apache/batik/svggen/font/table/TableFactory.java +121 -0
  111. metadata +206 -0
@@ -0,0 +1,401 @@
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
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ Geomerative is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ package geomerative ;
21
+
22
+ import processing.core.PApplet;
23
+
24
+ /**
25
+ * RMatrix is a very simple interface for creating, holding 3x3 matrices with the most common 2D affine transformations such as translation, rotation, scaling and shearing. We only have access to the first to rows of the matrix the last row is considered a constant 0, 0, 1 in order to have better performance.
26
+ * @eexample RMatrix
27
+ * @usage Geometry
28
+ * @extended
29
+ */
30
+ public class RMatrix
31
+ {
32
+
33
+ float m00 = 1F;
34
+ float m01 = 0F;
35
+ float m02 = 0F;
36
+
37
+ float m10 = 0F;
38
+ float m11 = 1F;
39
+ float m12 = 0F;
40
+
41
+ float m20 = 0F;
42
+ float m21 = 0F;
43
+ float m22 = 1F;
44
+
45
+ /**
46
+ * Create a new matrix given the coefficients.
47
+ * @eexample RMatrix
48
+ * @param m00 coefficient 00 of the matrix
49
+ * @param m01 coefficient 01 of the matrix
50
+ * @param m02 coefficient 02 of the matrix
51
+ * @param m10 coefficient 10 of the matrix
52
+ * @param m11 coefficient 11 of the matrix
53
+ * @param m12 coefficient 12 of the matrix
54
+ * @usage Geometry
55
+ * @related apply ( )
56
+ * @related translate ( )
57
+ * @related rotate ( )
58
+ * @related scale ( )
59
+ * @related shear ( )
60
+ */
61
+ public RMatrix(float m00, float m01, float m02,
62
+ float m10, float m11, float m12)
63
+ {
64
+ set(m00, m01, m02,
65
+ m10, m11, m12);
66
+ }
67
+
68
+ /**
69
+ * Create a new identity matrix.
70
+ * @eexample RMatrix
71
+ * @usage Geometry
72
+ * @related apply ( )
73
+ * @related translate ( )
74
+ * @related rotate ( )
75
+ * @related scale ( )
76
+ * @related shear ( )
77
+ */
78
+ public RMatrix()
79
+ {
80
+ m00 = 1F;
81
+ m01 = 0F;
82
+ m02 = 0F;
83
+
84
+ m10 = 0F;
85
+ m11 = 1F;
86
+ m12 = 0F;
87
+ }
88
+
89
+ /**
90
+ * Copy a matrix.
91
+ * @eexample RMatrix
92
+ * @param src source matrix from where to copy the matrix
93
+ * @usage Geometry
94
+ * @related apply ( )
95
+ * @related translate ( )
96
+ * @related rotate ( )
97
+ * @related scale ( )
98
+ * @related shear ( )
99
+ */
100
+ public RMatrix(RMatrix src)
101
+ {
102
+ set(src.m00, src.m01, src.m02,
103
+ src.m10, src.m11, src.m12);
104
+ }
105
+
106
+ public RMatrix(String transformationString){
107
+ String[] transfTokens = PApplet.splitTokens(transformationString, ")");
108
+
109
+ // Loop through all transformations
110
+ for(int i=0; i<transfTokens.length; i++){
111
+ // Check the transformation and the parameters
112
+ String[] transf = PApplet.splitTokens(transfTokens[i], "(");
113
+ String[] params = PApplet.splitTokens(transf[1], ", ");
114
+ float[] fparams = new float[params.length];
115
+ for(int j=0; j<params.length; j++){
116
+ fparams[j] = PApplet.parseFloat(params[j]);
117
+ }
118
+
119
+ transf[0] = PApplet.trim(transf[0]);
120
+
121
+ if(transf[0].equals("translate")){
122
+ if(params.length == 1){
123
+ this.translate(fparams[0]);
124
+
125
+ }else if(params.length == 2){
126
+ this.translate(fparams[0], fparams[1]);
127
+
128
+ }
129
+ }else if(transf[0].equals("rotate")){
130
+ if(params.length == 1){
131
+ this.rotate(PApplet.radians(fparams[0]));
132
+
133
+ }else if(params.length == 3){
134
+ this.rotate(PApplet.radians(fparams[0]), fparams[1], fparams[2]);
135
+
136
+ }
137
+
138
+ }else if(transf[0].equals("scale")){
139
+ if(params.length == 1){
140
+ this.scale(fparams[0]);
141
+
142
+ }else if(params.length == 2){
143
+ this.scale(fparams[0], fparams[1]);
144
+ }
145
+
146
+ }else if(transf[0].equals("skewX")){
147
+ this.skewX(PApplet.radians(fparams[0]));
148
+
149
+ }else if(transf[0].equals("skewY")){
150
+ this.skewY(PApplet.radians(fparams[0]));
151
+
152
+ }else if(transf[0].equals("matrix")){
153
+ this.apply(fparams[0], fparams[2], fparams[4], fparams[1], fparams[3], fparams[5]);
154
+
155
+ }else{
156
+ throw new RuntimeException("Transformation unknown. '"+ transf[0] +"'");
157
+ }
158
+ }
159
+ }
160
+
161
+ private void set(float m00, float m01, float m02,
162
+ float m10, float m11, float m12)
163
+ {
164
+ this.m00 = m00;
165
+ this.m01 = m01;
166
+ this.m02 = m02;
167
+
168
+ this.m10 = m10;
169
+ this.m11 = m11;
170
+ this.m12 = m12;
171
+ }
172
+
173
+ /**
174
+ * Multiply the matrix with another matrix. This is mostly use to chain transformations.
175
+ * @eexample RMatrix_apply
176
+ * @param n00 coefficient 00 of the matrix to be applied
177
+ * @param n01 coefficient 01 of the matrix to be applied
178
+ * @param n02 coefficient 02 of the matrix to be applied
179
+ * @param n10 coefficient 10 of the matrix to be applied
180
+ * @param n11 coefficient 11 of the matrix to be applied
181
+ * @param n12 coefficient 12 of the matrix to be applied
182
+ * @usage Geometry
183
+ * @related translate ( )
184
+ * @related rotate ( )
185
+ * @related scale ( )
186
+ * @related shear ( )
187
+ */
188
+ public void apply(float n00, float n01, float n02,
189
+ float n10, float n11, float n12) {
190
+
191
+ float r00 = m00*n00 + m01*n10;
192
+ float r01 = m00*n01 + m01*n11;
193
+ float r02 = m00*n02 + m01*n12 + m02;
194
+
195
+ float r10 = m10*n00 + m11*n10;
196
+ float r11 = m10*n01 + m11*n11 ;
197
+ float r12 = m10*n02 + m11*n12 + m12;
198
+
199
+ m00 = r00; m01 = r01; m02 = r02;
200
+ m10 = r10; m11 = r11; m12 = r12;
201
+ }
202
+
203
+ /**
204
+ * Multiply the matrix with another matrix. This is mostly use to chain transformations.
205
+ * @eexample RMatrix_apply
206
+ * @param rhs right hand side matrix
207
+ * @usage Geometry
208
+ * @related translate ( )
209
+ * @related rotate ( )
210
+ * @related scale ( )
211
+ * @related shear ( )
212
+ */
213
+ public void apply(RMatrix rhs) {
214
+ apply(rhs.m00, rhs.m01, rhs.m02,
215
+ rhs.m10, rhs.m11, rhs.m12);
216
+ }
217
+
218
+ /**
219
+ * Apply a translation to the matrix, given the coordinates.
220
+ * @eexample RMatrix_translate
221
+ * @param tx x coordinate translation
222
+ * @param ty y coordinate translation
223
+ * @usage Geometry
224
+ * @related rotate ( )
225
+ * @related scale ( )
226
+ * @related shear ( )
227
+ */
228
+ public void translate(float tx, float ty)
229
+ {
230
+ apply(1, 0, tx, 0, 1, ty);
231
+ }
232
+
233
+ public void translate(float tx)
234
+ {
235
+ translate(tx, 0);
236
+ }
237
+
238
+ /**
239
+ * Apply a translation to the matrix, given a point.
240
+ * @eexample RMatrix_translate
241
+ * @param t vector translation
242
+ * @usage Geometry
243
+ * @related rotate ( )
244
+ * @related scale ( )
245
+ * @related shear ( )
246
+ */
247
+ public void translate(RPoint t)
248
+ {
249
+ translate(t.x, t.y);
250
+ }
251
+
252
+ /**
253
+ * Apply a rotation to the matrix, given an angle and optionally a rotation center.
254
+ * @eexample RPoint_rotate
255
+ * @usage Geometry
256
+ * @param angle the angle of rotation to be applied
257
+ * @param vx the x coordinate of the center of rotation
258
+ * @param vy the y coordinate of the center of rotation
259
+ * @related transform ( )
260
+ * @related translate ( )
261
+ * @related scale ( )
262
+ */
263
+ public void rotate(float angle, float vx, float vy)
264
+ {
265
+ translate(vx,vy);
266
+ rotate(angle);
267
+ translate(-vx,-vy);
268
+ }
269
+
270
+ public void rotate(float angle)
271
+ {
272
+ float c = (float)Math.cos(angle);
273
+ float s = (float)Math.sin(angle);
274
+ apply(c, -s, 0, s, c, 0);
275
+ }
276
+
277
+ /**
278
+ * Apply a rotation to the matrix, given an angle and optionally a rotation center.
279
+ * @eexample RPoint_rotate
280
+ * @usage Geometry
281
+ * @param angle the angle of rotation to be applied
282
+ * @param v the position vector of the center of rotation
283
+ * @related transform ( )
284
+ * @related translate ( )
285
+ * @related scale ( )
286
+ */
287
+ public void rotate(float angle, RPoint v)
288
+ {
289
+ rotate(angle, v.x, v.y);
290
+ }
291
+
292
+ /**
293
+ * Apply a scale to the matrix, given scaling factors and optionally a scaling center.
294
+ * @eexample RPoint_scale
295
+ * @usage Geometry
296
+ * @param sx the scaling coefficient over the x axis
297
+ * @param sy the scaling coefficient over the y axis
298
+ * @param x x coordinate of the position vector of the center of the scaling
299
+ * @param y y coordinate of the position vector of the center of the scaling
300
+ * @related transform ( )
301
+ * @related translate ( )
302
+ * @related rotate ( )
303
+ */
304
+ public void scale(float sx, float sy, float x, float y)
305
+ {
306
+ translate(x,y);
307
+ scale(sx,sy);
308
+ translate(-x,-y);
309
+ }
310
+
311
+ public void scale(float sx, float sy)
312
+ {
313
+ apply(sx, 0, 0, 0, sy, 0);
314
+ }
315
+
316
+ /**
317
+ * Apply a scale to the matrix, given scaling factors and optionally a scaling center.
318
+ * @eexample RPoint_scale
319
+ * @usage Geometry
320
+ * @param s the scaling coefficient for a uniform scaling
321
+ * @param x x coordinate of the position vector of the center of the scaling
322
+ * @param y y coordinate of the position vector of the center of the scaling
323
+ * @related transform ( )
324
+ * @related translate ( )
325
+ * @related rotate ( )
326
+ */
327
+ public void scale(float s, float x, float y)
328
+ {
329
+ scale(s, s, x, y);
330
+ }
331
+
332
+ /**
333
+ * Apply a scale to the matrix, given scaling factors and optionally a scaling center.
334
+ * @eexample RPoint_scale
335
+ * @usage Geometry
336
+ * @param sx the scaling coefficient over the x axis
337
+ * @param sy the scaling coefficient over the y axis
338
+ * @param p the position vector of the center of the scaling
339
+ * @related transform ( )
340
+ * @related translate ( )
341
+ * @related rotate ( )
342
+ */
343
+ public void scale(float sx, float sy, RPoint p)
344
+ {
345
+ scale(sx, sy, p.x, p.y);
346
+ }
347
+
348
+ /**
349
+ * Apply a scale to the matrix, given scaling factors and optionally a scaling center.
350
+ * @eexample RPoint_scale
351
+ * @usage Geometry
352
+ * @param s the scaling coefficient for a uniform scaling
353
+ * @param p the position vector of the center of the scaling
354
+ * @related transform ( )
355
+ * @related translate ( )
356
+ * @related rotate ( )
357
+ */
358
+ public void scale(float s, RPoint p)
359
+ {
360
+ scale(s, s, p.x, p.y);
361
+ }
362
+
363
+ public void scale(float s)
364
+ {
365
+ scale(s, s);
366
+ }
367
+
368
+ /**
369
+ * Use this to apply a skewing to the matrix.
370
+ * @eexample RMatrix_skewing
371
+ * @param angle skewing angle
372
+ * @usage Geometry
373
+ * @related rotate ( )
374
+ * @related scale ( )
375
+ * @related translate ( )
376
+ */
377
+ public void skewX(float angle)
378
+ {
379
+ apply(1, (float)Math.tan(angle), 0, 0, 1, 0);
380
+ }
381
+
382
+ public void skewY(float angle)
383
+ {
384
+ apply(1, 0, 0, (float)Math.tan(angle), 1, 0);
385
+ }
386
+
387
+ /**
388
+ * Use this to apply a shearing to the matrix.
389
+ * @eexample RMatrix_translate
390
+ * @param shx x coordinate shearing
391
+ * @param shy y coordinate shearing
392
+ * @usage Geometry
393
+ * @related rotate ( )
394
+ * @related scale ( )
395
+ * @related translate ( )
396
+ */
397
+ public void shear(float shx, float shy)
398
+ {
399
+ apply(1, -shx, 0, shy, 1, 0);
400
+ }
401
+ }
@@ -0,0 +1,420 @@
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
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ Geomerative is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with Geomerative. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ package geomerative ;
21
+ import processing.core.*;
22
+
23
+ /**
24
+ * RMesh is a reduced interface for creating, holding and drawing meshes. A mesh is a group of triangular strips (RStrip).
25
+ * @eexample RMesh
26
+ * @usage Geometry
27
+ * @related RStrip
28
+ * @extended
29
+ */
30
+ public class RMesh extends RGeomElem
31
+ {
32
+ /**
33
+ * @invisible
34
+ */
35
+ public int type = RGeomElem.MESH;
36
+
37
+ /**
38
+ * Array of RStrip objects holding the contours of the polygon.
39
+ * @eexample strips
40
+ * @related RStrip
41
+ * @related countStrips ( )
42
+ * @related addStrip ( )
43
+ */
44
+ public RStrip[] strips;
45
+ int currentStrip=0;
46
+ // ----------------------
47
+ // --- Public Methods ---
48
+ // ----------------------
49
+
50
+ /**
51
+ * Create a new empty mesh.
52
+ * @eexample createaMesh
53
+ */
54
+ public RMesh(){
55
+ strips = null;
56
+ type = RGeomElem.MESH;
57
+ }
58
+
59
+ /**
60
+ * Copy a mesh.
61
+ * @eexample createaMesh
62
+ * @param m the object of which to make a copy
63
+ */
64
+ public RMesh(RMesh m){
65
+ if(m == null){
66
+ return;
67
+ }
68
+
69
+ for(int i=0;i<m.countStrips();i++){
70
+ this.append(new RStrip(m.strips[i]));
71
+ }
72
+ type = RGeomElem.MESH;
73
+
74
+ setStyle(m);
75
+ }
76
+
77
+ /**
78
+ * Use this method to count the number of strips in the mesh.
79
+ * @eexample countStrips
80
+ * @return int, the number strips in the mesh
81
+ * @related addStrip ( )
82
+ */
83
+ public int countStrips(){
84
+ if(this.strips==null){
85
+ return 0;
86
+ }
87
+
88
+ return this.strips.length;
89
+ }
90
+
91
+ /**
92
+ * Add a new strip.
93
+ * @eexample addStrip
94
+ * @param s the strip to be added
95
+ * @related addPoint ( )
96
+ */
97
+ public void addStrip(RStrip s){
98
+ this.append(s);
99
+ }
100
+
101
+ public void addStrip(){
102
+ this.append(new RStrip());
103
+ }
104
+
105
+ /**
106
+ * Use this method to set the current strip to which append points.
107
+ * @param indStrip
108
+ * @eexample addStrip
109
+ * @related addPoint ( )
110
+ * @invisible
111
+ */
112
+ public void setCurrent(int indStrip){
113
+ this.currentStrip = indStrip;
114
+ }
115
+
116
+ /**
117
+ * Add a new point to the current strip.
118
+ * @eexample addPoint
119
+ * @param p the point to be added
120
+ * @related addStrip ( )
121
+ * @related setCurrent ( )
122
+ * @invisible
123
+ */
124
+ public void addPoint(RPoint p){
125
+ if (strips == null) {
126
+ this.append(new RStrip());
127
+ }
128
+ this.strips[currentStrip].append(p);
129
+ }
130
+
131
+ /**
132
+ * Add a new point to the current strip.
133
+ * @eexample addPoint
134
+ * @param x the x coordinate of the point to be added
135
+ * @param y the y coordinate of the point to be added
136
+ * @related addStrip ( )
137
+ * @related setCurrent ( )
138
+ * @invisible
139
+ */
140
+ public void addPoint(float x, float y){
141
+ if (strips == null) {
142
+ this.append(new RStrip());
143
+ }
144
+ this.strips[currentStrip].append(new RPoint(x,y));
145
+ }
146
+
147
+ /**
148
+ * Add a new point to the given strip.
149
+ * @eexample addPoint
150
+ * @param indStrip the index of the strip to which the point will be added
151
+ * @param p the point to be added
152
+ * @related addStrip ( )
153
+ * @related setCurrent ( )
154
+ * @invisible
155
+ */
156
+ public void addPoint(int indStrip, RPoint p){
157
+ if (strips == null) {
158
+ this.append(new RStrip());
159
+ }
160
+ this.strips[indStrip].append(p);
161
+ }
162
+
163
+ /**
164
+ * Add a new point to the given strip.
165
+ * @eexample addPoint
166
+ * @param indStrip the index of the strip to which the point will be added
167
+ * @param x the x coordinate of the point to be added
168
+ * @param y the y coordinate of the point to be added
169
+ * @related addStrip ( )
170
+ * @related setCurrent ( )
171
+ * @invisible
172
+ */
173
+ public void addPoint(int indStrip, float x, float y){
174
+ if (strips == null) {
175
+ this.append(new RStrip());
176
+ }
177
+ this.strips[indStrip].append(new RPoint(x,y));
178
+ }
179
+
180
+ /**
181
+ * Use this method to draw the mesh.
182
+ * @eexample drawMesh
183
+ * @param g PGraphics, the graphics object on which to draw the mesh
184
+ */
185
+ @Override
186
+ public void draw(PGraphics g){
187
+ for(int i=0;i<this.countStrips();i++){
188
+ g.beginShape(PConstants.TRIANGLE_STRIP);
189
+ if(this.style.texture != null)
190
+ {
191
+ g.texture(this.style.texture);
192
+ for (RPoint vertice : this.strips[i].vertices) {
193
+ float x = vertice.x;
194
+ float y = vertice.y;
195
+ /*
196
+ float u = (x - minx)/(maxx-minx) * this.style.texture.width;
197
+ float v = (y - miny)/(maxy-miny) * this.style.texture.height;
198
+ */
199
+ g.vertex(x, y, x, y);
200
+ }
201
+ }else{
202
+ for (RPoint vertice : this.strips[i].vertices) {
203
+ float x = vertice.x;
204
+ float y = vertice.y;
205
+ g.vertex(x, y);
206
+ }
207
+ }
208
+ g.endShape(PConstants.CLOSE);
209
+ }
210
+
211
+
212
+ }
213
+
214
+ @Override
215
+ public void draw(PApplet g){
216
+ for(int i=0;i<this.countStrips();i++){
217
+ g.beginShape(PConstants.TRIANGLE_STRIP);
218
+ if(this.style.texture != null)
219
+ {
220
+ g.texture(this.style.texture);
221
+ }
222
+ for (RPoint vertice : this.strips[i].vertices) {
223
+ g.vertex(vertice.x, vertice.y);
224
+ }
225
+ g.endShape(PConstants.CLOSE);
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Use this to get the vertices of the mesh. It returns the points as an array of RPoint.
231
+ * @eexample RMesh_getHandles
232
+ * @return RPoint[], the vertices returned in an array.
233
+ * */
234
+ @Override
235
+ public RPoint[] getHandles(){
236
+ int numStrips = countStrips();
237
+ if(numStrips == 0){
238
+ return null;
239
+ }
240
+
241
+ RPoint[] result=null;
242
+ RPoint[] newresult=null;
243
+ for(int i=0;i<numStrips;i++){
244
+ RPoint[] newPoints = strips[i].getHandles();
245
+ if(newPoints!=null){
246
+ if(result==null){
247
+ result = new RPoint[newPoints.length];
248
+ System.arraycopy(newPoints,0,result,0,newPoints.length);
249
+ }else{
250
+ newresult = new RPoint[result.length + newPoints.length];
251
+ System.arraycopy(result,0,newresult,0,result.length);
252
+ System.arraycopy(newPoints,0,newresult,result.length,newPoints.length);
253
+ result = newresult;
254
+ }
255
+ }
256
+ }
257
+ return result;
258
+ }
259
+
260
+ /**
261
+ * Use this to get the vertices of the mesh. It returns the points as an array of RPoint.
262
+ * @eexample RMesh_getPoints
263
+ * @return RPoint[], the vertices returned in an array.
264
+ * */
265
+ @Override
266
+ public RPoint[] getPoints(){
267
+ int numStrips = countStrips();
268
+ if(numStrips == 0){
269
+ return null;
270
+ }
271
+
272
+ RPoint[] result=null;
273
+ RPoint[] newresult=null;
274
+ for(int i=0;i<numStrips;i++){
275
+ RPoint[] newPoints = strips[i].getPoints();
276
+ if(newPoints!=null){
277
+ if(result==null){
278
+ result = new RPoint[newPoints.length];
279
+ System.arraycopy(newPoints,0,result,0,newPoints.length);
280
+ }else{
281
+ newresult = new RPoint[result.length + newPoints.length];
282
+ System.arraycopy(result,0,newresult,0,result.length);
283
+ System.arraycopy(newPoints,0,newresult,result.length,newPoints.length);
284
+ result = newresult;
285
+ }
286
+ }
287
+ }
288
+ return result;
289
+ }
290
+
291
+ @Override
292
+ public RPoint getPoint(float t){
293
+ PApplet.println("Feature not yet implemented for this class.");
294
+ return null;
295
+ }
296
+
297
+ @Override
298
+ public RPoint getTangent(float t){
299
+ PApplet.println("Feature not yet implemented for this class.");
300
+ return null;
301
+ }
302
+
303
+ @Override
304
+ public RPoint[] getTangents(){
305
+ PApplet.println("Feature not yet implemented for this class.");
306
+ return null;
307
+ }
308
+
309
+ @Override
310
+ public RPoint[][] getPointsInPaths(){
311
+ PApplet.println("Feature not yet implemented for this class.");
312
+ return null;
313
+ }
314
+
315
+ /**
316
+ *
317
+ * @return
318
+ */
319
+ @Override
320
+ public RPoint[][] getHandlesInPaths(){
321
+ PApplet.println("Feature not yet implemented for this class.");
322
+ return null;
323
+ }
324
+
325
+ /**
326
+ *
327
+ * @return
328
+ */
329
+ @Override
330
+ public RPoint[][] getTangentsInPaths(){
331
+ PApplet.println("Feature not yet implemented for this class.");
332
+ return null;
333
+ }
334
+
335
+ /**
336
+ *
337
+ * @param p
338
+ * @return
339
+ */
340
+ @Override
341
+ public boolean contains(RPoint p){
342
+ PApplet.println("Feature not yet implemented for this class.");
343
+ return false;
344
+ }
345
+
346
+ /**
347
+ * Use this method to get the type of element this is.
348
+ * @eexample RMesh_getType
349
+ * @return int, will allways return RGeomElem.MESH
350
+ */
351
+ @Override
352
+ public int getType(){
353
+ return type;
354
+ }
355
+
356
+ /**
357
+ * Use this method to transform the mesh.
358
+ * @eexample transformMesh
359
+ * @param m RMatrix, the matrix of the affine transformation to apply to the mesh
360
+ */
361
+ @Override
362
+ public void transform(RMatrix m){
363
+ int numStrips = countStrips();
364
+ if(numStrips!=0){
365
+ for(int i=0;i<numStrips;i++){
366
+ strips[i].transform(m);
367
+ }
368
+ }
369
+ }
370
+
371
+ /**
372
+ * @return
373
+ * @invisible
374
+ */
375
+ @Override
376
+ public RMesh toMesh(){
377
+ return this;
378
+ }
379
+
380
+ /**
381
+ * @return
382
+ * @invisible
383
+ */
384
+ @Override
385
+ public RPolygon toPolygon() throws RuntimeException{
386
+ throw new RuntimeException("Transforming a Mesh to a Polygon is not yet implemented.");
387
+ }
388
+
389
+ /**
390
+ * @return
391
+ * @invisible
392
+ */
393
+ @Override
394
+ public RShape toShape() throws RuntimeException{
395
+ throw new RuntimeException("Transforming a Mesh to a Shape is not yet implemented.");
396
+ }
397
+
398
+ /**
399
+ * Remove all of the points. Creates an empty polygon.
400
+ */
401
+ void clear(){
402
+ this.strips = null;
403
+ }
404
+
405
+ final void append(RStrip nextstrip)
406
+ {
407
+ RStrip[] newstrips;
408
+ if(strips==null){
409
+ newstrips = new RStrip[1];
410
+ newstrips[0] = nextstrip;
411
+ currentStrip = 0;
412
+ }else{
413
+ newstrips = new RStrip[this.strips.length+1];
414
+ System.arraycopy(this.strips,0,newstrips,0,this.strips.length);
415
+ newstrips[this.strips.length]=nextstrip;
416
+ currentStrip++;
417
+ }
418
+ this.strips=newstrips;
419
+ }
420
+ }