geomerative 0.4.3-java → 2.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +1 -1
- data/CHANGELOG.md +19 -1
- data/COPYING.md +1 -1
- data/README.md +2 -2
- data/Rakefile +2 -15
- data/docs/_config.yml +8 -0
- data/docs/_includes/head.html +7 -6
- 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 +24 -0
- 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/README.md +1 -1
- data/examples/data/bot1.svg +1 -1
- data/examples/data/lion.svg +156 -156
- data/examples/data/ruby.svg +1 -1
- data/examples/jruby_merge.rb +1 -1
- data/examples/{f_agent.rb → library/f_agent/f_agent.rb} +0 -0
- data/examples/{font_agent.rb → library/font_agent/font_agent.rb} +2 -1
- data/examples/text_on_geomerative_path.rb +3 -2
- data/examples/typo_deform.rb +2 -2
- data/examples/typo_extra_bright.rb +1 -1
- data/geomerative.gemspec +3 -6
- data/lib/geomerative/version.rb +1 -1
- data/lib/geomerative.jar +0 -0
- data/lib/geomerative.rb +10 -10
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.rb +14 -16
- data/pom.xml +13 -19
- data/src/geomerative/FastRClip.java +2050 -2334
- 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 -962
- 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 -926
- data/src/geomerative/RPoint.java +391 -391
- data/src/geomerative/RPolygon.java +1017 -1013
- 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/module-info.java +4 -0
- 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 +18 -19
- data/.travis.yml +0 -10
- data/calculate_torsional_angle.rb +0 -17
@@ -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,11 +18,7 @@
|
|
18
18
|
*/
|
19
19
|
package geomerative;
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
import processing.core.PApplet;
|
24
|
-
import processing.core.PGraphics;
|
25
|
-
|
21
|
+
import processing.core.*;
|
26
22
|
|
27
23
|
/**
|
28
24
|
* RPolygon is a reduced interface for creating, holding and drawing complex
|
@@ -30,1085 +26,1093 @@ import processing.core.PGraphics;
|
|
30
26
|
* interface allows us to perform binary operations (difference, xor, union and
|
31
27
|
* intersection) on polygons.
|
32
28
|
*
|
33
|
-
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
43
|
-
|
29
|
+
RPolygon
|
30
|
+
* Geometry
|
31
|
+
* RContour
|
32
|
+
* createCircle ( )
|
33
|
+
* createRing ( )
|
34
|
+
* createStar ( )
|
35
|
+
* diff ( )
|
36
|
+
* xor ( )
|
37
|
+
* union ( )
|
38
|
+
* intersection ( )
|
39
|
+
|
44
40
|
*/
|
45
41
|
public class RPolygon extends RGeomElem {
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Array of RContour objects holding the contours of the polygon.
|
55
|
-
*
|
56
|
-
* @eexample contours
|
57
|
-
* @related RContour
|
58
|
-
* @related countContours ( )
|
59
|
-
* @related addContour ( )
|
60
|
-
*/
|
61
|
-
public RContour[] contours;
|
62
|
-
int currentContour = 0;
|
63
|
-
|
64
|
-
// ----------------------
|
65
|
-
// --- Public Methods ---
|
66
|
-
// ----------------------
|
67
|
-
/**
|
68
|
-
* Make a copy of the given polygon.
|
69
|
-
*
|
70
|
-
* @eexample createPolygon
|
71
|
-
* @param p the object of which to make a copy
|
72
|
-
*/
|
73
|
-
public RPolygon(RPolygon p) {
|
74
|
-
if (p == null) {
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
|
78
|
-
for (int i = 0; i < p.countContours(); i++) {
|
79
|
-
this.append(new RContour(p.contours[i]));
|
80
|
-
}
|
81
|
-
type = RGeomElem.POLYGON;
|
82
|
-
|
83
|
-
setStyle(p);
|
84
|
-
}
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Create a new polygon given an array of points.
|
88
|
-
*
|
89
|
-
* @eexample createPolygon
|
90
|
-
* @param points the points for the new polygon.
|
91
|
-
*/
|
92
|
-
public RPolygon(RPoint[] points) {
|
93
|
-
this(new RContour(points));
|
94
|
-
}
|
95
|
-
|
96
|
-
/**
|
97
|
-
* Create a new polygon given a contour.
|
98
|
-
*
|
99
|
-
* @param newcontour the contour for the new polygon.
|
100
|
-
*/
|
101
|
-
public RPolygon(RContour newcontour) {
|
102
|
-
this.append(newcontour);
|
103
|
-
type = RGeomElem.POLYGON;
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Create an empty polygon.
|
108
|
-
*/
|
109
|
-
public RPolygon() {
|
110
|
-
contours = null;
|
111
|
-
type = RGeomElem.POLYGON;
|
112
|
-
}
|
113
|
-
|
114
|
-
/**
|
115
|
-
* Use this method to create a new circle polygon.
|
116
|
-
*
|
117
|
-
* @param x
|
118
|
-
* @param y
|
119
|
-
* @eexample createCircle
|
120
|
-
* @param radius the radius of the circle
|
121
|
-
* @param detail the number of vertices of the polygon
|
122
|
-
* @return RPolygon, the circular polygon newly created
|
123
|
-
*/
|
124
|
-
static public RPolygon createCircle(float x, float y, float radius, int detail) {
|
125
|
-
RPoint[] points = new RPoint[detail];
|
126
|
-
double radiansPerStep = 2 * Math.PI / detail;
|
127
|
-
for (int i = 0; i < detail; i++) {
|
128
|
-
points[i] = new RPoint(
|
129
|
-
radius * Math.cos(i * radiansPerStep) + x,
|
130
|
-
radius * Math.sin(i * radiansPerStep) + y
|
131
|
-
);
|
132
|
-
}
|
133
|
-
return new RPolygon(points);
|
134
|
-
}
|
135
|
-
|
136
|
-
static public RPolygon createCircle(float radius, int detail) {
|
137
|
-
return createCircle(0, 0, radius, detail);
|
138
|
-
}
|
139
|
-
|
140
|
-
static public RPolygon createCircle(float x, float y, float radius) {
|
141
|
-
return createCircle(x, y, radius, defaultDetail);
|
142
|
-
}
|
143
|
-
|
144
|
-
static public RPolygon createCircle(float radius) {
|
145
|
-
return createCircle(0, 0, radius, defaultDetail);
|
146
|
-
}
|
43
|
+
/**
|
44
|
+
*
|
45
|
+
*/
|
46
|
+
public int type = RGeomElem.POLYGON;
|
47
|
+
public static int defaultDetail = 50;
|
147
48
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
static public RPolygon createRectangle(float x, float y, float w, float h) {
|
159
|
-
RPolygon rectangle = new RPolygon();
|
160
|
-
rectangle.addPoint(x, y);
|
161
|
-
rectangle.addPoint(x + w, y);
|
162
|
-
rectangle.addPoint(x + w, y + h);
|
163
|
-
rectangle.addPoint(x, y + h);
|
164
|
-
rectangle.addPoint(x, y);
|
165
|
-
return rectangle;
|
166
|
-
}
|
49
|
+
/**
|
50
|
+
* Array of RContour objects holding the contours of the polygon.
|
51
|
+
*
|
52
|
+
contours
|
53
|
+
* RContour
|
54
|
+
* countContours ( )
|
55
|
+
* addContour ( )
|
56
|
+
*/
|
57
|
+
public RContour[] contours;
|
58
|
+
int currentContour = 0;
|
167
59
|
|
168
|
-
|
169
|
-
|
60
|
+
// ----------------------
|
61
|
+
// --- Public Methods ---
|
62
|
+
// ----------------------
|
63
|
+
/**
|
64
|
+
* Make a copy of the given polygon.
|
65
|
+
*
|
66
|
+
createPolygon
|
67
|
+
* @param p the object of which to make a copy
|
68
|
+
*/
|
69
|
+
public RPolygon(RPolygon p) {
|
70
|
+
if (p == null) {
|
71
|
+
return;
|
170
72
|
}
|
171
73
|
|
172
|
-
|
173
|
-
|
174
|
-
*
|
175
|
-
* @param x
|
176
|
-
* @param y
|
177
|
-
* @eexample createStar
|
178
|
-
* @param radiusBig the outter radius of the star polygon
|
179
|
-
* @param radiusSmall the inner radius of the star polygon
|
180
|
-
* @param spikes the amount of spikes on the star polygon
|
181
|
-
* @return RPolygon, the starform polygon newly created
|
182
|
-
*/
|
183
|
-
static public RPolygon createStar(float x, float y, float radiusBig, float radiusSmall, int spikes) {
|
184
|
-
int numPoints = spikes * 2;
|
185
|
-
RPoint[] points = new RPoint[numPoints];
|
186
|
-
double radiansPerStep = Math.PI / spikes;
|
187
|
-
for (int i = 0; i < numPoints; i += 2) {
|
188
|
-
points[i] = new RPoint(
|
189
|
-
radiusBig * Math.cos(i * radiansPerStep) + x,
|
190
|
-
radiusBig * Math.sin(i * radiansPerStep) + y
|
191
|
-
);
|
192
|
-
points[i + 1] = new RPoint(
|
193
|
-
radiusSmall * Math.cos(i * radiansPerStep) + x,
|
194
|
-
radiusSmall * Math.sin(i * radiansPerStep) + y
|
195
|
-
);
|
196
|
-
}
|
197
|
-
return new RPolygon(points);
|
74
|
+
for (int i = 0; i < p.countContours(); i++) {
|
75
|
+
this.append(new RContour(p.contours[i]));
|
198
76
|
}
|
77
|
+
type = RGeomElem.POLYGON;
|
199
78
|
|
200
|
-
|
201
|
-
|
202
|
-
}
|
79
|
+
setStyle(p);
|
80
|
+
}
|
203
81
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
82
|
+
/**
|
83
|
+
* Create a new polygon given an array of points.
|
84
|
+
*
|
85
|
+
createPolygon
|
86
|
+
* @param points the points for the new polygon.
|
87
|
+
*/
|
88
|
+
public RPolygon(RPoint[] points) {
|
89
|
+
this(new RContour(points));
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Create a new polygon given a contour.
|
94
|
+
*
|
95
|
+
* @param newcontour the contour for the new polygon.
|
96
|
+
*/
|
97
|
+
public RPolygon(RContour newcontour) {
|
98
|
+
this.append(newcontour);
|
99
|
+
type = RGeomElem.POLYGON;
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Create an empty polygon.
|
104
|
+
*/
|
105
|
+
public RPolygon() {
|
106
|
+
contours = null;
|
107
|
+
type = RGeomElem.POLYGON;
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Use this method to create a new circle polygon.
|
112
|
+
*
|
113
|
+
* @param x
|
114
|
+
* @param y
|
115
|
+
createCircle
|
116
|
+
* @param radius the radius of the circle
|
117
|
+
* @param detail the number of vertices of the polygon
|
118
|
+
* @return RPolygon, the circular polygon newly created
|
119
|
+
*/
|
120
|
+
static public RPolygon createCircle(float x, float y, float radius, int detail) {
|
121
|
+
RPoint[] points = new RPoint[detail];
|
122
|
+
double radiansPerStep = 2 * Math.PI / detail;
|
123
|
+
for (int i = 0; i < detail; i++) {
|
124
|
+
points[i] = new RPoint(
|
125
|
+
radius * Math.cos(i * radiansPerStep) + x,
|
126
|
+
radius * Math.sin(i * radiansPerStep) + y
|
127
|
+
);
|
128
|
+
}
|
129
|
+
return new RPolygon(points);
|
130
|
+
}
|
131
|
+
|
132
|
+
static public RPolygon createCircle(float radius, int detail) {
|
133
|
+
return createCircle(0, 0, radius, detail);
|
134
|
+
}
|
135
|
+
|
136
|
+
static public RPolygon createCircle(float x, float y, float radius) {
|
137
|
+
return createCircle(x, y, radius, defaultDetail);
|
138
|
+
}
|
139
|
+
|
140
|
+
static public RPolygon createCircle(float radius) {
|
141
|
+
return createCircle(0, 0, radius, defaultDetail);
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Use this method to create a new rectangle polygon.
|
146
|
+
*
|
147
|
+
createRectangle
|
148
|
+
* @param x the upper-left corner x coordinate
|
149
|
+
* @param y the upper-left corner y coordinate
|
150
|
+
* @param w the width
|
151
|
+
* @param h the height
|
152
|
+
* @return RPolygon, the circular polygon newly created
|
153
|
+
*/
|
154
|
+
static public RPolygon createRectangle(float x, float y, float w, float h) {
|
155
|
+
RPolygon rectangle = new RPolygon();
|
156
|
+
rectangle.addPoint(x, y);
|
157
|
+
rectangle.addPoint(x + w, y);
|
158
|
+
rectangle.addPoint(x + w, y + h);
|
159
|
+
rectangle.addPoint(x, y + h);
|
160
|
+
rectangle.addPoint(x, y);
|
161
|
+
return rectangle;
|
162
|
+
}
|
163
|
+
|
164
|
+
static public RPolygon createRectangle(float w, float h) {
|
165
|
+
return createRectangle(0, 0, w, h);
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Use this method to create a new starform polygon.
|
170
|
+
*
|
171
|
+
* @param x
|
172
|
+
* @param y
|
173
|
+
createStar
|
174
|
+
* @param radiusBig the outter radius of the star polygon
|
175
|
+
* @param radiusSmall the inner radius of the star polygon
|
176
|
+
* @param spikes the amount of spikes on the star polygon
|
177
|
+
* @return RPolygon, the starform polygon newly created
|
178
|
+
*/
|
179
|
+
static public RPolygon createStar(float x, float y, float radiusBig, float radiusSmall, int spikes) {
|
180
|
+
int numPoints = spikes * 2;
|
181
|
+
RPoint[] points = new RPoint[numPoints];
|
182
|
+
double radiansPerStep = Math.PI / spikes;
|
183
|
+
for (int i = 0; i < numPoints; i += 2) {
|
184
|
+
points[i] = new RPoint(
|
185
|
+
radiusBig * Math.cos(i * radiansPerStep) + x,
|
186
|
+
radiusBig * Math.sin(i * radiansPerStep) + y
|
187
|
+
);
|
188
|
+
points[i + 1] = new RPoint(
|
189
|
+
radiusSmall * Math.cos(i * radiansPerStep) + x,
|
190
|
+
radiusSmall * Math.sin(i * radiansPerStep) + y
|
191
|
+
);
|
192
|
+
}
|
193
|
+
return new RPolygon(points);
|
194
|
+
}
|
195
|
+
|
196
|
+
static public RPolygon createStar(float radiusBig, float radiusSmall, int spikes) {
|
197
|
+
return createStar(0, 0, radiusBig, radiusSmall, spikes);
|
198
|
+
}
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Use this method to create a new ring polygon.
|
202
|
+
*
|
203
|
+
* @param x
|
204
|
+
* @param y
|
205
|
+
createRing
|
206
|
+
* @param radiusBig the outter radius of the ring polygon
|
207
|
+
* @param radiusSmall the inner radius of the ring polygon
|
208
|
+
* @param detail the number of vertices on each contour of the ring
|
209
|
+
* @return RPolygon, the ring polygon newly created
|
210
|
+
*/
|
211
|
+
static public RPolygon createRing(float x, float y, float radiusBig, float radiusSmall, int detail) {
|
212
|
+
RPoint[] inner = new RPoint[detail];
|
213
|
+
RPoint[] outer = new RPoint[detail];
|
214
|
+
double radiansPerStep = 2 * Math.PI / detail;
|
215
|
+
for (int i = 0; i < detail; i++) {
|
216
|
+
inner[i] = new RPoint(
|
217
|
+
radiusSmall * Math.cos(i * radiansPerStep) + x,
|
218
|
+
radiusSmall * Math.sin(i * radiansPerStep) + y
|
219
|
+
);
|
220
|
+
outer[i] = new RPoint(
|
221
|
+
radiusBig * Math.cos(i * radiansPerStep) + x,
|
222
|
+
radiusBig * Math.sin(i * radiansPerStep) + y
|
223
|
+
);
|
224
|
+
}
|
225
|
+
RPolygon ring = new RPolygon();
|
226
|
+
ring.addContour(outer);
|
227
|
+
ring.addContour(inner);
|
228
|
+
return ring;
|
229
|
+
}
|
230
|
+
|
231
|
+
static public RPolygon createRing(float radiusBig, float radiusSmall, int detail) {
|
232
|
+
return createRing(0, 0, radiusBig, radiusSmall, detail);
|
233
|
+
}
|
234
|
+
|
235
|
+
static public RPolygon createRing(float x, float y, float radiusBig, float radiusSmall) {
|
236
|
+
return createRing(x, y, radiusBig, radiusSmall, defaultDetail);
|
237
|
+
}
|
238
|
+
|
239
|
+
static public RPolygon createRing(float radiusBig, float radiusSmall) {
|
240
|
+
return createRing(0, 0, radiusBig, radiusSmall, defaultDetail);
|
241
|
+
}
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Use this method to get the centroid of the element.
|
245
|
+
*
|
246
|
+
RGroup_getCentroid
|
247
|
+
* @return RPo the centroid point of the element
|
248
|
+
* getBounds ( )
|
249
|
+
* getCenter ( )
|
250
|
+
*/
|
251
|
+
@Override
|
252
|
+
public RPoint getCentroid() {
|
253
|
+
RPoint bestCentroid = new RPoint();
|
254
|
+
float bestArea = Float.NEGATIVE_INFINITY;
|
255
|
+
if (contours != null) {
|
256
|
+
for (RContour contour : contours) {
|
257
|
+
float area = Math.abs(contour.getArea());
|
258
|
+
if (area > bestArea) {
|
259
|
+
bestArea = area;
|
260
|
+
bestCentroid = contour.getCentroid();
|
228
261
|
}
|
229
|
-
|
230
|
-
|
231
|
-
ring.addContour(inner);
|
232
|
-
return ring;
|
262
|
+
}
|
263
|
+
return bestCentroid;
|
233
264
|
}
|
265
|
+
return null;
|
266
|
+
}
|
234
267
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
268
|
+
/**
|
269
|
+
* Use this method to count the number of contours in the polygon.
|
270
|
+
*
|
271
|
+
countContours
|
272
|
+
* @return int the number contours in the polygon
|
273
|
+
* addContour ( )
|
274
|
+
*/
|
275
|
+
public int countContours() {
|
276
|
+
if (this.contours == null) {
|
277
|
+
return 0;
|
245
278
|
}
|
246
279
|
|
247
|
-
|
248
|
-
|
249
|
-
*
|
250
|
-
* @eexample RGroup_getCentroid
|
251
|
-
* @return RPo the centroid point of the element
|
252
|
-
* @related getBounds ( )
|
253
|
-
* @related getCenter ( )
|
254
|
-
*/
|
255
|
-
@Override
|
256
|
-
public RPoint getCentroid() {
|
257
|
-
RPoint bestCentroid = new RPoint();
|
258
|
-
float bestArea = Float.NEGATIVE_INFINITY;
|
259
|
-
if (contours != null) {
|
260
|
-
for (RContour contour : contours) {
|
261
|
-
float area = Math.abs(contour.getArea());
|
262
|
-
if (area > bestArea) {
|
263
|
-
bestArea = area;
|
264
|
-
bestCentroid = contour.getCentroid();
|
265
|
-
}
|
266
|
-
}
|
267
|
-
return bestCentroid;
|
268
|
-
}
|
269
|
-
return null;
|
270
|
-
}
|
280
|
+
return this.contours.length;
|
281
|
+
}
|
271
282
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
283
|
+
/**
|
284
|
+
* Add a new contour to the polygon.
|
285
|
+
*
|
286
|
+
addContour
|
287
|
+
* @param c the contour to be added
|
288
|
+
* addPoint ( )
|
289
|
+
*/
|
290
|
+
public void addContour(RContour c) {
|
291
|
+
this.append(c);
|
292
|
+
}
|
293
|
+
|
294
|
+
/**
|
295
|
+
* Add an empty contour to the polygon.
|
296
|
+
*
|
297
|
+
addContour
|
298
|
+
* addPoint ( )
|
299
|
+
*/
|
300
|
+
public void addContour() {
|
301
|
+
this.append(new RContour());
|
302
|
+
}
|
303
|
+
|
304
|
+
/**
|
305
|
+
* Add a new contour to the polygon given an array of points.
|
306
|
+
*
|
307
|
+
addContour
|
308
|
+
* @param points the points of the new contour to be added
|
309
|
+
* addPoint ( )
|
310
|
+
*/
|
311
|
+
public void addContour(RPoint[] points) {
|
312
|
+
this.append(new RContour(points));
|
313
|
+
}
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Use this method to set the current contour to which append points.
|
317
|
+
*
|
318
|
+
* @param indContour
|
319
|
+
addContour
|
320
|
+
* addPoint ( )
|
321
|
+
*/
|
322
|
+
public void setContour(int indContour) {
|
323
|
+
this.currentContour = indContour;
|
324
|
+
}
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Add a new point to the current contour.
|
328
|
+
*
|
329
|
+
addPoint
|
330
|
+
* @param p the point to be added
|
331
|
+
* addContour ( )
|
332
|
+
* setCurrent ( )
|
333
|
+
*/
|
334
|
+
public void addPoint(RPoint p) {
|
335
|
+
if (contours == null) {
|
336
|
+
this.append(new RContour());
|
337
|
+
}
|
338
|
+
this.contours[currentContour].append(p);
|
339
|
+
}
|
340
|
+
|
341
|
+
/**
|
342
|
+
* Add a new point to the current contour.
|
343
|
+
*
|
344
|
+
addPoint
|
345
|
+
* @param x the x coordinate of the point to be added
|
346
|
+
* @param y the y coordinate of the point to be added
|
347
|
+
* addContour ( )
|
348
|
+
* setCurrent ( )
|
349
|
+
*/
|
350
|
+
public void addPoint(float x, float y) {
|
351
|
+
if (contours == null) {
|
352
|
+
this.append(new RContour());
|
353
|
+
}
|
354
|
+
this.contours[currentContour].append(new RPoint(x, y));
|
355
|
+
}
|
356
|
+
|
357
|
+
/**
|
358
|
+
* Add a new point to the selected contour.
|
359
|
+
*
|
360
|
+
addPoint
|
361
|
+
* @param indContour the index of the contour to which the point will be added
|
362
|
+
* @param p the point to be added
|
363
|
+
* addContour ( )
|
364
|
+
* setCurrent ( )
|
365
|
+
*/
|
366
|
+
public void addPoint(int indContour, RPoint p) {
|
367
|
+
if (contours == null) {
|
368
|
+
this.append(new RContour());
|
369
|
+
}
|
370
|
+
this.contours[indContour].append(p);
|
371
|
+
}
|
372
|
+
|
373
|
+
/**
|
374
|
+
* Add a new point to the selected contour.
|
375
|
+
*
|
376
|
+
addPoint
|
377
|
+
* @param indContour the index of the contour to which the point will be added
|
378
|
+
* @param x the x coordinate of the point to be added
|
379
|
+
* @param y the y coordinate of the point to be added
|
380
|
+
* addContour ( )
|
381
|
+
* setCurrent ( )
|
382
|
+
*/
|
383
|
+
public void addPoint(int indContour, float x, float y) {
|
384
|
+
if (contours == null) {
|
385
|
+
this.append(new RContour());
|
386
|
+
}
|
387
|
+
this.contours[indContour].append(new RPoint(x, y));
|
388
|
+
}
|
389
|
+
|
390
|
+
public void addClose() {
|
391
|
+
if (contours == null) {
|
392
|
+
return;
|
393
|
+
}
|
394
|
+
|
395
|
+
contours[contours.length - 1].addClose();
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* Use this method to create a new mesh from a given polygon.
|
400
|
+
*
|
401
|
+
toMesh
|
402
|
+
* @return RMesh, the mesh made of tristrips resulting of a tesselation of the
|
403
|
+
* polygon
|
404
|
+
* draw ( )
|
405
|
+
*/
|
406
|
+
@Override
|
407
|
+
public RMesh toMesh() {
|
408
|
+
if (contours == null) {
|
409
|
+
return new RMesh();
|
410
|
+
}
|
411
|
+
|
412
|
+
RMesh mesh = RClip.polygonToMesh(this);
|
413
|
+
if (mesh == null) {
|
414
|
+
return null;
|
415
|
+
}
|
416
|
+
|
417
|
+
mesh.setStyle(this);
|
418
|
+
return mesh;
|
419
|
+
}
|
420
|
+
|
421
|
+
@Override
|
422
|
+
public void print() {
|
423
|
+
System.out.println("polygon: ");
|
424
|
+
for (int i = 0; i < countContours(); i++) {
|
425
|
+
System.out.println("--- contour " + i + " ---");
|
426
|
+
contours[i].print();
|
427
|
+
System.out.println("---------------");
|
428
|
+
}
|
429
|
+
}
|
430
|
+
|
431
|
+
/**
|
432
|
+
* Removes contours with less than 3 points. These are contours that are open.
|
433
|
+
* Since close polygons have points[0] == points[-1] and two more points to
|
434
|
+
* form a triangle at least. This is useful to avoid the clipping algorithm
|
435
|
+
* from breaking.
|
436
|
+
*
|
437
|
+
* @return
|
438
|
+
*
|
439
|
+
*/
|
440
|
+
protected RPolygon removeOpenContours() {
|
441
|
+
RPolygon clean = new RPolygon();
|
442
|
+
for (int i = 0; i < countContours(); i++) {
|
443
|
+
if (contours[i].countPoints() > 3) {
|
444
|
+
clean.addContour(contours[i]);
|
445
|
+
}
|
446
|
+
}
|
447
|
+
clean.setStyle(this);
|
448
|
+
return clean;
|
449
|
+
}
|
450
|
+
|
451
|
+
/**
|
452
|
+
* @return
|
453
|
+
*/
|
454
|
+
@Override
|
455
|
+
public RPolygon toPolygon() {
|
456
|
+
return new RPolygon(this);
|
457
|
+
}
|
458
|
+
|
459
|
+
/**
|
460
|
+
* @return
|
461
|
+
*/
|
462
|
+
@Override
|
463
|
+
public RShape toShape() {
|
464
|
+
int numContours = countContours();
|
465
|
+
|
466
|
+
RShape result = new RShape();
|
467
|
+
for (int i = 0; i < numContours; i++) {
|
468
|
+
RPoint[] newpoints = this.contours[i].getHandles();
|
469
|
+
|
470
|
+
if (newpoints != null) {
|
471
|
+
result.addMoveTo(newpoints[0]);
|
472
|
+
|
473
|
+
for (int j = 1; j < newpoints.length; j++) {
|
474
|
+
result.addLineTo(newpoints[j]);
|
282
475
|
}
|
283
476
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
/**
|
288
|
-
* Add a new contour to the polygon.
|
289
|
-
*
|
290
|
-
* @eexample addContour
|
291
|
-
* @param c the contour to be added
|
292
|
-
* @related addPoint ( )
|
293
|
-
*/
|
294
|
-
public void addContour(RContour c) {
|
295
|
-
this.append(c);
|
296
|
-
}
|
297
|
-
|
298
|
-
/**
|
299
|
-
* Add an empty contour to the polygon.
|
300
|
-
*
|
301
|
-
* @eexample addContour
|
302
|
-
* @related addPoint ( )
|
303
|
-
*/
|
304
|
-
public void addContour() {
|
305
|
-
this.append(new RContour());
|
306
|
-
}
|
307
|
-
|
308
|
-
/**
|
309
|
-
* Add a new contour to the polygon given an array of points.
|
310
|
-
*
|
311
|
-
* @eexample addContour
|
312
|
-
* @param points the points of the new contour to be added
|
313
|
-
* @related addPoint ( )
|
314
|
-
*/
|
315
|
-
public void addContour(RPoint[] points) {
|
316
|
-
this.append(new RContour(points));
|
317
|
-
}
|
318
|
-
|
319
|
-
/**
|
320
|
-
* Use this method to set the current contour to which append points.
|
321
|
-
*
|
322
|
-
* @param indContour
|
323
|
-
* @eexample addContour
|
324
|
-
* @related addPoint ( )
|
325
|
-
*/
|
326
|
-
public void setContour(int indContour) {
|
327
|
-
this.currentContour = indContour;
|
328
|
-
}
|
329
|
-
|
330
|
-
/**
|
331
|
-
* Add a new point to the current contour.
|
332
|
-
*
|
333
|
-
* @eexample addPoint
|
334
|
-
* @param p the point to be added
|
335
|
-
* @related addContour ( )
|
336
|
-
* @related setCurrent ( )
|
337
|
-
*/
|
338
|
-
public void addPoint(RPoint p) {
|
339
|
-
if (contours == null) {
|
340
|
-
this.append(new RContour());
|
477
|
+
if (contours[i].closed) {
|
478
|
+
result.addClose();
|
341
479
|
}
|
342
|
-
this.contours[currentContour].append(p);
|
343
|
-
}
|
344
480
|
|
345
|
-
|
346
|
-
|
347
|
-
*
|
348
|
-
* @eexample addPoint
|
349
|
-
* @param x the x coordinate of the point to be added
|
350
|
-
* @param y the y coordinate of the point to be added
|
351
|
-
* @related addContour ( )
|
352
|
-
* @related setCurrent ( )
|
353
|
-
*/
|
354
|
-
public void addPoint(float x, float y) {
|
355
|
-
if (contours == null) {
|
356
|
-
this.append(new RContour());
|
357
|
-
}
|
358
|
-
this.contours[currentContour].append(new RPoint(x, y));
|
481
|
+
result.paths[i].setStyle(contours[i]);
|
482
|
+
}
|
359
483
|
}
|
360
484
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
* @eexample addPoint
|
365
|
-
* @param indContour the index of the contour to which the point will be
|
366
|
-
* added
|
367
|
-
* @param p the point to be added
|
368
|
-
* @related addContour ( )
|
369
|
-
* @related setCurrent ( )
|
370
|
-
*/
|
371
|
-
public void addPoint(int indContour, RPoint p) {
|
372
|
-
if (contours == null) {
|
373
|
-
this.append(new RContour());
|
374
|
-
}
|
375
|
-
this.contours[indContour].append(p);
|
376
|
-
}
|
485
|
+
result.setStyle(this);
|
486
|
+
return result;
|
487
|
+
}
|
377
488
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
489
|
+
/**
|
490
|
+
* Use this to return the points of the polygon. It returns the points in the
|
491
|
+
* way of an array of RPoint.
|
492
|
+
*
|
493
|
+
RPolygon_getHandles
|
494
|
+
* @return RPoint[], the points returned in an array.
|
495
|
+
*
|
496
|
+
*/
|
497
|
+
@Override
|
498
|
+
public RPoint[] getHandles() {
|
499
|
+
int numContours = countContours();
|
500
|
+
if (numContours == 0) {
|
501
|
+
return null;
|
502
|
+
}
|
503
|
+
|
504
|
+
RPoint[] result = null;
|
505
|
+
RPoint[] newresult = null;
|
506
|
+
for (int i = 0; i < numContours; i++) {
|
507
|
+
RPoint[] newPoints = contours[i].getHandles();
|
508
|
+
if (newPoints != null) {
|
509
|
+
if (result == null) {
|
510
|
+
result = new RPoint[newPoints.length];
|
511
|
+
System.arraycopy(newPoints, 0, result, 0, newPoints.length);
|
512
|
+
} else {
|
513
|
+
newresult = new RPoint[result.length + newPoints.length];
|
514
|
+
System.arraycopy(result, 0, newresult, 0, result.length);
|
515
|
+
System.arraycopy(newPoints, 0, newresult, result.length, newPoints.length);
|
516
|
+
result = newresult;
|
392
517
|
}
|
393
|
-
|
518
|
+
}
|
394
519
|
}
|
520
|
+
return result;
|
521
|
+
}
|
395
522
|
|
396
|
-
|
397
|
-
|
398
|
-
|
523
|
+
/**
|
524
|
+
* Use this to return the points of the polygon. It returns the points in the
|
525
|
+
* way of an array of RPoint.
|
526
|
+
*
|
527
|
+
RPolygon_getPoints
|
528
|
+
* @return RPoint[], the points returned in an array.
|
529
|
+
*
|
530
|
+
*/
|
531
|
+
@Override
|
532
|
+
public RPoint[] getPoints() {
|
533
|
+
int numContours = countContours();
|
534
|
+
if (numContours == 0) {
|
535
|
+
return null;
|
536
|
+
}
|
537
|
+
|
538
|
+
RPoint[] result = null;
|
539
|
+
RPoint[] newresult = null;
|
540
|
+
for (int i = 0; i < numContours; i++) {
|
541
|
+
RPoint[] newPoints = contours[i].getPoints();
|
542
|
+
if (newPoints != null) {
|
543
|
+
if (result == null) {
|
544
|
+
result = new RPoint[newPoints.length];
|
545
|
+
System.arraycopy(newPoints, 0, result, 0, newPoints.length);
|
546
|
+
} else {
|
547
|
+
newresult = new RPoint[result.length + newPoints.length];
|
548
|
+
System.arraycopy(result, 0, newresult, 0, result.length);
|
549
|
+
System.arraycopy(newPoints, 0, newresult, result.length, newPoints.length);
|
550
|
+
result = newresult;
|
399
551
|
}
|
400
|
-
|
401
|
-
contours[contours.length - 1].addClose();
|
552
|
+
}
|
402
553
|
}
|
554
|
+
return result;
|
555
|
+
}
|
403
556
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
557
|
+
/**
|
558
|
+
* Use this method to get the type of element this is.
|
559
|
+
*
|
560
|
+
RPolygon_getType
|
561
|
+
* @return int, will allways return RGeomElem.POLYGON
|
562
|
+
*/
|
563
|
+
@Override
|
564
|
+
public int getType() {
|
565
|
+
return type;
|
566
|
+
}
|
567
|
+
|
568
|
+
/**
|
569
|
+
* Use this method to get the area covered by the polygon.
|
570
|
+
*
|
571
|
+
getArea
|
572
|
+
* @return float, the area covered by the polygon
|
573
|
+
* draw ( )
|
574
|
+
*/
|
575
|
+
@Override
|
576
|
+
public float getArea() {
|
577
|
+
if (getNumPoints() < 3) {
|
578
|
+
return 0.0F;
|
579
|
+
}
|
580
|
+
float ax = getX(0);
|
581
|
+
float ay = getY(0);
|
582
|
+
float area = 0.0F;
|
583
|
+
for (int i = 1; i < (getNumPoints() - 1); i++) {
|
584
|
+
float bx = getX(i);
|
585
|
+
float by = getY(i);
|
586
|
+
float cx = getX(i + 1);
|
587
|
+
float cy = getY(i + 1);
|
588
|
+
float tarea = ((cx - bx) * (ay - by)) - ((ax - bx) * (cy - by));
|
589
|
+
area += tarea;
|
590
|
+
}
|
591
|
+
area = 0.5F * Math.abs(area);
|
592
|
+
return area;
|
593
|
+
}
|
594
|
+
|
595
|
+
/**
|
596
|
+
* Use this method to draw the polygon.
|
597
|
+
*
|
598
|
+
drawPolygon
|
599
|
+
* @param g PGraphics, the graphics object on which to draw the polygon
|
600
|
+
* draw ( )
|
601
|
+
*/
|
602
|
+
@Override
|
603
|
+
public void draw(PGraphics g) {
|
604
|
+
int numContours = countContours();
|
605
|
+
if (numContours != 0) {
|
606
|
+
if (isIn(g)) {
|
607
|
+
if (!RG.ignoreStyles) {
|
608
|
+
saveContext(g);
|
609
|
+
setContext(g);
|
416
610
|
}
|
417
611
|
|
418
|
-
|
419
|
-
if (
|
420
|
-
|
421
|
-
|
612
|
+
// Check whether to draw the fill or not
|
613
|
+
if (g.fill) {
|
614
|
+
// Since we are drawing the different tristrips we must turn off the stroke or make it the same color as the fill
|
615
|
+
// NOTE: there's currently no way of drawing the outline of a mesh, since no information is kept about what vertices are at the edge
|
422
616
|
|
423
|
-
|
424
|
-
|
425
|
-
|
617
|
+
// Save the information about the current stroke color and turn off
|
618
|
+
boolean stroking = g.stroke;
|
619
|
+
g.noStroke();
|
426
620
|
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
contours[i].print();
|
433
|
-
System.out.println("---------------");
|
434
|
-
}
|
435
|
-
}
|
436
|
-
|
437
|
-
/**
|
438
|
-
* Removes contours with less than 3 points. These are contours that are
|
439
|
-
* open. Since close polygons have points[0] == points[-1] and two more
|
440
|
-
* points to form a triangle at least. This is useful to avoid the clipping
|
441
|
-
* algorithm from breaking.
|
442
|
-
*
|
443
|
-
* @return
|
444
|
-
* @invisible
|
445
|
-
*/
|
446
|
-
protected RPolygon removeOpenContours() {
|
447
|
-
RPolygon clean = new RPolygon();
|
448
|
-
for (int i = 0; i < countContours(); i++) {
|
449
|
-
if (contours[i].countPoints() > 3) {
|
450
|
-
clean.addContour(contours[i]);
|
621
|
+
// Save smoothing state and turn off
|
622
|
+
int smoothing = g.smooth;
|
623
|
+
try {
|
624
|
+
if (smoothing > 0) {
|
625
|
+
g.noSmooth();
|
451
626
|
}
|
452
|
-
|
453
|
-
|
454
|
-
return clean;
|
455
|
-
}
|
627
|
+
} catch (Exception e) {
|
628
|
+
}
|
456
629
|
|
457
|
-
|
458
|
-
|
459
|
-
*/
|
460
|
-
@Override
|
461
|
-
public RPolygon toPolygon() {
|
462
|
-
return new RPolygon(this);
|
463
|
-
}
|
630
|
+
RMesh tempMesh = this.toMesh();
|
631
|
+
tempMesh.draw(g);
|
464
632
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
public RShape toShape() {
|
470
|
-
int numContours = countContours();
|
471
|
-
|
472
|
-
RShape result = new RShape();
|
473
|
-
for (int i = 0; i < numContours; i++) {
|
474
|
-
RPoint[] newpoints = this.contours[i].getHandles();
|
475
|
-
|
476
|
-
if (newpoints != null) {
|
477
|
-
result.addMoveTo(newpoints[0]);
|
478
|
-
|
479
|
-
for (int j = 1; j < newpoints.length; j++) {
|
480
|
-
result.addLineTo(newpoints[j]);
|
481
|
-
}
|
633
|
+
// Restore the old stroke color
|
634
|
+
if (stroking) {
|
635
|
+
g.stroke(g.strokeColor);
|
636
|
+
}
|
482
637
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
result.paths[i].setStyle(contours[i]);
|
638
|
+
// Restore the old smoothing state
|
639
|
+
try {
|
640
|
+
if (smoothing > 0) {
|
641
|
+
g.smooth();
|
488
642
|
}
|
643
|
+
} catch (Exception e) {
|
644
|
+
}
|
489
645
|
}
|
490
646
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
* Use this to return the points of the polygon. It returns the points in
|
497
|
-
* the way of an array of RPoint.
|
498
|
-
*
|
499
|
-
* @eexample RPolygon_getHandles
|
500
|
-
* @return RPoint[], the points returned in an array.
|
501
|
-
*
|
502
|
-
*/
|
503
|
-
@Override
|
504
|
-
public RPoint[] getHandles() {
|
505
|
-
int numContours = countContours();
|
506
|
-
if (numContours == 0) {
|
507
|
-
return null;
|
647
|
+
// Check whether to draw the stroke or not
|
648
|
+
if (g.stroke) {
|
649
|
+
for (int i = 0; i < numContours; i++) {
|
650
|
+
contours[i].draw(g);
|
651
|
+
}
|
508
652
|
}
|
509
653
|
|
510
|
-
|
511
|
-
|
512
|
-
for (int i = 0; i < numContours; i++) {
|
513
|
-
RPoint[] newPoints = contours[i].getHandles();
|
514
|
-
if (newPoints != null) {
|
515
|
-
if (result == null) {
|
516
|
-
result = new RPoint[newPoints.length];
|
517
|
-
System.arraycopy(newPoints, 0, result, 0, newPoints.length);
|
518
|
-
} else {
|
519
|
-
newresult = new RPoint[result.length + newPoints.length];
|
520
|
-
System.arraycopy(result, 0, newresult, 0, result.length);
|
521
|
-
System.arraycopy(newPoints, 0, newresult, result.length, newPoints.length);
|
522
|
-
result = newresult;
|
523
|
-
}
|
524
|
-
}
|
654
|
+
if (!RG.ignoreStyles) {
|
655
|
+
restoreContext(g);
|
525
656
|
}
|
526
|
-
|
527
|
-
}
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
public RPoint[] getPoints() {
|
539
|
-
int numContours = countContours();
|
540
|
-
if (numContours == 0) {
|
541
|
-
return null;
|
657
|
+
}
|
658
|
+
}
|
659
|
+
}
|
660
|
+
|
661
|
+
@Override
|
662
|
+
public void draw(PApplet g) {
|
663
|
+
int numContours = countContours();
|
664
|
+
if (numContours != 0) {
|
665
|
+
if (isIn(g)) {
|
666
|
+
if (!RG.ignoreStyles) {
|
667
|
+
saveContext(g);
|
668
|
+
setContext(g);
|
542
669
|
}
|
543
670
|
|
544
|
-
|
545
|
-
|
546
|
-
for (int i = 0; i < numContours; i++) {
|
547
|
-
RPoint[] newPoints = contours[i].getPoints();
|
548
|
-
if (newPoints != null) {
|
549
|
-
if (result == null) {
|
550
|
-
result = new RPoint[newPoints.length];
|
551
|
-
System.arraycopy(newPoints, 0, result, 0, newPoints.length);
|
552
|
-
} else {
|
553
|
-
newresult = new RPoint[result.length + newPoints.length];
|
554
|
-
System.arraycopy(result, 0, newresult, 0, result.length);
|
555
|
-
System.arraycopy(newPoints, 0, newresult, result.length, newPoints.length);
|
556
|
-
result = newresult;
|
557
|
-
}
|
558
|
-
}
|
559
|
-
}
|
560
|
-
return result;
|
561
|
-
}
|
562
|
-
|
563
|
-
/**
|
564
|
-
* Use this method to get the type of element this is.
|
565
|
-
*
|
566
|
-
* @eexample RPolygon_getType
|
567
|
-
* @return int, will allways return RGeomElem.POLYGON
|
568
|
-
*/
|
569
|
-
@Override
|
570
|
-
public int getType() {
|
571
|
-
return type;
|
572
|
-
}
|
573
|
-
|
574
|
-
/**
|
575
|
-
* Use this method to get the area covered by the polygon.
|
576
|
-
*
|
577
|
-
* @eexample getArea
|
578
|
-
* @return float, the area covered by the polygon
|
579
|
-
* @related draw ( )
|
580
|
-
*/
|
581
|
-
@Override
|
582
|
-
public float getArea() {
|
583
|
-
if (getNumPoints() < 3) {
|
584
|
-
return 0.0F;
|
585
|
-
}
|
586
|
-
float ax = getX(0);
|
587
|
-
float ay = getY(0);
|
588
|
-
float area = 0.0F;
|
589
|
-
for (int i = 1; i < (getNumPoints() - 1); i++) {
|
590
|
-
float bx = getX(i);
|
591
|
-
float by = getY(i);
|
592
|
-
float cx = getX(i + 1);
|
593
|
-
float cy = getY(i + 1);
|
594
|
-
float tarea = ((cx - bx) * (ay - by)) - ((ax - bx) * (cy - by));
|
595
|
-
area += tarea;
|
596
|
-
}
|
597
|
-
area = 0.5F * Math.abs(area);
|
598
|
-
return area;
|
599
|
-
}
|
600
|
-
|
601
|
-
/**
|
602
|
-
* Use this method to draw the polygon.
|
603
|
-
*
|
604
|
-
* @eexample drawPolygon
|
605
|
-
* @param g PGraphics, the graphics object on which to draw the polygon
|
606
|
-
* @related draw ( )
|
607
|
-
*/
|
608
|
-
@Override
|
609
|
-
public void draw(PGraphics g) {
|
610
|
-
int numContours = countContours();
|
611
|
-
if (numContours != 0) {
|
612
|
-
if (isIn(g)) {
|
613
|
-
if (!RG.ignoreStyles) {
|
614
|
-
saveContext(g);
|
615
|
-
setContext(g);
|
616
|
-
}
|
617
|
-
|
618
|
-
// Check whether to draw the fill or not
|
619
|
-
if (g.fill) {
|
671
|
+
// Check whether to draw the fill or not
|
672
|
+
if (g.g.fill) {
|
620
673
|
// Since we are drawing the different tristrips we must turn off the stroke or make it the same color as the fill
|
621
|
-
|
674
|
+
// NOTE: there's currently no way of drawing the outline of a mesh, since no information is kept about what vertices are at the edge
|
622
675
|
|
623
|
-
|
624
|
-
|
625
|
-
|
676
|
+
// Save the information about the current stroke color and turn off
|
677
|
+
boolean stroking = g.g.stroke;
|
678
|
+
g.noStroke();
|
626
679
|
|
627
680
|
// Save smoothing state and turn off
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
} catch (Exception e) {
|
634
|
-
}
|
635
|
-
|
636
|
-
RMesh tempMesh = this.toMesh();
|
637
|
-
tempMesh.draw(g);
|
638
|
-
|
639
|
-
// Restore the old stroke color
|
640
|
-
if (stroking) {
|
641
|
-
g.stroke(g.strokeColor);
|
642
|
-
}
|
643
|
-
|
644
|
-
}
|
645
|
-
|
646
|
-
// Check whether to draw the stroke or not
|
647
|
-
if (g.stroke) {
|
648
|
-
for (int i = 0; i < numContours; i++) {
|
649
|
-
contours[i].draw(g);
|
650
|
-
}
|
651
|
-
}
|
652
|
-
|
653
|
-
if (!RG.ignoreStyles) {
|
654
|
-
restoreContext(g);
|
655
|
-
}
|
681
|
+
int smoothing = g.g.smooth;
|
682
|
+
try {
|
683
|
+
if (smoothing > 0) {
|
684
|
+
g.noSmooth();
|
656
685
|
}
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
// Check whether to draw the fill or not
|
675
|
-
if (g.g.fill) {
|
676
|
-
// Since we are drawing the different tristrips we must turn off the stroke or make it the same color as the fill
|
677
|
-
// NOTE: there's currently no way of drawing the outline of a mesh, since no information is kept about what vertices are at the edge
|
678
|
-
|
679
|
-
// Save the information about the current stroke color and turn off
|
680
|
-
boolean stroking = g.g.stroke;
|
681
|
-
g.noStroke();
|
682
|
-
|
683
|
-
RMesh tempMesh = this.toMesh();
|
684
|
-
if (tempMesh != null) {
|
685
|
-
tempMesh.draw(g);
|
686
|
-
}
|
687
|
-
|
688
|
-
// Restore the old stroke color
|
689
|
-
if (stroking) {
|
690
|
-
g.stroke(g.g.strokeColor);
|
691
|
-
}
|
692
|
-
|
693
|
-
}
|
694
|
-
|
695
|
-
// Check whether to draws the stroke or not
|
696
|
-
if (g.g.stroke) {
|
697
|
-
for (int i = 0; i < numContours; i++) {
|
698
|
-
contours[i].draw(g);
|
699
|
-
}
|
700
|
-
}
|
701
|
-
|
702
|
-
if (!RG.ignoreStyles) {
|
703
|
-
restoreContext(g);
|
704
|
-
}
|
686
|
+
} catch (Exception e) {
|
687
|
+
}
|
688
|
+
|
689
|
+
RMesh tempMesh = this.toMesh();
|
690
|
+
if (tempMesh != null) {
|
691
|
+
tempMesh.draw(g);
|
692
|
+
}
|
693
|
+
|
694
|
+
// Restore the old stroke color
|
695
|
+
if (stroking) {
|
696
|
+
g.stroke(g.g.strokeColor);
|
697
|
+
}
|
698
|
+
|
699
|
+
// Restore the old smoothing state
|
700
|
+
try {
|
701
|
+
if (smoothing > 0) {
|
702
|
+
g.smooth();
|
705
703
|
}
|
704
|
+
} catch (Exception e) {
|
705
|
+
}
|
706
706
|
}
|
707
|
-
}
|
708
|
-
|
709
|
-
/**
|
710
|
-
* Use this method to get the intersection of this polygon with the polygon
|
711
|
-
* passed in as a parameter.
|
712
|
-
*
|
713
|
-
* @eexample intersection
|
714
|
-
* @param p RPolygon, the polygon with which to perform the intersection
|
715
|
-
* @return RPolygon, the intersection of the two polygons
|
716
|
-
* @related union ( )
|
717
|
-
* @related xor ( )
|
718
|
-
* @related diff ( )
|
719
|
-
*/
|
720
|
-
public RPolygon intersection(RPolygon p) {
|
721
|
-
RPolygon res = RClip.intersection(p, this);
|
722
|
-
res.setStyle(this.getStyle());
|
723
|
-
return res;
|
724
|
-
}
|
725
|
-
|
726
|
-
/**
|
727
|
-
* Use this method to get the union of this polygon with the polygon passed
|
728
|
-
* in as a parameter.
|
729
|
-
*
|
730
|
-
* @eexample union
|
731
|
-
* @param p RPolygon, the polygon with which to perform the union
|
732
|
-
* @return RPolygon, the union of the two polygons
|
733
|
-
* @related intersection ( )
|
734
|
-
* @related xor ( )
|
735
|
-
* @related diff ( )
|
736
|
-
*/
|
737
|
-
public RPolygon union(RPolygon p) {
|
738
|
-
RPolygon res = RClip.union(p, this);
|
739
|
-
res.setStyle(this.getStyle());
|
740
|
-
return res;
|
741
|
-
}
|
742
|
-
|
743
|
-
/**
|
744
|
-
* Use this method to get the xor of this polygon with the polygon passed in
|
745
|
-
* as a parameter.
|
746
|
-
*
|
747
|
-
* @eexample xor
|
748
|
-
* @param p RPolygon, the polygon with which to perform the xor
|
749
|
-
* @return RPolygon, the xor of the two polygons
|
750
|
-
* @related union ( )
|
751
|
-
* @related intersection ( )
|
752
|
-
* @related diff ( )
|
753
|
-
*/
|
754
|
-
public RPolygon xor(RPolygon p) {
|
755
|
-
RPolygon res = RClip.xor(p, this);
|
756
|
-
res.setStyle(this.getStyle());
|
757
|
-
return res;
|
758
|
-
}
|
759
707
|
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
* @param p RPolygon, the polygon with which to perform the difference
|
766
|
-
* @return RPolygon, the difference of the two polygons
|
767
|
-
* @related union ( )
|
768
|
-
* @related xor ( )
|
769
|
-
* @related intersection ( )
|
770
|
-
*/
|
771
|
-
public RPolygon diff(RPolygon p) {
|
772
|
-
RPolygon res = RClip.diff(this, p);
|
773
|
-
res.setStyle(this.getStyle());
|
774
|
-
return res;
|
775
|
-
}
|
776
|
-
|
777
|
-
/**
|
778
|
-
* Use this method to get a rebuilt version of a given polygon by removing
|
779
|
-
* extra points and solving intersecting contours or holes.
|
780
|
-
*
|
781
|
-
* @eexample RPolygon_update
|
782
|
-
* @return RPolygon, the updated polygon
|
783
|
-
* @related diff ( )
|
784
|
-
* @related union ( )
|
785
|
-
* @related xor ( )
|
786
|
-
* @related intersection ( )
|
787
|
-
*/
|
788
|
-
public RPolygon update() {
|
789
|
-
return RClip.update(this);
|
790
|
-
}
|
791
|
-
|
792
|
-
@Override
|
793
|
-
public RPoint getPoint(float t) {
|
794
|
-
PApplet.println("Feature not yet implemented for this class.");
|
795
|
-
return null;
|
796
|
-
}
|
797
|
-
|
798
|
-
/**
|
799
|
-
*
|
800
|
-
* @param t
|
801
|
-
* @return
|
802
|
-
*/
|
803
|
-
@Override
|
804
|
-
public RPoint getTangent(float t) {
|
805
|
-
PApplet.println("Feature not yet implemented for this class.");
|
806
|
-
return null;
|
807
|
-
}
|
808
|
-
|
809
|
-
/**
|
810
|
-
*
|
811
|
-
* @return
|
812
|
-
*/
|
813
|
-
@Override
|
814
|
-
public RPoint[] getTangents() {
|
815
|
-
PApplet.println("Feature not yet implemented for this class.");
|
816
|
-
return null;
|
817
|
-
}
|
818
|
-
|
819
|
-
/**
|
820
|
-
*
|
821
|
-
* @return
|
822
|
-
*/
|
823
|
-
@Override
|
824
|
-
public RPoint[][] getPointsInPaths() {
|
825
|
-
PApplet.println("Feature not yet implemented for this class.");
|
826
|
-
return null;
|
827
|
-
}
|
828
|
-
|
829
|
-
@Override
|
830
|
-
public RPoint[][] getHandlesInPaths() {
|
831
|
-
PApplet.println("Feature not yet implemented for this class.");
|
832
|
-
return null;
|
833
|
-
}
|
834
|
-
|
835
|
-
@Override
|
836
|
-
public RPoint[][] getTangentsInPaths() {
|
837
|
-
PApplet.println("Feature not yet implemented for this class.");
|
838
|
-
return null;
|
839
|
-
}
|
840
|
-
|
841
|
-
@Override
|
842
|
-
public boolean contains(RPoint p) {
|
843
|
-
PApplet.println("Feature not yet implemented for this class.");
|
844
|
-
return false;
|
845
|
-
}
|
846
|
-
|
847
|
-
/**
|
848
|
-
* Use this method to transform the polygon.
|
849
|
-
*
|
850
|
-
* @eexample RPolygon_transform
|
851
|
-
* @param m RMatrix, the matrix of the affine transformation to apply to the
|
852
|
-
* polygon
|
853
|
-
*/
|
854
|
-
/*
|
855
|
-
public void transform(RMatrix m){
|
856
|
-
int numContours = countContours();
|
857
|
-
if(numContours!=0){
|
858
|
-
for(int i=0;i<numContours;i++){
|
859
|
-
contours[i].transform(m);
|
860
|
-
}
|
861
|
-
}
|
862
|
-
}
|
863
|
-
*/
|
864
|
-
// ----------------------
|
865
|
-
// --- Private Methods ---
|
866
|
-
// ----------------------
|
867
|
-
/**
|
868
|
-
* Remove all of the points. Creates an empty polygon.
|
869
|
-
*/
|
870
|
-
protected void clear() {
|
871
|
-
this.contours = null;
|
872
|
-
}
|
873
|
-
|
874
|
-
/**
|
875
|
-
* Add a point to the first inner polygon.
|
876
|
-
*
|
877
|
-
* @param x
|
878
|
-
* @param y
|
879
|
-
*/
|
880
|
-
protected void add(float x, float y) {
|
881
|
-
if (contours == null) {
|
882
|
-
this.append(new RContour());
|
708
|
+
// Check whether to draws the stroke or not
|
709
|
+
if (g.g.stroke) {
|
710
|
+
for (int i = 0; i < numContours; i++) {
|
711
|
+
contours[i].draw(g);
|
712
|
+
}
|
883
713
|
}
|
884
|
-
this.contours[0].append(new RPoint(x, y));
|
885
|
-
}
|
886
714
|
|
887
|
-
|
888
|
-
|
889
|
-
*
|
890
|
-
* @param p
|
891
|
-
*/
|
892
|
-
protected void add(RPoint p) {
|
893
|
-
if (contours == null) {
|
894
|
-
this.append(new RContour());
|
715
|
+
if (!RG.ignoreStyles) {
|
716
|
+
restoreContext(g);
|
895
717
|
}
|
896
|
-
|
718
|
+
}
|
897
719
|
}
|
720
|
+
}
|
898
721
|
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
722
|
+
/**
|
723
|
+
* Use this method to get the intersection of this polygon with the polygon
|
724
|
+
* passed in as a parameter.
|
725
|
+
*
|
726
|
+
intersection
|
727
|
+
* @param p RPolygon, the polygon with which to perform the intersection
|
728
|
+
* @return RPolygon, the intersection of the two polygons
|
729
|
+
* union ( )
|
730
|
+
* xor ( )
|
731
|
+
* diff ( )
|
732
|
+
*/
|
733
|
+
public RPolygon intersection(RPolygon p) {
|
734
|
+
RPolygon res = RClip.intersection(p, this);
|
735
|
+
res.setStyle(this.getStyle());
|
736
|
+
return res;
|
737
|
+
}
|
738
|
+
|
739
|
+
/**
|
740
|
+
* Use this method to get the union of this polygon with the polygon passed in
|
741
|
+
* as a parameter.
|
742
|
+
*
|
743
|
+
union
|
744
|
+
* @param p RPolygon, the polygon with which to perform the union
|
745
|
+
* @return RPolygon, the union of the two polygons
|
746
|
+
* intersection ( )
|
747
|
+
* xor ( )
|
748
|
+
* diff ( )
|
749
|
+
*/
|
750
|
+
public RPolygon union(RPolygon p) {
|
751
|
+
RPolygon res = RClip.union(p, this);
|
752
|
+
res.setStyle(this.getStyle());
|
753
|
+
return res;
|
754
|
+
}
|
755
|
+
|
756
|
+
/**
|
757
|
+
* Use this method to get the xor of this polygon with the polygon passed in
|
758
|
+
* as a parameter.
|
759
|
+
*
|
760
|
+
xor
|
761
|
+
* @param p RPolygon, the polygon with which to perform the xor
|
762
|
+
* @return RPolygon, the xor of the two polygons
|
763
|
+
* union ( )
|
764
|
+
* intersection ( )
|
765
|
+
* diff ( )
|
766
|
+
*/
|
767
|
+
public RPolygon xor(RPolygon p) {
|
768
|
+
RPolygon res = RClip.xor(p, this);
|
769
|
+
res.setStyle(this.getStyle());
|
770
|
+
return res;
|
771
|
+
}
|
772
|
+
|
773
|
+
/**
|
774
|
+
* Use this method to get the difference between this polygon and the polygon
|
775
|
+
* passed in as a parameter.
|
776
|
+
*
|
777
|
+
diff
|
778
|
+
* @param p RPolygon, the polygon with which to perform the difference
|
779
|
+
* @return RPolygon, the difference of the two polygons
|
780
|
+
* union ( )
|
781
|
+
* xor ( )
|
782
|
+
* intersection ( )
|
783
|
+
*/
|
784
|
+
public RPolygon diff(RPolygon p) {
|
785
|
+
RPolygon res = RClip.diff(this, p);
|
786
|
+
res.setStyle(this.getStyle());
|
787
|
+
return res;
|
788
|
+
}
|
789
|
+
|
790
|
+
/**
|
791
|
+
* Use this method to get a rebuilt version of a given polygon by removing
|
792
|
+
* extra points and solving intersecting contours or holes.
|
793
|
+
*
|
794
|
+
RPolygon_update
|
795
|
+
* @return RPolygon, the updated polygon
|
796
|
+
* diff ( )
|
797
|
+
* union ( )
|
798
|
+
* xor ( )
|
799
|
+
* intersection ( )
|
800
|
+
*/
|
801
|
+
public RPolygon update() {
|
802
|
+
return RClip.update(this);
|
803
|
+
}
|
804
|
+
|
805
|
+
@Override
|
806
|
+
public RPoint getPoint(float t) {
|
807
|
+
PApplet.println("Feature not yet implemented for this class.");
|
808
|
+
return null;
|
809
|
+
}
|
810
|
+
|
811
|
+
@Override
|
812
|
+
public RPoint getTangent(float t) {
|
813
|
+
PApplet.println("Feature not yet implemented for this class.");
|
814
|
+
return null;
|
815
|
+
}
|
816
|
+
|
817
|
+
/**
|
818
|
+
*
|
819
|
+
* @return
|
820
|
+
*/
|
821
|
+
@Override
|
822
|
+
public RPoint[] getTangents() {
|
823
|
+
PApplet.println("Feature not yet implemented for this class.");
|
824
|
+
return null;
|
825
|
+
}
|
826
|
+
|
827
|
+
@Override
|
828
|
+
public RPoint[][] getPointsInPaths() {
|
829
|
+
PApplet.println("Feature not yet implemented for this class.");
|
830
|
+
return null;
|
831
|
+
}
|
832
|
+
|
833
|
+
@Override
|
834
|
+
public RPoint[][] getHandlesInPaths() {
|
835
|
+
PApplet.println("Feature not yet implemented for this class.");
|
836
|
+
return null;
|
837
|
+
}
|
838
|
+
|
839
|
+
@Override
|
840
|
+
public RPoint[][] getTangentsInPaths() {
|
841
|
+
PApplet.println("Feature not yet implemented for this class.");
|
842
|
+
return null;
|
843
|
+
}
|
844
|
+
|
845
|
+
@Override
|
846
|
+
public boolean contains(RPoint p) {
|
847
|
+
PApplet.println("Feature not yet implemented for this class.");
|
848
|
+
return false;
|
849
|
+
}
|
850
|
+
|
851
|
+
/**
|
852
|
+
* Use this method to transform the polygon.
|
853
|
+
*
|
854
|
+
RPolygon_transform
|
855
|
+
* @param m RMatrix, the matrix of the affine transformation to apply to the
|
856
|
+
* polygon
|
857
|
+
*/
|
858
|
+
/*
|
859
|
+
public void transform(RMatrix m){
|
860
|
+
int numContours = countContours();
|
861
|
+
if(numContours!=0){
|
862
|
+
for(int i=0;i<numContours;i++){
|
863
|
+
contours[i].transform(m);
|
914
864
|
}
|
915
|
-
|
916
|
-
/**
|
917
|
-
* Add an inner polygon to this polygon - assumes that adding polygon does
|
918
|
-
* not have any inner polygons.
|
919
|
-
*
|
920
|
-
* @param c
|
921
|
-
*/
|
922
|
-
protected void add(RContour c) {
|
923
|
-
/*if (this.contours.length > 0 && this.isHole){
|
924
|
-
throw new IllegalStateException("Cannot add polys to something designated as a hole.");
|
925
|
-
}*/
|
926
|
-
this.append(c);
|
927
865
|
}
|
928
|
-
|
929
|
-
/**
|
930
|
-
* Return true if the polygon is empty
|
931
|
-
*
|
932
|
-
* @return
|
933
|
-
*/
|
934
|
-
protected boolean isEmpty() {
|
935
|
-
return (this.contours == null);
|
936
866
|
}
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
867
|
+
*/
|
868
|
+
// ----------------------
|
869
|
+
// --- Private Methods ---
|
870
|
+
// ----------------------
|
871
|
+
/**
|
872
|
+
* Remove all of the points. Creates an empty polygon.
|
873
|
+
*/
|
874
|
+
protected void clear() {
|
875
|
+
this.contours = null;
|
876
|
+
}
|
877
|
+
|
878
|
+
/**
|
879
|
+
* Add a point to the first inner polygon.
|
880
|
+
*
|
881
|
+
* @param x
|
882
|
+
* @param y
|
883
|
+
*/
|
884
|
+
protected void add(float x, float y) {
|
885
|
+
if (contours == null) {
|
886
|
+
this.append(new RContour());
|
887
|
+
}
|
888
|
+
this.contours[0].append(new RPoint(x, y));
|
889
|
+
}
|
890
|
+
|
891
|
+
/**
|
892
|
+
* Add a point to the first inner polygon.
|
893
|
+
*
|
894
|
+
* @param p
|
895
|
+
*/
|
896
|
+
protected void add(RPoint p) {
|
897
|
+
if (contours == null) {
|
898
|
+
this.append(new RContour());
|
899
|
+
}
|
900
|
+
this.contours[0].append(p);
|
901
|
+
}
|
902
|
+
|
903
|
+
/**
|
904
|
+
* Add an inner polygon to this polygon - assumes that adding polygon does not
|
905
|
+
* have any inner polygons.
|
906
|
+
*
|
907
|
+
* @param p
|
908
|
+
*/
|
909
|
+
protected void add(RPolygon p) {
|
910
|
+
/*if (this.contours.length > 0 && this.isHole){
|
911
|
+
throw new IllegalStateException("Cannot add polys to something designated as a hole.");
|
912
|
+
}*/
|
913
|
+
RContour c = new RContour();
|
914
|
+
for (int i = 0; i < p.getNumPoints(); i++) {
|
915
|
+
c.addPoint(p.getX(i), p.getY(i));
|
916
|
+
}
|
917
|
+
this.append(c);
|
918
|
+
}
|
919
|
+
|
920
|
+
/**
|
921
|
+
* Add an inner polygon to this polygon - assumes that adding polygon does not
|
922
|
+
* have any inner polygons.
|
923
|
+
*
|
924
|
+
* @param c
|
925
|
+
*/
|
926
|
+
protected void add(RContour c) {
|
927
|
+
/*if (this.contours.length > 0 && this.isHole){
|
928
|
+
throw new IllegalStateException("Cannot add polys to something designated as a hole.");
|
929
|
+
}*/
|
930
|
+
this.append(c);
|
931
|
+
}
|
932
|
+
|
933
|
+
/**
|
934
|
+
* Return true if the polygon is empty
|
935
|
+
*
|
936
|
+
* @return
|
937
|
+
*/
|
938
|
+
protected boolean isEmpty() {
|
939
|
+
return (this.contours == null);
|
940
|
+
}
|
941
|
+
|
942
|
+
/**
|
943
|
+
* Returns the bounding box of the polygon.
|
944
|
+
*
|
945
|
+
* @return
|
946
|
+
*/
|
947
|
+
protected RRectangle getBBox() {
|
948
|
+
if (this.contours == null) {
|
949
|
+
return new RRectangle();
|
950
|
+
} else if (this.contours.length == 1) {
|
951
|
+
|
952
|
+
float xmin = Float.MAX_VALUE;
|
953
|
+
float ymin = Float.MAX_VALUE;
|
954
|
+
float xmax = -Float.MAX_VALUE;
|
955
|
+
float ymax = -Float.MAX_VALUE;
|
956
|
+
|
957
|
+
if (this.contours[0].points == null) {
|
958
|
+
return new RRectangle();
|
959
|
+
}
|
960
|
+
|
961
|
+
for (RPoint point : this.contours[0].points) {
|
962
|
+
float x = point.getX();
|
963
|
+
float y = point.getY();
|
964
|
+
if (x < xmin) {
|
965
|
+
xmin = x;
|
999
966
|
}
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
/**
|
1004
|
-
* Return the number points of the first inner polygon
|
1005
|
-
*
|
1006
|
-
* @return
|
1007
|
-
*/
|
1008
|
-
protected int getNumPoints() {
|
1009
|
-
if (this.contours == null) {
|
1010
|
-
return 0;
|
967
|
+
if (x > xmax) {
|
968
|
+
xmax = x;
|
1011
969
|
}
|
1012
|
-
if (
|
1013
|
-
|
970
|
+
if (y < ymin) {
|
971
|
+
ymin = y;
|
1014
972
|
}
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
/**
|
1019
|
-
* Return the X value of the point at the index in the first inner polygon
|
1020
|
-
*
|
1021
|
-
* @param index
|
1022
|
-
* @return
|
1023
|
-
*/
|
1024
|
-
protected float getX(int index) {
|
1025
|
-
if (this.contours == null) {
|
1026
|
-
return 0;
|
973
|
+
if (y > ymax) {
|
974
|
+
ymax = y;
|
1027
975
|
}
|
1028
|
-
|
1029
|
-
}
|
976
|
+
}
|
1030
977
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
* @param index
|
1035
|
-
* @return
|
1036
|
-
*/
|
1037
|
-
protected float getY(int index) {
|
1038
|
-
if (this.contours == null) {
|
1039
|
-
return 0;
|
1040
|
-
}
|
1041
|
-
return this.contours[0].points[index].y;
|
978
|
+
return new RRectangle(xmin, ymin, (xmax - xmin), (ymax - ymin));
|
979
|
+
} else {
|
980
|
+
throw new UnsupportedOperationException("getBounds not supported on complex poly.");
|
1042
981
|
}
|
982
|
+
}
|
1043
983
|
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
984
|
+
/**
|
985
|
+
* Returns the polygon at this index.
|
986
|
+
*
|
987
|
+
* @param polyIndex
|
988
|
+
* @return
|
989
|
+
*/
|
990
|
+
protected RPolygon getInnerPoly(int polyIndex) {
|
991
|
+
return new RPolygon(this.contours[polyIndex]);
|
992
|
+
}
|
993
|
+
|
994
|
+
/**
|
995
|
+
* Returns the number of inner polygons - inner polygons are assumed to return
|
996
|
+
* one here.
|
997
|
+
*
|
998
|
+
* @return
|
999
|
+
*/
|
1000
|
+
protected int getNumInnerPoly() {
|
1001
|
+
if (this.contours == null) {
|
1002
|
+
return 0;
|
1056
1003
|
}
|
1004
|
+
return this.contours.length;
|
1005
|
+
}
|
1057
1006
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
if (this.contours == null || this.contours.length > 1) {
|
1067
|
-
throw new IllegalStateException("Cannot call on a poly made up of more than one poly.");
|
1068
|
-
}
|
1069
|
-
this.contours[0].isHole = isHole;
|
1007
|
+
/**
|
1008
|
+
* Return the number points of the first inner polygon
|
1009
|
+
*
|
1010
|
+
* @return
|
1011
|
+
*/
|
1012
|
+
protected int getNumPoints() {
|
1013
|
+
if (this.contours == null) {
|
1014
|
+
return 0;
|
1070
1015
|
}
|
1071
|
-
|
1072
|
-
|
1073
|
-
* Return true if the given inner polygon is contributing to the set
|
1074
|
-
* operation. This method should NOT be used outside the Clip algorithm.
|
1075
|
-
*
|
1076
|
-
* @param polyIndex
|
1077
|
-
* @return
|
1078
|
-
*/
|
1079
|
-
protected boolean isContributing(int polyIndex) {
|
1080
|
-
return this.contours[polyIndex].isContributing;
|
1016
|
+
if (this.contours[0].points == null) {
|
1017
|
+
return 0;
|
1081
1018
|
}
|
1019
|
+
return this.contours[0].points.length;
|
1020
|
+
}
|
1082
1021
|
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1022
|
+
/**
|
1023
|
+
* Return the X value of the point at the index in the first inner polygon
|
1024
|
+
*
|
1025
|
+
* @param index
|
1026
|
+
* @return
|
1027
|
+
*/
|
1028
|
+
protected float getX(int index) {
|
1029
|
+
if (this.contours == null) {
|
1030
|
+
return 0;
|
1031
|
+
}
|
1032
|
+
return this.contours[0].points[index].x;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
/**
|
1036
|
+
* Return the Y value of the point at the index in the first inner polygon
|
1037
|
+
*
|
1038
|
+
* @param index
|
1039
|
+
* @return
|
1040
|
+
*/
|
1041
|
+
protected float getY(int index) {
|
1042
|
+
if (this.contours == null) {
|
1043
|
+
return 0;
|
1044
|
+
}
|
1045
|
+
return this.contours[0].points[index].y;
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
/**
|
1049
|
+
* Return true if this polygon is a hole. Holes are assumed to be inner
|
1050
|
+
* polygons of a more complex polygon.
|
1051
|
+
*
|
1052
|
+
* @return
|
1053
|
+
* @throws IllegalStateException if called on a complex polygon.
|
1054
|
+
*/
|
1055
|
+
public boolean isHole() {
|
1056
|
+
if (this.contours == null || this.contours.length > 1) {
|
1057
|
+
throw new IllegalStateException("Cannot call on a poly made up of more than one poly.");
|
1058
|
+
}
|
1059
|
+
return this.contours[0].isHole;
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
/**
|
1063
|
+
* Set whether or not this polygon is a hole. Cannot be called on a complex
|
1064
|
+
* polygon.
|
1065
|
+
*
|
1066
|
+
* @param isHole
|
1067
|
+
* @throws IllegalStateException if called on a complex polygon.
|
1068
|
+
*/
|
1069
|
+
protected void setIsHole(boolean isHole) {
|
1070
|
+
if (this.contours == null || this.contours.length > 1) {
|
1071
|
+
throw new IllegalStateException("Cannot call on a poly made up of more than one poly.");
|
1072
|
+
}
|
1073
|
+
this.contours[0].isHole = isHole;
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
/**
|
1077
|
+
* Return true if the given inner polygon is contributing to the set
|
1078
|
+
* operation. This method should NOT be used outside the Clip algorithm.
|
1079
|
+
*
|
1080
|
+
* @param polyIndex
|
1081
|
+
* @return
|
1082
|
+
*/
|
1083
|
+
protected boolean isContributing(int polyIndex) {
|
1084
|
+
return this.contours[polyIndex].isContributing;
|
1085
|
+
}
|
1086
|
+
|
1087
|
+
/**
|
1088
|
+
* Set whether or not this inner polygon is constributing to the set
|
1089
|
+
* operation. This method should NOT be used outside the Clip algorithm.
|
1090
|
+
*
|
1091
|
+
* @param polyIndex
|
1092
|
+
* @param contributes
|
1093
|
+
*/
|
1094
|
+
protected void setContributing(int polyIndex, boolean contributes) {
|
1095
|
+
/*
|
1096
|
+
if( this.contours.length != 1 )
|
1097
|
+
{
|
1098
|
+
throw new IllegalStateException( "Only applies to polys of size 1" );
|
1099
|
+
}
|
1089
1100
|
*/
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
newcontours = new RContour[this.contours.length + 1];
|
1108
|
-
System.arraycopy(this.contours, 0, newcontours, 0, this.contours.length);
|
1109
|
-
newcontours[this.contours.length] = nextcontour;
|
1110
|
-
currentContour++;
|
1111
|
-
}
|
1112
|
-
this.contours = newcontours;
|
1113
|
-
}
|
1101
|
+
this.contours[polyIndex].isContributing = contributes;
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
private void append(RContour nextcontour) {
|
1105
|
+
RContour[] newcontours;
|
1106
|
+
if (contours == null) {
|
1107
|
+
newcontours = new RContour[1];
|
1108
|
+
newcontours[0] = nextcontour;
|
1109
|
+
currentContour = 0;
|
1110
|
+
} else {
|
1111
|
+
newcontours = new RContour[this.contours.length + 1];
|
1112
|
+
System.arraycopy(this.contours, 0, newcontours, 0, this.contours.length);
|
1113
|
+
newcontours[this.contours.length] = nextcontour;
|
1114
|
+
currentContour++;
|
1115
|
+
}
|
1116
|
+
this.contours = newcontours;
|
1117
|
+
}
|
1114
1118
|
}
|