geomerative 1.1.0-java → 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +1 -1
- data/CHANGELOG.md +3 -0
- data/COPYING.md +1 -1
- data/README.md +0 -1
- data/Rakefile +2 -15
- data/docs/_includes/header.html +6 -6
- data/docs/_includes/icon-github.svg +3 -1
- data/docs/_includes/icon-twitter.svg +3 -1
- data/docs/_includes/navigation.html +18 -18
- data/docs/_sass/_base.scss +79 -79
- data/docs/_sass/_layout.scss +137 -137
- data/docs/_sass/_syntax-highlighting.scss +64 -64
- data/docs/index.html +18 -18
- data/examples/data/bot1.svg +1 -1
- data/examples/data/lion.svg +156 -156
- data/examples/data/ruby.svg +1 -1
- data/geomerative.gemspec +1 -2
- data/lib/geomerative/version.rb +1 -1
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.rb +14 -13
- data/pom.xml +14 -13
- data/src/geomerative/FastRClip.java +2149 -2156
- data/src/geomerative/RClip.java +2237 -2539
- data/src/geomerative/RClosest.java +33 -31
- data/src/geomerative/RCommand.java +1750 -1758
- data/src/geomerative/RContour.java +290 -292
- data/src/geomerative/RFont.java +277 -246
- data/src/geomerative/RG.java +722 -727
- data/src/geomerative/RGeomElem.java +967 -960
- data/src/geomerative/RGroup.java +508 -467
- data/src/geomerative/RMatrix.java +304 -289
- data/src/geomerative/RMesh.java +241 -229
- data/src/geomerative/RPath.java +924 -925
- data/src/geomerative/RPoint.java +391 -391
- data/src/geomerative/RPolygon.java +998 -988
- data/src/geomerative/RRectangle.java +43 -52
- data/src/geomerative/RSVG.java +480 -516
- data/src/geomerative/RShape.java +1767 -1777
- data/src/geomerative/RStrip.java +173 -176
- data/src/geomerative/RStyle.java +197 -194
- data/src/org/apache/batik/svggen/font/Font.java +141 -142
- data/src/org/apache/batik/svggen/font/Glyph.java +102 -71
- data/src/org/apache/batik/svggen/font/Point.java +12 -12
- data/src/org/apache/batik/svggen/font/RandomAccessFileEmulator.java +14 -12
- data/src/org/apache/batik/svggen/font/table/ClassDef.java +12 -12
- data/src/org/apache/batik/svggen/font/table/ClassDefFormat1.java +27 -24
- data/src/org/apache/batik/svggen/font/table/ClassDefFormat2.java +20 -17
- data/src/org/apache/batik/svggen/font/table/CmapFormat.java +43 -43
- data/src/org/apache/batik/svggen/font/table/CmapFormat0.java +33 -26
- data/src/org/apache/batik/svggen/font/table/CmapFormat2.java +25 -20
- data/src/org/apache/batik/svggen/font/table/CmapFormat4.java +106 -96
- data/src/org/apache/batik/svggen/font/table/CmapFormat6.java +36 -32
- data/src/org/apache/batik/svggen/font/table/CmapIndexEntry.java +69 -49
- data/src/org/apache/batik/svggen/font/table/CmapTable.java +50 -50
- data/src/org/apache/batik/svggen/font/table/Coverage.java +19 -19
- data/src/org/apache/batik/svggen/font/table/CoverageFormat1.java +30 -27
- data/src/org/apache/batik/svggen/font/table/CoverageFormat2.java +26 -24
- data/src/org/apache/batik/svggen/font/table/CvtTable.java +16 -16
- data/src/org/apache/batik/svggen/font/table/Device.java +32 -32
- data/src/org/apache/batik/svggen/font/table/DirectoryEntry.java +39 -39
- data/src/org/apache/batik/svggen/font/table/Feature.java +26 -23
- data/src/org/apache/batik/svggen/font/table/FeatureList.java +37 -35
- data/src/org/apache/batik/svggen/font/table/FeatureRecord.java +22 -22
- data/src/org/apache/batik/svggen/font/table/FeatureTags.java +4 -3
- data/src/org/apache/batik/svggen/font/table/FpgmTable.java +9 -9
- data/src/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +134 -132
- data/src/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +123 -122
- data/src/org/apache/batik/svggen/font/table/GlyfDescript.java +44 -44
- data/src/org/apache/batik/svggen/font/table/GlyfSimpleDescript.java +110 -109
- data/src/org/apache/batik/svggen/font/table/GlyfTable.java +46 -46
- data/src/org/apache/batik/svggen/font/table/GlyphDescription.java +25 -13
- data/src/org/apache/batik/svggen/font/table/GposTable.java +26 -23
- data/src/org/apache/batik/svggen/font/table/GsubTable.java +85 -82
- data/src/org/apache/batik/svggen/font/table/HeadTable.java +131 -131
- data/src/org/apache/batik/svggen/font/table/HheaTable.java +80 -80
- data/src/org/apache/batik/svggen/font/table/HmtxTable.java +50 -49
- data/src/org/apache/batik/svggen/font/table/KernSubtable.java +29 -27
- data/src/org/apache/batik/svggen/font/table/KernSubtableFormat0.java +35 -32
- data/src/org/apache/batik/svggen/font/table/KernSubtableFormat2.java +28 -26
- data/src/org/apache/batik/svggen/font/table/KernTable.java +36 -31
- data/src/org/apache/batik/svggen/font/table/KerningPair.java +27 -23
- data/src/org/apache/batik/svggen/font/table/LangSys.java +28 -26
- data/src/org/apache/batik/svggen/font/table/LangSysRecord.java +22 -22
- data/src/org/apache/batik/svggen/font/table/Ligature.java +24 -24
- data/src/org/apache/batik/svggen/font/table/LigatureSet.java +24 -24
- data/src/org/apache/batik/svggen/font/table/LigatureSubst.java +9 -9
- data/src/org/apache/batik/svggen/font/table/LigatureSubstFormat1.java +30 -30
- data/src/org/apache/batik/svggen/font/table/LocaTable.java +37 -37
- data/src/org/apache/batik/svggen/font/table/Lookup.java +41 -40
- data/src/org/apache/batik/svggen/font/table/LookupList.java +34 -34
- data/src/org/apache/batik/svggen/font/table/LookupSubtableFactory.java +7 -5
- data/src/org/apache/batik/svggen/font/table/MaxpTable.java +96 -96
- data/src/org/apache/batik/svggen/font/table/NameRecord.java +64 -65
- data/src/org/apache/batik/svggen/font/table/NameTable.java +33 -33
- data/src/org/apache/batik/svggen/font/table/Os2Table.java +196 -196
- data/src/org/apache/batik/svggen/font/table/Panose.java +14 -12
- data/src/org/apache/batik/svggen/font/table/PostTable.java +338 -338
- data/src/org/apache/batik/svggen/font/table/PrepTable.java +9 -9
- data/src/org/apache/batik/svggen/font/table/Program.java +15 -15
- data/src/org/apache/batik/svggen/font/table/RangeRecord.java +26 -25
- data/src/org/apache/batik/svggen/font/table/Script.java +38 -38
- data/src/org/apache/batik/svggen/font/table/ScriptList.java +42 -42
- data/src/org/apache/batik/svggen/font/table/ScriptRecord.java +22 -22
- data/src/org/apache/batik/svggen/font/table/ScriptTags.java +2 -1
- data/src/org/apache/batik/svggen/font/table/SingleSubst.java +15 -16
- data/src/org/apache/batik/svggen/font/table/SingleSubstFormat1.java +33 -33
- data/src/org/apache/batik/svggen/font/table/SingleSubstFormat2.java +32 -32
- data/src/org/apache/batik/svggen/font/table/Table.java +171 -170
- data/src/org/apache/batik/svggen/font/table/TableDirectory.java +55 -55
- data/src/org/apache/batik/svggen/font/table/TableFactory.java +92 -93
- metadata +10 -11
- data/.travis.yml +0 -9
data/src/geomerative/RPoint.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
|
@@ -22,398 +22,398 @@ package geomerative;
|
|
22
22
|
* RPoint is a very simple interface for creating, holding and drawing 2D
|
23
23
|
* points.
|
24
24
|
*
|
25
|
-
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
25
|
+
RPoint
|
26
|
+
* Geometry
|
27
|
+
* x
|
28
|
+
* y
|
29
29
|
*/
|
30
30
|
public class RPoint {
|
31
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
|
-
* 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");
|
32
|
+
/**
|
33
|
+
* The x coordinate of the point.
|
34
|
+
*
|
35
|
+
RPoint_x
|
36
|
+
* Geometry
|
37
|
+
* y
|
38
|
+
*/
|
39
|
+
public float x;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* The y coordinate of the point.
|
43
|
+
*
|
44
|
+
RPoint_y
|
45
|
+
* Geometry
|
46
|
+
* x
|
47
|
+
*/
|
48
|
+
public float y;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Create a new point, given the coordinates.
|
52
|
+
*
|
53
|
+
RPoint_constructor
|
54
|
+
* Geometry
|
55
|
+
* @param x the x coordinate of the new point
|
56
|
+
* @param y the y coordinate of the new point
|
57
|
+
* x
|
58
|
+
* 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
|
+
RPoint_constructor
|
74
|
+
* Geometry
|
75
|
+
* x
|
76
|
+
* y
|
77
|
+
*/
|
78
|
+
public RPoint() {
|
79
|
+
x = 0;
|
80
|
+
y = 0;
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Copy a point.
|
85
|
+
*
|
86
|
+
RPoint_constructor
|
87
|
+
* Geometry
|
88
|
+
* @param p the point we wish to make a copy of
|
89
|
+
* x
|
90
|
+
* y
|
91
|
+
*/
|
92
|
+
public RPoint(RPoint p) {
|
93
|
+
this.x = p.x;
|
94
|
+
this.y = p.y;
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
*/
|
100
|
+
float getX() {
|
101
|
+
return this.x;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
*
|
106
|
+
*/
|
107
|
+
float getY() {
|
108
|
+
return this.y;
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
*
|
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
|
+
RPoint_transform
|
123
|
+
* Geometry
|
124
|
+
* @param m the transformation matrix to be applied
|
125
|
+
* translate ( )
|
126
|
+
* rotate ( )
|
127
|
+
* 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
|
+
RPoint_translate
|
141
|
+
* Geometry
|
142
|
+
* @param tx the coefficient of x translation
|
143
|
+
* @param ty the coefficient of y translation
|
144
|
+
* transform ( )
|
145
|
+
* rotate ( )
|
146
|
+
* 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
|
+
RPoint_translate
|
157
|
+
* Geometry
|
158
|
+
* @param t the translation vector to be applied
|
159
|
+
* transform ( )
|
160
|
+
* rotate ( )
|
161
|
+
* 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
|
+
RPoint_rotate
|
173
|
+
* 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
|
+
* transform ( )
|
178
|
+
* translate ( )
|
179
|
+
* 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 of
|
211
|
+
* the center of rotation.
|
212
|
+
*
|
213
|
+
RPoint_rotate
|
214
|
+
* Geometry
|
215
|
+
* @param angle the angle of rotation to be applied
|
216
|
+
* @param v the position vector of the center of rotation
|
217
|
+
* transform ( )
|
218
|
+
* translate ( )
|
219
|
+
* 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
|
+
RPoint_scale
|
242
|
+
* Geometry
|
243
|
+
* @param sx the scaling coefficient over the x axis
|
244
|
+
* @param sy the scaling coefficient over the y axis
|
245
|
+
* transform ( )
|
246
|
+
* translate ( )
|
247
|
+
* 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
|
+
RPoint_scale
|
258
|
+
* Geometry
|
259
|
+
* @param s the scaling coefficient for a uniform scaling
|
260
|
+
* transform ( )
|
261
|
+
* translate ( )
|
262
|
+
* 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
|
+
RPoint_scale
|
273
|
+
* Geometry
|
274
|
+
* @param s the scaling vector
|
275
|
+
* transform ( )
|
276
|
+
* translate ( )
|
277
|
+
* 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 norm
|
286
|
+
* will be equal to 1.
|
287
|
+
*
|
288
|
+
RPoint_normalize
|
289
|
+
* Geometry
|
290
|
+
* transform ( )
|
291
|
+
* translate ( )
|
292
|
+
* rotate ( )
|
293
|
+
* scale ( )
|
294
|
+
*/
|
295
|
+
public void normalize() {
|
296
|
+
float norma = norm();
|
297
|
+
if (norma != 0) {
|
298
|
+
scale(1 / norma);
|
418
299
|
}
|
300
|
+
}
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Use this to subtract a vector from this point.
|
304
|
+
*
|
305
|
+
RPoint_sub
|
306
|
+
* Geometry
|
307
|
+
* @param p the vector to substract
|
308
|
+
* add ( )
|
309
|
+
* mult ( )
|
310
|
+
* 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
|
+
RPoint_add
|
321
|
+
* Geometry
|
322
|
+
* @param p the vector to add
|
323
|
+
* sub ( )
|
324
|
+
* mult ( )
|
325
|
+
* 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
|
+
RPoint_mult
|
337
|
+
* Geometry
|
338
|
+
* @param p the vector to multiply
|
339
|
+
* @return float, the result of the scalar product
|
340
|
+
* add ( )
|
341
|
+
* sub ( )
|
342
|
+
* 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
|
+
RPoint_cross
|
353
|
+
* Geometry
|
354
|
+
* @param p the vector to perform the cross product with
|
355
|
+
* @return RPoint, the resulting vector of the cross product
|
356
|
+
* add ( )
|
357
|
+
* sub ( )
|
358
|
+
* 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
|
+
RPoint_norm
|
368
|
+
* Geometry
|
369
|
+
* @return float, the norm of the point
|
370
|
+
* 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
|
+
RPoint_norm
|
380
|
+
* Geometry
|
381
|
+
* @return float, the norm of the point
|
382
|
+
* 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
|
+
RPoint_angle
|
392
|
+
* 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
|
+
* 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
|
+
RPoint_dist
|
407
|
+
* 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
|
+
* 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
|
}
|