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