1 Clazz.declarePackage ("java.awt");
\r
2 Clazz.load (["java.awt.Shape", "java.awt.geom.PathIterator"], "java.awt.Polygon", ["java.lang.IndexOutOfBoundsException", "$.NegativeArraySizeException", "java.util.Arrays", "java.awt.Rectangle", "jssun.awt.geom.Crossings"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
8 if (!Clazz.isClassDefined ("java.awt.Polygon.PolygonPathIterator")) {
\r
9 java.awt.Polygon.$Polygon$PolygonPathIterator$ ();
\r
11 Clazz.instantialize (this, arguments);
\r
12 }, java.awt, "Polygon", null, java.awt.Shape);
\r
13 Clazz.makeConstructor (c$,
\r
15 this.xpoints = Clazz.newIntArray (4, 0);
\r
16 this.ypoints = Clazz.newIntArray (4, 0);
\r
18 Clazz.makeConstructor (c$,
\r
19 function (xpoints, ypoints, npoints) {
\r
20 if (npoints > xpoints.length || npoints > ypoints.length) {
\r
21 throw new IndexOutOfBoundsException ("npoints > xpoints.length || npoints > ypoints.length");
\r
23 throw new NegativeArraySizeException ("npoints < 0");
\r
24 }this.npoints = npoints;
\r
25 this.xpoints = java.util.Arrays.copyOf (xpoints, npoints);
\r
26 this.ypoints = java.util.Arrays.copyOf (ypoints, npoints);
\r
28 Clazz.defineMethod (c$, "reset",
\r
33 Clazz.defineMethod (c$, "invalidate",
\r
37 Clazz.defineMethod (c$, "translate",
\r
38 function (deltaX, deltaY) {
\r
39 for (var i = 0; i < this.npoints; i++) {
\r
40 this.xpoints[i] += deltaX;
\r
41 this.ypoints[i] += deltaY;
\r
43 if (this.bounds != null) {
\r
44 this.bounds.translate (deltaX, deltaY);
\r
46 Clazz.defineMethod (c$, "calculateBounds",
\r
47 function (xpoints, ypoints, npoints) {
\r
48 var boundsMinX = 2147483647;
\r
49 var boundsMinY = 2147483647;
\r
50 var boundsMaxX = -2147483648;
\r
51 var boundsMaxY = -2147483648;
\r
52 for (var i = 0; i < npoints; i++) {
\r
54 boundsMinX = Math.min (boundsMinX, x);
\r
55 boundsMaxX = Math.max (boundsMaxX, x);
\r
57 boundsMinY = Math.min (boundsMinY, y);
\r
58 boundsMaxY = Math.max (boundsMaxY, y);
\r
60 this.bounds = new java.awt.Rectangle (boundsMinX, boundsMinY, boundsMaxX - boundsMinX, boundsMaxY - boundsMinY);
\r
62 Clazz.defineMethod (c$, "updateBounds",
\r
64 if (x < this.bounds.x) {
\r
65 this.bounds.width = this.bounds.width + (this.bounds.x - x);
\r
68 this.bounds.width = Math.max (this.bounds.width, x - this.bounds.x);
\r
69 }if (y < this.bounds.y) {
\r
70 this.bounds.height = this.bounds.height + (this.bounds.y - y);
\r
73 this.bounds.height = Math.max (this.bounds.height, y - this.bounds.y);
\r
75 Clazz.defineMethod (c$, "addPoint",
\r
77 if (this.npoints >= this.xpoints.length || this.npoints >= this.ypoints.length) {
\r
78 var newLength = this.npoints * 2;
\r
79 if (newLength < 4) {
\r
81 } else if ((newLength & (newLength - 1)) != 0) {
\r
82 newLength = Integer.highestOneBit (newLength);
\r
83 }this.xpoints = java.util.Arrays.copyOf (this.xpoints, newLength);
\r
84 this.ypoints = java.util.Arrays.copyOf (this.ypoints, newLength);
\r
85 }this.xpoints[this.npoints] = x;
\r
86 this.ypoints[this.npoints] = y;
\r
88 if (this.bounds != null) {
\r
89 this.updateBounds (x, y);
\r
91 Clazz.overrideMethod (c$, "getBounds",
\r
93 return this.getBoundingBox ();
\r
95 Clazz.defineMethod (c$, "getBoundingBox",
\r
97 if (this.npoints == 0) {
\r
98 return new java.awt.Rectangle ();
\r
99 }if (this.bounds == null) {
\r
100 this.calculateBounds (this.xpoints, this.ypoints, this.npoints);
\r
101 }return this.bounds.getBounds ();
\r
103 Clazz.defineMethod (c$, "contains",
\r
105 return this.contains (p.x, p.y);
\r
106 }, "java.awt.Point");
\r
107 Clazz.defineMethod (c$, "contains",
\r
109 return this.contains (x, y);
\r
111 Clazz.defineMethod (c$, "inside",
\r
113 return this.contains (x, y);
\r
115 Clazz.overrideMethod (c$, "getBounds2D",
\r
117 return this.getBounds ();
\r
119 Clazz.defineMethod (c$, "contains",
\r
121 if (this.npoints <= 2 || !this.getBoundingBox ().contains (x, y)) {
\r
124 var lastx = this.xpoints[this.npoints - 1];
\r
125 var lasty = this.ypoints[this.npoints - 1];
\r
128 for (var i = 0; i < this.npoints; lastx = curx, lasty = cury, i++) {
\r
129 curx = this.xpoints[i];
\r
130 cury = this.ypoints[i];
\r
131 if (cury == lasty) {
\r
134 if (curx < lastx) {
\r
144 if (cury < lasty) {
\r
145 if (y < cury || y >= lasty) {
\r
153 if (y < lasty || y >= cury) {
\r
158 }test1 = x - lastx;
\r
160 }if (test1 < (test2 / (lasty - cury) * (lastx - curx))) {
\r
163 return ((hits & 1) != 0);
\r
165 Clazz.defineMethod (c$, "getCrossings",
\r
166 function (xlo, ylo, xhi, yhi) {
\r
167 var cross = new jssun.awt.geom.Crossings.EvenOdd (xlo, ylo, xhi, yhi);
\r
168 var lastx = this.xpoints[this.npoints - 1];
\r
169 var lasty = this.ypoints[this.npoints - 1];
\r
172 for (var i = 0; i < this.npoints; i++) {
\r
173 curx = this.xpoints[i];
\r
174 cury = this.ypoints[i];
\r
175 if (cross.accumulateLine (lastx, lasty, curx, cury)) {
\r
182 Clazz.defineMethod (c$, "contains",
\r
184 return this.contains (p.getX (), p.getY ());
\r
185 }, "java.awt.geom.Point2D");
\r
186 Clazz.defineMethod (c$, "intersects",
\r
187 function (x, y, w, h) {
\r
188 if (this.npoints <= 0 || !this.getBoundingBox ().intersects (x, y, w, h)) {
\r
190 }var cross = this.getCrossings (x, y, x + w, y + h);
\r
191 return (cross == null || !cross.isEmpty ());
\r
193 Clazz.defineMethod (c$, "intersects",
\r
195 return this.intersects (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
\r
196 }, "java.awt.geom.Rectangle2D");
\r
197 Clazz.defineMethod (c$, "contains",
\r
198 function (x, y, w, h) {
\r
199 if (this.npoints <= 0 || !this.getBoundingBox ().intersects (x, y, w, h)) {
\r
201 }var cross = this.getCrossings (x, y, x + w, y + h);
\r
202 return (cross != null && cross.covers (y, y + h));
\r
204 Clazz.defineMethod (c$, "contains",
\r
206 return this.contains (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
\r
207 }, "java.awt.geom.Rectangle2D");
\r
208 Clazz.defineMethod (c$, "getPathIterator",
\r
210 return Clazz.innerTypeInstance (java.awt.Polygon.PolygonPathIterator, this, null, this, at);
\r
211 }, "java.awt.geom.AffineTransform");
\r
212 Clazz.defineMethod (c$, "getPathIterator",
\r
213 function (at, flatness) {
\r
214 return this.getPathIterator (at);
\r
215 }, "java.awt.geom.AffineTransform,~N");
\r
216 c$.$Polygon$PolygonPathIterator$ = function () {
\r
217 Clazz.pu$h(self.c$);
\r
218 c$ = Clazz.decorateAsClass (function () {
\r
219 Clazz.prepareCallback (this, arguments);
\r
221 this.transform = null;
\r
223 Clazz.instantialize (this, arguments);
\r
224 }, java.awt.Polygon, "PolygonPathIterator", null, java.awt.geom.PathIterator);
\r
225 Clazz.makeConstructor (c$,
\r
228 this.transform = b;
\r
229 if (a.npoints == 0) {
\r
231 }}, "java.awt.Polygon,java.awt.geom.AffineTransform");
\r
232 Clazz.overrideMethod (c$, "getWindingRule",
\r
236 Clazz.overrideMethod (c$, "isDone",
\r
238 return this.index > this.poly.npoints;
\r
240 Clazz.overrideMethod (c$, "next",
\r
244 Clazz.defineMethod (c$, "currentSegment",
\r
246 if (this.index >= this.poly.npoints) {
\r
248 }a[0] = this.poly.xpoints[this.index];
\r
249 a[1] = this.poly.ypoints[this.index];
\r
250 if (this.transform != null) {
\r
251 this.transform.transform (a, 0, a, 0, 1);
\r
252 }return (this.index == 0 ? 0 : 1);
\r
256 Clazz.defineStatics (c$,
\r