geomerative 0.2.0-java → 0.3.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +8 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +4 -0
- data/COPYING.md +17 -0
- data/Gemfile +8 -1
- data/README.md +5 -1
- data/examples/README.md +1 -7
- data/examples/Rakefile +30 -0
- data/examples/data/ruby.svg +16 -0
- data/examples/f_agent.rb +30 -0
- data/examples/font_agent.rb +24 -0
- data/examples/hello_polygonize.rb +1 -1
- data/examples/hello_svg_to_pdf.rb +2 -2
- data/examples/hello_world.rb +1 -1
- data/examples/jruby_merge.rb +94 -0
- data/examples/physics_type.rb +1 -1
- data/examples/rotate_first_letter.rb +3 -4
- data/examples/typo_deform.rb +68 -0
- data/examples/typo_extra_bright.rb +62 -0
- data/examples/typo_merge.rb +94 -0
- data/geomerative.gemspec +2 -3
- data/lib/geomerative/version.rb +1 -1
- data/pom.rb +47 -0
- data/pom.xml +35 -65
- data/src/geomerative/FastRClip.java +1 -1
- data/src/geomerative/RCommand.java +1877 -1741
- data/src/geomerative/RContour.java +8 -1
- data/src/geomerative/RFont.java +8 -5
- data/src/geomerative/RG.java +8 -3
- data/src/geomerative/RGeomElem.java +8 -9
- data/src/geomerative/RGroup.java +50 -28
- data/src/geomerative/RMatrix.java +53 -57
- data/src/geomerative/RMesh.java +8 -3
- data/src/geomerative/RPath.java +34 -29
- data/src/geomerative/RPoint.java +408 -408
- data/src/geomerative/RPolygon.java +7 -3
- data/src/geomerative/RSVG.java +13 -10
- data/src/geomerative/RShape.java +18 -11
- data/src/geomerative/RStrip.java +5 -1
- data/src/geomerative/RStyle.java +15 -11
- metadata +17 -18
data/src/geomerative/RMesh.java
CHANGED
@@ -18,7 +18,12 @@
|
|
18
18
|
*/
|
19
19
|
|
20
20
|
package geomerative ;
|
21
|
-
|
21
|
+
|
22
|
+
|
23
|
+
import processing.core.PApplet;
|
24
|
+
import processing.core.PConstants;
|
25
|
+
import processing.core.PGraphics;
|
26
|
+
|
22
27
|
|
23
28
|
/**
|
24
29
|
* RMesh is a reduced interface for creating, holding and drawing meshes. A mesh is a group of triangular strips (RStrip).
|
@@ -239,7 +244,7 @@ public class RMesh extends RGeomElem
|
|
239
244
|
}
|
240
245
|
|
241
246
|
RPoint[] result=null;
|
242
|
-
RPoint[] newresult
|
247
|
+
RPoint[] newresult;
|
243
248
|
for(int i=0;i<numStrips;i++){
|
244
249
|
RPoint[] newPoints = strips[i].getHandles();
|
245
250
|
if(newPoints!=null){
|
@@ -270,7 +275,7 @@ public class RMesh extends RGeomElem
|
|
270
275
|
}
|
271
276
|
|
272
277
|
RPoint[] result=null;
|
273
|
-
RPoint[] newresult
|
278
|
+
RPoint[] newresult;
|
274
279
|
for(int i=0;i<numStrips;i++){
|
275
280
|
RPoint[] newPoints = strips[i].getPoints();
|
276
281
|
if(newPoints!=null){
|
data/src/geomerative/RPath.java
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
|
3
3
|
*
|
4
|
-
|
4
|
+
* This file is part of Geomerative.
|
5
5
|
*
|
6
6
|
* Geomerative is free software: you can redistribute it and/or modify it under
|
7
7
|
* the terms of the GNU General Public License as published by the Free Software
|
@@ -18,7 +18,10 @@
|
|
18
18
|
*/
|
19
19
|
package geomerative;
|
20
20
|
|
21
|
-
import processing.core.*;
|
21
|
+
//import processing.core.*;
|
22
|
+
import processing.core.PApplet;
|
23
|
+
import processing.core.PConstants;
|
24
|
+
import processing.core.PGraphics;
|
22
25
|
|
23
26
|
/**
|
24
27
|
* RPath is a reduced interface for creating, holding and drawing contours.
|
@@ -152,14 +155,14 @@ public class RPath extends RGeomElem {
|
|
152
155
|
*
|
153
156
|
* @eexample getHandles
|
154
157
|
* @return RPoint[], the start, control and end points returned in an array.
|
155
|
-
|
158
|
+
*
|
156
159
|
*/
|
157
160
|
@Override
|
158
161
|
public RPoint[] getHandles() {
|
159
162
|
int numCommands = countCommands();
|
160
163
|
|
161
164
|
RPoint[] result = null;
|
162
|
-
RPoint[] newresult
|
165
|
+
RPoint[] newresult;
|
163
166
|
for (int i = 0; i < numCommands; i++) {
|
164
167
|
RPoint[] newPoints = commands[i].getHandles();
|
165
168
|
if (newPoints != null) {
|
@@ -187,7 +190,7 @@ public class RPath extends RGeomElem {
|
|
187
190
|
*
|
188
191
|
* @eexample getPoints
|
189
192
|
* @return RPoint[], the vertices returned in an array.
|
190
|
-
|
193
|
+
*
|
191
194
|
*/
|
192
195
|
@Override
|
193
196
|
public RPoint[] getPoints() {
|
@@ -196,11 +199,11 @@ public class RPath extends RGeomElem {
|
|
196
199
|
return null;
|
197
200
|
}
|
198
201
|
|
199
|
-
|
202
|
+
// Add the curve points of each command
|
200
203
|
// First set the accumulated offset to the value of the inital offset
|
201
204
|
RCommand.segmentAccOffset = RCommand.segmentOffset;
|
202
205
|
RPoint[] result = null;
|
203
|
-
RPoint[] newresult
|
206
|
+
RPoint[] newresult;
|
204
207
|
for (int i = 0; i < numCommands; i++) {
|
205
208
|
RPoint[] newPoints = commands[i].getPoints(false);
|
206
209
|
if (newPoints != null) {
|
@@ -208,7 +211,7 @@ public class RPath extends RGeomElem {
|
|
208
211
|
result = new RPoint[newPoints.length];
|
209
212
|
System.arraycopy(newPoints, 0, result, 0, newPoints.length);
|
210
213
|
} else {
|
211
|
-
|
214
|
+
// Check for overlapping
|
212
215
|
// Overlapping happens when the last point of the last command
|
213
216
|
// is the same as the first point of the current command
|
214
217
|
RPoint lastp = result[result.length - 1];
|
@@ -224,12 +227,13 @@ public class RPath extends RGeomElem {
|
|
224
227
|
}
|
225
228
|
}
|
226
229
|
}
|
227
|
-
|
228
230
|
// Always add last point
|
231
|
+
if (result == null) {
|
232
|
+
return result;
|
233
|
+
}
|
229
234
|
newresult = new RPoint[result.length + 1];
|
230
235
|
System.arraycopy(result, 0, newresult, 0, result.length);
|
231
236
|
newresult[newresult.length - 1] = new RPoint(commands[numCommands - 1].endPoint);
|
232
|
-
|
233
237
|
return newresult;
|
234
238
|
}
|
235
239
|
|
@@ -239,7 +243,7 @@ public class RPath extends RGeomElem {
|
|
239
243
|
*
|
240
244
|
* @eexample RGroup_getPoints
|
241
245
|
* @return RPoint[], the points returned in an array.
|
242
|
-
|
246
|
+
*
|
243
247
|
*/
|
244
248
|
@Override
|
245
249
|
public RPoint[][] getPointsInPaths() {
|
@@ -253,7 +257,7 @@ public class RPath extends RGeomElem {
|
|
253
257
|
*
|
254
258
|
* @eexample RGroup_getHandles
|
255
259
|
* @return RPoint[], the handles returned in an array.
|
256
|
-
|
260
|
+
*
|
257
261
|
*/
|
258
262
|
@Override
|
259
263
|
public RPoint[][] getHandlesInPaths() {
|
@@ -267,7 +271,7 @@ public class RPath extends RGeomElem {
|
|
267
271
|
*
|
268
272
|
* @eexample RGroup_getTangents
|
269
273
|
* @return RPoint[], the tangents returned in an array.
|
270
|
-
|
274
|
+
*
|
271
275
|
*/
|
272
276
|
@Override
|
273
277
|
public RPoint[][] getTangentsInPaths() {
|
@@ -291,7 +295,7 @@ public class RPath extends RGeomElem {
|
|
291
295
|
*
|
292
296
|
* @eexample getTangents
|
293
297
|
* @return RPoint[], the tangent vectors returned in an array.
|
294
|
-
|
298
|
+
*
|
295
299
|
*/
|
296
300
|
@Override
|
297
301
|
public RPoint[] getTangents() {
|
@@ -301,7 +305,7 @@ public class RPath extends RGeomElem {
|
|
301
305
|
}
|
302
306
|
|
303
307
|
RPoint[] result = null;
|
304
|
-
RPoint[] newresult
|
308
|
+
RPoint[] newresult;
|
305
309
|
for (int i = 0; i < numCommands; i++) {
|
306
310
|
RPoint[] newTangents = commands[i].getTangents();
|
307
311
|
if (newTangents != null) {
|
@@ -328,7 +332,7 @@ public class RPath extends RGeomElem {
|
|
328
332
|
*
|
329
333
|
* @param other
|
330
334
|
* @return RPoint[], the intersection points returned in an array.
|
331
|
-
|
335
|
+
*
|
332
336
|
*/
|
333
337
|
public RPoint[] intersectionPoints(RCommand other) {
|
334
338
|
int numCommands = countCommands();
|
@@ -337,7 +341,7 @@ public class RPath extends RGeomElem {
|
|
337
341
|
}
|
338
342
|
|
339
343
|
RPoint[] result = null;
|
340
|
-
RPoint[] newresult
|
344
|
+
RPoint[] newresult;
|
341
345
|
for (int i = 0; i < numCommands; i++) {
|
342
346
|
RPoint[] newPoints = commands[i].intersectionPoints(other);
|
343
347
|
if (newPoints != null) {
|
@@ -361,7 +365,7 @@ public class RPath extends RGeomElem {
|
|
361
365
|
*
|
362
366
|
* @param other
|
363
367
|
* @return RPoint[], the intersection points returned in an array.
|
364
|
-
|
368
|
+
*
|
365
369
|
*/
|
366
370
|
public RPoint[] intersectionPoints(RPath other) {
|
367
371
|
int numCommands = countCommands();
|
@@ -372,7 +376,7 @@ public class RPath extends RGeomElem {
|
|
372
376
|
}
|
373
377
|
|
374
378
|
RPoint[] result = null;
|
375
|
-
RPoint[] newresult
|
379
|
+
RPoint[] newresult;
|
376
380
|
|
377
381
|
for (int j = 0; j < numOtherCommands; j++) {
|
378
382
|
for (int i = 0; i < numCommands; i++) {
|
@@ -400,7 +404,7 @@ public class RPath extends RGeomElem {
|
|
400
404
|
*
|
401
405
|
* @param other
|
402
406
|
* @return RPoint[], the intersection points returned in an array.
|
403
|
-
|
407
|
+
*
|
404
408
|
*/
|
405
409
|
public RClosest closestPoints(RCommand other) {
|
406
410
|
int numCommands = countCommands();
|
@@ -428,7 +432,7 @@ public class RPath extends RGeomElem {
|
|
428
432
|
*
|
429
433
|
* @param other
|
430
434
|
* @return RPoint[], the intersection points returned in an array.
|
431
|
-
|
435
|
+
*
|
432
436
|
*/
|
433
437
|
public RClosest closestPoints(RPath other) {
|
434
438
|
int numCommands = countCommands();
|
@@ -461,7 +465,7 @@ public class RPath extends RGeomElem {
|
|
461
465
|
* @param t the parameter of advancement on the curve. t must have values
|
462
466
|
* between 0 and 1.
|
463
467
|
* @return RPoint, the vertice returned.
|
464
|
-
|
468
|
+
*
|
465
469
|
*/
|
466
470
|
@Override
|
467
471
|
public RPoint getPoint(float t) {
|
@@ -492,7 +496,7 @@ public class RPath extends RGeomElem {
|
|
492
496
|
* @param t float, the parameter of advancement on the curve. t must have
|
493
497
|
* values between 0 and 1.
|
494
498
|
* @return RPoint, the vertice returned.
|
495
|
-
|
499
|
+
*
|
496
500
|
*/
|
497
501
|
@Override
|
498
502
|
public RPoint getTangent(float t) {
|
@@ -540,7 +544,7 @@ public class RPath extends RGeomElem {
|
|
540
544
|
*
|
541
545
|
* @param p the point for which to test containement..
|
542
546
|
* @return boolean, true if the point is in the path.
|
543
|
-
|
547
|
+
*
|
544
548
|
*/
|
545
549
|
@Override
|
546
550
|
public boolean contains(RPoint p) {
|
@@ -567,7 +571,8 @@ public class RPath extends RGeomElem {
|
|
567
571
|
}
|
568
572
|
|
569
573
|
int nvert = verts.length;
|
570
|
-
int i
|
574
|
+
int i;
|
575
|
+
int j;
|
571
576
|
boolean c = false;
|
572
577
|
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
|
573
578
|
if (((verts[i].y > testy) != (verts[j].y > testy))
|
@@ -584,7 +589,7 @@ public class RPath extends RGeomElem {
|
|
584
589
|
* @eexample insertHandle
|
585
590
|
* @param t float, the parameter of advancement on the curve. t must have
|
586
591
|
* values between 0 and 1.
|
587
|
-
|
592
|
+
*
|
588
593
|
*/
|
589
594
|
public void insertHandle(float t) {
|
590
595
|
if ((t == 0F) || (t == 1F)) {
|
@@ -620,7 +625,7 @@ public class RPath extends RGeomElem {
|
|
620
625
|
* @eexample insertHandleInPaths
|
621
626
|
* @param t float, the parameter of advancement on the curve. t must have
|
622
627
|
* values between 0 and 1.
|
623
|
-
|
628
|
+
*
|
624
629
|
*/
|
625
630
|
public void insertHandleInPaths(float t) {
|
626
631
|
if ((t == 0F) || (t == 1F)) {
|
@@ -657,7 +662,7 @@ public class RPath extends RGeomElem {
|
|
657
662
|
* @param t float, the parameter of advancement on the curve. t must have
|
658
663
|
* values between 0 and 1.
|
659
664
|
* @return RPath[], an array of two RPath.
|
660
|
-
|
665
|
+
*
|
661
666
|
*/
|
662
667
|
public RPath[] split(float t) {
|
663
668
|
RPath[] result = new RPath[2];
|
@@ -973,7 +978,7 @@ public class RPath extends RGeomElem {
|
|
973
978
|
* @param m RMatrix, the matrix defining the affine transformation
|
974
979
|
* @related draw ( )
|
975
980
|
*/
|
976
|
-
|
981
|
+
// OPT: not transform the EndPoint since it's equal to the next StartPoint
|
977
982
|
/*
|
978
983
|
public void transform(RMatrix m){
|
979
984
|
RPoint[] ps = getHandles();
|
data/src/geomerative/RPoint.java
CHANGED
@@ -1,419 +1,419 @@
|
|
1
1
|
/**
|
2
|
-
|
3
|
-
|
2
|
+
* Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
|
3
|
+
*
|
4
4
|
This file is part of Geomerative.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
*/
|
19
|
-
|
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
|
+
*/
|
20
19
|
package geomerative;
|
21
20
|
|
22
21
|
/**
|
23
|
-
* RPoint is a very simple interface for creating, holding and drawing 2D
|
22
|
+
* RPoint is a very simple interface for creating, holding and drawing 2D
|
23
|
+
* points.
|
24
|
+
*
|
24
25
|
* @eexample RPoint
|
25
26
|
* @usage Geometry
|
26
27
|
* @related x
|
27
28
|
* @related y
|
28
29
|
*/
|
29
|
-
public class RPoint
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
float
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
float
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
}
|
30
|
+
public class RPoint {
|
31
|
+
|
32
|
+
/**
|
33
|
+
* The x coordinate of the point.
|
34
|
+
*
|
35
|
+
* @eexample RPoint_x
|
36
|
+
* @usage Geometry
|
37
|
+
* @related y
|
38
|
+
*/
|
39
|
+
public float x;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* The y coordinate of the point.
|
43
|
+
*
|
44
|
+
* @eexample RPoint_y
|
45
|
+
* @usage Geometry
|
46
|
+
* @related x
|
47
|
+
*/
|
48
|
+
public float y;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Create a new point, given the coordinates.
|
52
|
+
*
|
53
|
+
* @eexample RPoint_constructor
|
54
|
+
* @usage Geometry
|
55
|
+
* @param x the x coordinate of the new point
|
56
|
+
* @param y the y coordinate of the new point
|
57
|
+
* @related x
|
58
|
+
* @related y
|
59
|
+
*/
|
60
|
+
public RPoint(float x, float y) {
|
61
|
+
this.x = x;
|
62
|
+
this.y = y;
|
63
|
+
}
|
64
|
+
|
65
|
+
public RPoint(double x, double y) {
|
66
|
+
this.x = (float) x;
|
67
|
+
this.y = (float) y;
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Create a new point at (0, 0).
|
72
|
+
*
|
73
|
+
* @eexample RPoint_constructor
|
74
|
+
* @usage Geometry
|
75
|
+
* @related x
|
76
|
+
* @related y
|
77
|
+
*/
|
78
|
+
public RPoint() {
|
79
|
+
x = 0;
|
80
|
+
y = 0;
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Copy a point.
|
85
|
+
*
|
86
|
+
* @eexample RPoint_constructor
|
87
|
+
* @usage Geometry
|
88
|
+
* @param p the point we wish to make a copy of
|
89
|
+
* @related x
|
90
|
+
* @related y
|
91
|
+
*/
|
92
|
+
public RPoint(RPoint p) {
|
93
|
+
this.x = p.x;
|
94
|
+
this.y = p.y;
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* @invisible
|
99
|
+
*/
|
100
|
+
float getX() {
|
101
|
+
return this.x;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @invisible
|
106
|
+
*/
|
107
|
+
float getY() {
|
108
|
+
return this.y;
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* @invisible
|
113
|
+
*/
|
114
|
+
void setLocation(float nx, float ny) {
|
115
|
+
this.x = nx;
|
116
|
+
this.y = ny;
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Use this to apply a transformation to the point.
|
121
|
+
*
|
122
|
+
* @eexample RPoint_transform
|
123
|
+
* @usage Geometry
|
124
|
+
* @param m the transformation matrix to be applied
|
125
|
+
* @related translate ( )
|
126
|
+
* @related rotate ( )
|
127
|
+
* @related scale ( )
|
128
|
+
*/
|
129
|
+
public void transform(RMatrix m) {
|
130
|
+
float tempx = m.m00 * x + m.m01 * y + m.m02;
|
131
|
+
float tempy = m.m10 * x + m.m11 * y + m.m12;
|
132
|
+
|
133
|
+
x = tempx;
|
134
|
+
y = tempy;
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Apply a translation to the point.
|
139
|
+
*
|
140
|
+
* @eexample RPoint_translate
|
141
|
+
* @usage Geometry
|
142
|
+
* @param tx the coefficient of x translation
|
143
|
+
* @param ty the coefficient of y translation
|
144
|
+
* @related transform ( )
|
145
|
+
* @related rotate ( )
|
146
|
+
* @related scale ( )
|
147
|
+
*/
|
148
|
+
public void translate(float tx, float ty) {
|
149
|
+
x += tx;
|
150
|
+
y += ty;
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Apply a translation to the point.
|
155
|
+
*
|
156
|
+
* @eexample RPoint_translate
|
157
|
+
* @usage Geometry
|
158
|
+
* @param t the translation vector to be applied
|
159
|
+
* @related transform ( )
|
160
|
+
* @related rotate ( )
|
161
|
+
* @related scale ( )
|
162
|
+
*/
|
163
|
+
public void translate(RPoint t) {
|
164
|
+
x += t.x;
|
165
|
+
y += t.y;
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Apply a rotation to the point, given the angle and optionally the
|
170
|
+
* coordinates of the center of rotation.
|
171
|
+
*
|
172
|
+
* @eexample RPoint_rotate
|
173
|
+
* @usage Geometry
|
174
|
+
* @param angle the angle of rotation to be applied
|
175
|
+
* @param vx the x coordinate of the center of rotation
|
176
|
+
* @param vy the y coordinate of the center of rotation
|
177
|
+
* @related transform ( )
|
178
|
+
* @related translate ( )
|
179
|
+
* @related scale ( )
|
180
|
+
*/
|
181
|
+
public void rotate(float angle, float vx, float vy) {
|
182
|
+
float c = (float) Math.cos(angle);
|
183
|
+
float s = (float) Math.sin(angle);
|
184
|
+
|
185
|
+
x -= vx;
|
186
|
+
y -= vy;
|
187
|
+
|
188
|
+
float tempx = x;
|
189
|
+
float tempy = y;
|
190
|
+
|
191
|
+
x = tempx * c - tempy * s;
|
192
|
+
y = tempx * s + tempy * c;
|
193
|
+
|
194
|
+
x += vx;
|
195
|
+
y += vy;
|
196
|
+
}
|
197
|
+
|
198
|
+
public void rotate(float angle) {
|
199
|
+
float c = (float) Math.cos(angle);
|
200
|
+
float s = (float) Math.sin(angle);
|
201
|
+
|
202
|
+
float tempx = x;
|
203
|
+
float tempy = y;
|
204
|
+
|
205
|
+
x = tempx * c - tempy * s;
|
206
|
+
y = tempx * s + tempy * c;
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Apply a rotation to the point, given the angle and optionally the point
|
211
|
+
* of the center of rotation.
|
212
|
+
*
|
213
|
+
* @eexample RPoint_rotate
|
214
|
+
* @usage Geometry
|
215
|
+
* @param angle the angle of rotation to be applied
|
216
|
+
* @param v the position vector of the center of rotation
|
217
|
+
* @related transform ( )
|
218
|
+
* @related translate ( )
|
219
|
+
* @related scale ( )
|
220
|
+
*/
|
221
|
+
public void rotate(float angle, RPoint v) {
|
222
|
+
float c = (float) Math.cos(angle);
|
223
|
+
float s = (float) Math.sin(angle);
|
224
|
+
|
225
|
+
x -= v.x;
|
226
|
+
y -= v.y;
|
227
|
+
|
228
|
+
float tempx = x;
|
229
|
+
float tempy = y;
|
230
|
+
|
231
|
+
x = tempx * c - tempy * s;
|
232
|
+
y = tempx * s + tempy * c;
|
233
|
+
|
234
|
+
x += v.x;
|
235
|
+
y += v.y;
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* Apply a scaling to the point, given the scaling factors.
|
240
|
+
*
|
241
|
+
* @eexample RPoint_scale
|
242
|
+
* @usage Geometry
|
243
|
+
* @param sx the scaling coefficient over the x axis
|
244
|
+
* @param sy the scaling coefficient over the y axis
|
245
|
+
* @related transform ( )
|
246
|
+
* @related translate ( )
|
247
|
+
* @related rotate ( )
|
248
|
+
*/
|
249
|
+
public void scale(float sx, float sy) {
|
250
|
+
x *= sx;
|
251
|
+
y *= sy;
|
252
|
+
}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Apply a scaling to the point, given a scaling factor.
|
256
|
+
*
|
257
|
+
* @eexample RPoint_scale
|
258
|
+
* @usage Geometry
|
259
|
+
* @param s the scaling coefficient for a uniform scaling
|
260
|
+
* @related transform ( )
|
261
|
+
* @related translate ( )
|
262
|
+
* @related rotate ( )
|
263
|
+
*/
|
264
|
+
public void scale(float s) {
|
265
|
+
x *= s;
|
266
|
+
y *= s;
|
267
|
+
}
|
268
|
+
|
269
|
+
/**
|
270
|
+
* Apply a scaling to the point, given a scaling vector.
|
271
|
+
*
|
272
|
+
* @eexample RPoint_scale
|
273
|
+
* @usage Geometry
|
274
|
+
* @param s the scaling vector
|
275
|
+
* @related transform ( )
|
276
|
+
* @related translate ( )
|
277
|
+
* @related rotate ( )
|
278
|
+
*/
|
279
|
+
public void scale(RPoint s) {
|
280
|
+
x *= s.x;
|
281
|
+
y *= s.y;
|
282
|
+
}
|
283
|
+
|
284
|
+
/**
|
285
|
+
* Use this to normalize the point. This means that after applying, it's
|
286
|
+
* norm will be equal to 1.
|
287
|
+
*
|
288
|
+
* @eexample RPoint_normalize
|
289
|
+
* @usage Geometry
|
290
|
+
* @related transform ( )
|
291
|
+
* @related translate ( )
|
292
|
+
* @related rotate ( )
|
293
|
+
* @related scale ( )
|
294
|
+
*/
|
295
|
+
public void normalize() {
|
296
|
+
float norma = norm();
|
297
|
+
if (norma != 0) {
|
298
|
+
scale(1 / norma);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Use this to subtract a vector from this point.
|
304
|
+
*
|
305
|
+
* @eexample RPoint_sub
|
306
|
+
* @usage Geometry
|
307
|
+
* @param p the vector to substract
|
308
|
+
* @related add ( )
|
309
|
+
* @related mult ( )
|
310
|
+
* @related cross ( )
|
311
|
+
*/
|
312
|
+
public void sub(RPoint p) {
|
313
|
+
x -= p.x;
|
314
|
+
y -= p.y;
|
315
|
+
}
|
316
|
+
|
317
|
+
/**
|
318
|
+
* Use this to add a vector to this point.
|
319
|
+
*
|
320
|
+
* @eexample RPoint_add
|
321
|
+
* @usage Geometry
|
322
|
+
* @param p the vector to add
|
323
|
+
* @related sub ( )
|
324
|
+
* @related mult ( )
|
325
|
+
* @related cross ( )
|
326
|
+
*/
|
327
|
+
public void add(RPoint p) {
|
328
|
+
x += p.x;
|
329
|
+
y += p.y;
|
330
|
+
}
|
331
|
+
|
332
|
+
/**
|
333
|
+
* Use this to multiply a vector to this point. This returns a float
|
334
|
+
* corresponding to the scalar product of both vectors.
|
335
|
+
*
|
336
|
+
* @eexample RPoint_mult
|
337
|
+
* @usage Geometry
|
338
|
+
* @param p the vector to multiply
|
339
|
+
* @return float, the result of the scalar product
|
340
|
+
* @related add ( )
|
341
|
+
* @related sub ( )
|
342
|
+
* @related cross ( )
|
343
|
+
*/
|
344
|
+
public float mult(RPoint p) {
|
345
|
+
return (x * p.x + y * p.y);
|
346
|
+
}
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Use this to perform a cross product of the point with another point. This
|
350
|
+
* returns a RPoint corresponding to the cross product of both vectors.
|
351
|
+
*
|
352
|
+
* @eexample RPoint_cross
|
353
|
+
* @usage Geometry
|
354
|
+
* @param p the vector to perform the cross product with
|
355
|
+
* @return RPoint, the resulting vector of the cross product
|
356
|
+
* @related add ( )
|
357
|
+
* @related sub ( )
|
358
|
+
* @related mult ( )
|
359
|
+
*/
|
360
|
+
public RPoint cross(RPoint p) {
|
361
|
+
return new RPoint(x * p.y - p.x * y, y * p.x - p.y * x);
|
362
|
+
}
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Use this to obtain the norm of the point.
|
366
|
+
*
|
367
|
+
* @eexample RPoint_norm
|
368
|
+
* @usage Geometry
|
369
|
+
* @return float, the norm of the point
|
370
|
+
* @related angle ( )
|
371
|
+
*/
|
372
|
+
public float norm() {
|
373
|
+
return (float) Math.sqrt(mult(this));
|
374
|
+
}
|
375
|
+
|
376
|
+
/**
|
377
|
+
* Use this to obtain the square norm of the point.
|
378
|
+
*
|
379
|
+
* @eexample RPoint_norm
|
380
|
+
* @usage Geometry
|
381
|
+
* @return float, the norm of the point
|
382
|
+
* @related angle ( )
|
383
|
+
*/
|
384
|
+
public float sqrnorm() {
|
385
|
+
return (float) mult(this);
|
386
|
+
}
|
387
|
+
|
388
|
+
/**
|
389
|
+
* Use this to obtain the angle between the vector and another vector
|
390
|
+
*
|
391
|
+
* @eexample RPoint_angle
|
392
|
+
* @usage Geometry
|
393
|
+
* @param p the vector relative to which we want to evaluate the angle
|
394
|
+
* @return float, the angle between the two vectors
|
395
|
+
* @related norm ( )
|
396
|
+
*/
|
397
|
+
public float angle(RPoint p) {
|
398
|
+
float normp = p.norm();
|
399
|
+
float normthis = norm();
|
400
|
+
return (float) Math.acos(mult(p) / (normp * normthis));
|
401
|
+
}
|
402
|
+
|
403
|
+
/**
|
404
|
+
* Use this to obtain the distance between the vector and another vector
|
405
|
+
*
|
406
|
+
* @eexample RPoint_dist
|
407
|
+
* @usage Geometry
|
408
|
+
* @param p the vector relative to which we want to evaluate the distance
|
409
|
+
* @return float, the distance between the two vectors
|
410
|
+
* @related norm ( )
|
411
|
+
*/
|
412
|
+
public float dist(RPoint p) {
|
413
|
+
return (float) Math.hypot(p.x - this.x, p.y - this.y);
|
414
|
+
}
|
415
|
+
|
416
|
+
public void print() {
|
417
|
+
System.out.print("(" + x + "," + y + ")\n");
|
418
|
+
}
|
419
419
|
}
|