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