Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / geom / Area.js
1 Clazz.declarePackage ("java.awt.geom");
2 Clazz.load (["java.awt.Shape", "java.awt.geom.PathIterator", "java.util.Vector"], ["java.awt.geom.Area", "$.AreaIterator"], ["java.lang.NullPointerException", "java.util.NoSuchElementException", "java.awt.geom.FlatteningPathIterator", "$.Rectangle2D", "jssun.awt.geom.AreaOp", "$.Crossings", "$.Curve"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.curves = null;
5 this.cachedBounds = null;
6 Clazz.instantialize (this, arguments);
7 }, java.awt.geom, "Area", null, [java.awt.Shape, Cloneable]);
8 Clazz.makeConstructor (c$, 
9 function () {
10 this.curves = java.awt.geom.Area.EmptyCurves;
11 });
12 Clazz.makeConstructor (c$, 
13 function (s) {
14 if (Clazz.instanceOf (s, java.awt.geom.Area)) {
15 this.curves = (s).curves;
16 } else {
17 this.curves = java.awt.geom.Area.pathToCurves (s.getPathIterator (null));
18 }}, "java.awt.Shape");
19 c$.pathToCurves = Clazz.defineMethod (c$, "pathToCurves", 
20  function (pi) {
21 var curves =  new java.util.Vector ();
22 var windingRule = pi.getWindingRule ();
23 var coords =  Clazz.newDoubleArray (23, 0);
24 var movx = 0;
25 var movy = 0;
26 var curx = 0;
27 var cury = 0;
28 var newx;
29 var newy;
30 while (!pi.isDone ()) {
31 switch (pi.currentSegment (coords)) {
32 case 0:
33 jssun.awt.geom.Curve.insertLine (curves, curx, cury, movx, movy);
34 curx = movx = coords[0];
35 cury = movy = coords[1];
36 jssun.awt.geom.Curve.insertMove (curves, movx, movy);
37 break;
38 case 1:
39 newx = coords[0];
40 newy = coords[1];
41 jssun.awt.geom.Curve.insertLine (curves, curx, cury, newx, newy);
42 curx = newx;
43 cury = newy;
44 break;
45 case 2:
46 newx = coords[2];
47 newy = coords[3];
48 jssun.awt.geom.Curve.insertQuad (curves, curx, cury, coords);
49 curx = newx;
50 cury = newy;
51 break;
52 case 3:
53 newx = coords[4];
54 newy = coords[5];
55 jssun.awt.geom.Curve.insertCubic (curves, curx, cury, coords);
56 curx = newx;
57 cury = newy;
58 break;
59 case 4:
60 jssun.awt.geom.Curve.insertLine (curves, curx, cury, movx, movy);
61 curx = movx;
62 cury = movy;
63 break;
64 }
65 pi.next ();
66 }
67 jssun.awt.geom.Curve.insertLine (curves, curx, cury, movx, movy);
68 var operator;
69 if (windingRule == 0) {
70 operator =  new jssun.awt.geom.AreaOp.EOWindOp ();
71 } else {
72 operator =  new jssun.awt.geom.AreaOp.NZWindOp ();
73 }return operator.calculate (curves, java.awt.geom.Area.EmptyCurves);
74 }, "java.awt.geom.PathIterator");
75 Clazz.defineMethod (c$, "add", 
76 function (rhs) {
77 this.curves =  new jssun.awt.geom.AreaOp.AddOp ().calculate (this.curves, rhs.curves);
78 this.invalidateBounds ();
79 }, "java.awt.geom.Area");
80 Clazz.defineMethod (c$, "subtract", 
81 function (rhs) {
82 this.curves =  new jssun.awt.geom.AreaOp.SubOp ().calculate (this.curves, rhs.curves);
83 this.invalidateBounds ();
84 }, "java.awt.geom.Area");
85 Clazz.defineMethod (c$, "intersect", 
86 function (rhs) {
87 this.curves =  new jssun.awt.geom.AreaOp.IntOp ().calculate (this.curves, rhs.curves);
88 this.invalidateBounds ();
89 }, "java.awt.geom.Area");
90 Clazz.defineMethod (c$, "exclusiveOr", 
91 function (rhs) {
92 this.curves =  new jssun.awt.geom.AreaOp.XorOp ().calculate (this.curves, rhs.curves);
93 this.invalidateBounds ();
94 }, "java.awt.geom.Area");
95 Clazz.defineMethod (c$, "reset", 
96 function () {
97 this.curves =  new java.util.Vector ();
98 this.invalidateBounds ();
99 });
100 Clazz.defineMethod (c$, "isEmpty", 
101 function () {
102 return (this.curves.size () == 0);
103 });
104 Clazz.defineMethod (c$, "isPolygonal", 
105 function () {
106 var enum_ = this.curves.elements ();
107 while (enum_.hasMoreElements ()) {
108 if ((enum_.nextElement ()).getOrder () > 1) {
109 return false;
110 }}
111 return true;
112 });
113 Clazz.defineMethod (c$, "isRectangular", 
114 function () {
115 var size = this.curves.size ();
116 if (size == 0) {
117 return true;
118 }if (size > 3) {
119 return false;
120 }var c1 = this.curves.get (1);
121 var c2 = this.curves.get (2);
122 if (c1.getOrder () != 1 || c2.getOrder () != 1) {
123 return false;
124 }if (c1.getXTop () != c1.getXBot () || c2.getXTop () != c2.getXBot ()) {
125 return false;
126 }if (c1.getYTop () != c2.getYTop () || c1.getYBot () != c2.getYBot ()) {
127 return false;
128 }return true;
129 });
130 Clazz.defineMethod (c$, "isSingular", 
131 function () {
132 if (this.curves.size () < 3) {
133 return true;
134 }var enum_ = this.curves.elements ();
135 enum_.nextElement ();
136 while (enum_.hasMoreElements ()) {
137 if ((enum_.nextElement ()).getOrder () == 0) {
138 return false;
139 }}
140 return true;
141 });
142 Clazz.defineMethod (c$, "invalidateBounds", 
143  function () {
144 this.cachedBounds = null;
145 });
146 Clazz.defineMethod (c$, "getCachedBounds", 
147  function () {
148 if (this.cachedBounds != null) {
149 return this.cachedBounds;
150 }var r =  new java.awt.geom.Rectangle2D.Double ();
151 if (this.curves.size () > 0) {
152 var c = this.curves.get (0);
153 r.setRect (c.getX0 (), c.getY0 (), 0, 0);
154 for (var i = 1; i < this.curves.size (); i++) {
155 (this.curves.get (i)).enlarge (r);
156 }
157 }return (this.cachedBounds = r);
158 });
159 Clazz.overrideMethod (c$, "getBounds2D", 
160 function () {
161 return this.getCachedBounds ().getBounds2D ();
162 });
163 Clazz.overrideMethod (c$, "getBounds", 
164 function () {
165 return this.getCachedBounds ().getBounds ();
166 });
167 Clazz.overrideMethod (c$, "clone", 
168 function () {
169 return  new java.awt.geom.Area (this);
170 });
171 Clazz.defineMethod (c$, "equals", 
172 function (other) {
173 if (other === this) {
174 return true;
175 }if (other == null) {
176 return false;
177 }var c =  new jssun.awt.geom.AreaOp.XorOp ().calculate (this.curves, other.curves);
178 return c.isEmpty ();
179 }, "java.awt.geom.Area");
180 Clazz.defineMethod (c$, "transform", 
181 function (t) {
182 if (t == null) {
183 throw  new NullPointerException ("transform must not be null");
184 }this.curves = java.awt.geom.Area.pathToCurves (this.getPathIterator (t));
185 this.invalidateBounds ();
186 }, "java.awt.geom.AffineTransform");
187 Clazz.defineMethod (c$, "createTransformedArea", 
188 function (t) {
189 var a =  new java.awt.geom.Area (this);
190 a.transform (t);
191 return a;
192 }, "java.awt.geom.AffineTransform");
193 Clazz.defineMethod (c$, "contains", 
194 function (x, y) {
195 if (!this.getCachedBounds ().contains (x, y)) {
196 return false;
197 }var enum_ = this.curves.elements ();
198 var crossings = 0;
199 while (enum_.hasMoreElements ()) {
200 var c = enum_.nextElement ();
201 crossings += c.crossingsFor (x, y);
202 }
203 return ((crossings & 1) == 1);
204 }, "~N,~N");
205 Clazz.defineMethod (c$, "contains", 
206 function (p) {
207 return this.contains (p.getX (), p.getY ());
208 }, "java.awt.geom.Point2D");
209 Clazz.defineMethod (c$, "contains", 
210 function (x, y, w, h) {
211 if (w < 0 || h < 0) {
212 return false;
213 }if (!this.getCachedBounds ().contains (x, y, w, h)) {
214 return false;
215 }var c = jssun.awt.geom.Crossings.findCrossings (this.curves, x, y, x + w, y + h);
216 return (c != null && c.covers (y, y + h));
217 }, "~N,~N,~N,~N");
218 Clazz.defineMethod (c$, "contains", 
219 function (r) {
220 return this.contains (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
221 }, "java.awt.geom.Rectangle2D");
222 Clazz.defineMethod (c$, "intersects", 
223 function (x, y, w, h) {
224 if (w < 0 || h < 0) {
225 return false;
226 }if (!this.getCachedBounds ().intersects (x, y, w, h)) {
227 return false;
228 }var c = jssun.awt.geom.Crossings.findCrossings (this.curves, x, y, x + w, y + h);
229 return (c == null || !c.isEmpty ());
230 }, "~N,~N,~N,~N");
231 Clazz.defineMethod (c$, "intersects", 
232 function (r) {
233 return this.intersects (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
234 }, "java.awt.geom.Rectangle2D");
235 Clazz.defineMethod (c$, "getPathIterator", 
236 function (at) {
237 return  new java.awt.geom.AreaIterator (this.curves, at);
238 }, "java.awt.geom.AffineTransform");
239 Clazz.defineMethod (c$, "getPathIterator", 
240 function (at, flatness) {
241 return  new java.awt.geom.FlatteningPathIterator (this.getPathIterator (at), flatness);
242 }, "java.awt.geom.AffineTransform,~N");
243 c$.EmptyCurves = c$.prototype.EmptyCurves =  new java.util.Vector ();
244 c$ = Clazz.decorateAsClass (function () {
245 this.transform = null;
246 this.curves = null;
247 this.index = 0;
248 this.prevcurve = null;
249 this.thiscurve = null;
250 Clazz.instantialize (this, arguments);
251 }, java.awt.geom, "AreaIterator", null, java.awt.geom.PathIterator);
252 Clazz.makeConstructor (c$, 
253 function (curves, at) {
254 this.curves = curves;
255 this.transform = at;
256 if (curves.size () >= 1) {
257 this.thiscurve = curves.get (0);
258 }}, "java.util.Vector,java.awt.geom.AffineTransform");
259 Clazz.overrideMethod (c$, "getWindingRule", 
260 function () {
261 return 1;
262 });
263 Clazz.overrideMethod (c$, "isDone", 
264 function () {
265 return (this.prevcurve == null && this.thiscurve == null);
266 });
267 Clazz.overrideMethod (c$, "next", 
268 function () {
269 if (this.prevcurve != null) {
270 this.prevcurve = null;
271 } else {
272 this.prevcurve = this.thiscurve;
273 this.index++;
274 if (this.index < this.curves.size ()) {
275 this.thiscurve = this.curves.get (this.index);
276 if (this.thiscurve.getOrder () != 0 && this.prevcurve.getX1 () == this.thiscurve.getX0 () && this.prevcurve.getY1 () == this.thiscurve.getY0 ()) {
277 this.prevcurve = null;
278 }} else {
279 this.thiscurve = null;
280 }}});
281 Clazz.defineMethod (c$, "currentSegment", 
282 function (coords) {
283 var dcoords =  Clazz.newDoubleArray (6, 0);
284 var segtype = this.currentSegment (dcoords);
285 var numpoints = (segtype == 4 ? 0 : (segtype == 2 ? 2 : (segtype == 3 ? 3 : 1)));
286 for (var i = 0; i < numpoints * 2; i++) {
287 coords[i] = dcoords[i];
288 }
289 return segtype;
290 }, "~A");
291 Clazz.defineMethod (c$, "currentSegment", 
292 function (coords) {
293 var segtype;
294 var numpoints;
295 if (this.prevcurve != null) {
296 if (this.thiscurve == null || this.thiscurve.getOrder () == 0) {
297 return 4;
298 }coords[0] = this.thiscurve.getX0 ();
299 coords[1] = this.thiscurve.getY0 ();
300 segtype = 1;
301 numpoints = 1;
302 } else if (this.thiscurve == null) {
303 throw  new java.util.NoSuchElementException ("area iterator out of bounds");
304 } else {
305 segtype = this.thiscurve.getSegment (coords);
306 numpoints = this.thiscurve.getOrder ();
307 if (numpoints == 0) {
308 numpoints = 1;
309 }}if (this.transform != null) {
310 this.transform.transform (coords, 0, coords, 0, numpoints);
311 }return segtype;
312 }, "~A");
313 });