Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / Polygon.js
index 969c5d9..97658b4 100644 (file)
-Clazz.declarePackage ("java.awt");\r
-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
-c$ = Clazz.decorateAsClass (function () {\r
-this.npoints = 0;\r
-this.xpoints = null;\r
-this.ypoints = null;\r
-this.bounds = null;\r
-if (!Clazz.isClassDefined ("java.awt.Polygon.PolygonPathIterator")) {\r
-java.awt.Polygon.$Polygon$PolygonPathIterator$ ();\r
-}\r
-Clazz.instantialize (this, arguments);\r
-}, java.awt, "Polygon", null, java.awt.Shape);\r
-Clazz.makeConstructor (c$, \r
-function () {\r
-this.xpoints =  Clazz.newIntArray (4, 0);\r
-this.ypoints =  Clazz.newIntArray (4, 0);\r
-});\r
-Clazz.makeConstructor (c$, \r
-function (xpoints, ypoints, npoints) {\r
-if (npoints > xpoints.length || npoints > ypoints.length) {\r
-throw  new IndexOutOfBoundsException ("npoints > xpoints.length || npoints > ypoints.length");\r
-}if (npoints < 0) {\r
-throw  new NegativeArraySizeException ("npoints < 0");\r
-}this.npoints = npoints;\r
-this.xpoints = java.util.Arrays.copyOf (xpoints, npoints);\r
-this.ypoints = java.util.Arrays.copyOf (ypoints, npoints);\r
-}, "~A,~A,~N");\r
-Clazz.defineMethod (c$, "reset", \r
-function () {\r
-this.npoints = 0;\r
-this.bounds = null;\r
-});\r
-Clazz.defineMethod (c$, "invalidate", \r
-function () {\r
-this.bounds = null;\r
-});\r
-Clazz.defineMethod (c$, "translate", \r
-function (deltaX, deltaY) {\r
-for (var i = 0; i < this.npoints; i++) {\r
-this.xpoints[i] += deltaX;\r
-this.ypoints[i] += deltaY;\r
-}\r
-if (this.bounds != null) {\r
-this.bounds.translate (deltaX, deltaY);\r
-}}, "~N,~N");\r
-Clazz.defineMethod (c$, "calculateBounds", \r
-function (xpoints, ypoints, npoints) {\r
-var boundsMinX = 2147483647;\r
-var boundsMinY = 2147483647;\r
-var boundsMaxX = -2147483648;\r
-var boundsMaxY = -2147483648;\r
-for (var i = 0; i < npoints; i++) {\r
-var x = xpoints[i];\r
-boundsMinX = Math.min (boundsMinX, x);\r
-boundsMaxX = Math.max (boundsMaxX, x);\r
-var y = ypoints[i];\r
-boundsMinY = Math.min (boundsMinY, y);\r
-boundsMaxY = Math.max (boundsMaxY, y);\r
-}\r
-this.bounds =  new java.awt.Rectangle (boundsMinX, boundsMinY, boundsMaxX - boundsMinX, boundsMaxY - boundsMinY);\r
-}, "~A,~A,~N");\r
-Clazz.defineMethod (c$, "updateBounds", \r
-function (x, y) {\r
-if (x < this.bounds.x) {\r
-this.bounds.width = this.bounds.width + (this.bounds.x - x);\r
-this.bounds.x = x;\r
-} else {\r
-this.bounds.width = Math.max (this.bounds.width, x - this.bounds.x);\r
-}if (y < this.bounds.y) {\r
-this.bounds.height = this.bounds.height + (this.bounds.y - y);\r
-this.bounds.y = y;\r
-} else {\r
-this.bounds.height = Math.max (this.bounds.height, y - this.bounds.y);\r
-}}, "~N,~N");\r
-Clazz.defineMethod (c$, "addPoint", \r
-function (x, y) {\r
-if (this.npoints >= this.xpoints.length || this.npoints >= this.ypoints.length) {\r
-var newLength = this.npoints * 2;\r
-if (newLength < 4) {\r
-newLength = 4;\r
-} else if ((newLength & (newLength - 1)) != 0) {\r
-newLength = Integer.highestOneBit (newLength);\r
-}this.xpoints = java.util.Arrays.copyOf (this.xpoints, newLength);\r
-this.ypoints = java.util.Arrays.copyOf (this.ypoints, newLength);\r
-}this.xpoints[this.npoints] = x;\r
-this.ypoints[this.npoints] = y;\r
-this.npoints++;\r
-if (this.bounds != null) {\r
-this.updateBounds (x, y);\r
-}}, "~N,~N");\r
-Clazz.overrideMethod (c$, "getBounds", \r
-function () {\r
-return this.getBoundingBox ();\r
-});\r
-Clazz.defineMethod (c$, "getBoundingBox", \r
-function () {\r
-if (this.npoints == 0) {\r
-return  new java.awt.Rectangle ();\r
-}if (this.bounds == null) {\r
-this.calculateBounds (this.xpoints, this.ypoints, this.npoints);\r
-}return this.bounds.getBounds ();\r
-});\r
-Clazz.defineMethod (c$, "contains", \r
-function (p) {\r
-return this.contains (p.x, p.y);\r
-}, "java.awt.Point");\r
-Clazz.defineMethod (c$, "contains", \r
-function (x, y) {\r
-return this.contains (x, y);\r
-}, "~N,~N");\r
-Clazz.defineMethod (c$, "inside", \r
-function (x, y) {\r
-return this.contains (x, y);\r
-}, "~N,~N");\r
-Clazz.overrideMethod (c$, "getBounds2D", \r
-function () {\r
-return this.getBounds ();\r
-});\r
-Clazz.defineMethod (c$, "contains", \r
-function (x, y) {\r
-if (this.npoints <= 2 || !this.getBoundingBox ().contains (x, y)) {\r
-return false;\r
-}var hits = 0;\r
-var lastx = this.xpoints[this.npoints - 1];\r
-var lasty = this.ypoints[this.npoints - 1];\r
-var curx;\r
-var cury;\r
-for (var i = 0; i < this.npoints; lastx = curx, lasty = cury, i++) {\r
-curx = this.xpoints[i];\r
-cury = this.ypoints[i];\r
-if (cury == lasty) {\r
-continue;\r
-}var leftx;\r
-if (curx < lastx) {\r
-if (x >= lastx) {\r
-continue;\r
-}leftx = curx;\r
-} else {\r
-if (x >= curx) {\r
-continue;\r
-}leftx = lastx;\r
-}var test1;\r
-var test2;\r
-if (cury < lasty) {\r
-if (y < cury || y >= lasty) {\r
-continue;\r
-}if (x < leftx) {\r
-hits++;\r
-continue;\r
-}test1 = x - curx;\r
-test2 = y - cury;\r
-} else {\r
-if (y < lasty || y >= cury) {\r
-continue;\r
-}if (x < leftx) {\r
-hits++;\r
-continue;\r
-}test1 = x - lastx;\r
-test2 = y - lasty;\r
-}if (test1 < (test2 / (lasty - cury) * (lastx - curx))) {\r
-hits++;\r
-}}\r
-return ((hits & 1) != 0);\r
-}, "~N,~N");\r
-Clazz.defineMethod (c$, "getCrossings", \r
- function (xlo, ylo, xhi, yhi) {\r
-var cross =  new jssun.awt.geom.Crossings.EvenOdd (xlo, ylo, xhi, yhi);\r
-var lastx = this.xpoints[this.npoints - 1];\r
-var lasty = this.ypoints[this.npoints - 1];\r
-var curx;\r
-var cury;\r
-for (var i = 0; i < this.npoints; i++) {\r
-curx = this.xpoints[i];\r
-cury = this.ypoints[i];\r
-if (cross.accumulateLine (lastx, lasty, curx, cury)) {\r
-return null;\r
-}lastx = curx;\r
-lasty = cury;\r
-}\r
-return cross;\r
-}, "~N,~N,~N,~N");\r
-Clazz.defineMethod (c$, "contains", \r
-function (p) {\r
-return this.contains (p.getX (), p.getY ());\r
-}, "java.awt.geom.Point2D");\r
-Clazz.defineMethod (c$, "intersects", \r
-function (x, y, w, h) {\r
-if (this.npoints <= 0 || !this.getBoundingBox ().intersects (x, y, w, h)) {\r
-return false;\r
-}var cross = this.getCrossings (x, y, x + w, y + h);\r
-return (cross == null || !cross.isEmpty ());\r
-}, "~N,~N,~N,~N");\r
-Clazz.defineMethod (c$, "intersects", \r
-function (r) {\r
-return this.intersects (r.getX (), r.getY (), r.getWidth (), r.getHeight ());\r
-}, "java.awt.geom.Rectangle2D");\r
-Clazz.defineMethod (c$, "contains", \r
-function (x, y, w, h) {\r
-if (this.npoints <= 0 || !this.getBoundingBox ().intersects (x, y, w, h)) {\r
-return false;\r
-}var cross = this.getCrossings (x, y, x + w, y + h);\r
-return (cross != null && cross.covers (y, y + h));\r
-}, "~N,~N,~N,~N");\r
-Clazz.defineMethod (c$, "contains", \r
-function (r) {\r
-return this.contains (r.getX (), r.getY (), r.getWidth (), r.getHeight ());\r
-}, "java.awt.geom.Rectangle2D");\r
-Clazz.defineMethod (c$, "getPathIterator", \r
-function (at) {\r
-return Clazz.innerTypeInstance (java.awt.Polygon.PolygonPathIterator, this, null, this, at);\r
-}, "java.awt.geom.AffineTransform");\r
-Clazz.defineMethod (c$, "getPathIterator", \r
-function (at, flatness) {\r
-return this.getPathIterator (at);\r
-}, "java.awt.geom.AffineTransform,~N");\r
-c$.$Polygon$PolygonPathIterator$ = function () {\r
-Clazz.pu$h(self.c$);\r
-c$ = Clazz.decorateAsClass (function () {\r
-Clazz.prepareCallback (this, arguments);\r
-this.poly = null;\r
-this.transform = null;\r
-this.index = 0;\r
-Clazz.instantialize (this, arguments);\r
-}, java.awt.Polygon, "PolygonPathIterator", null, java.awt.geom.PathIterator);\r
-Clazz.makeConstructor (c$, \r
-function (a, b) {\r
-this.poly = a;\r
-this.transform = b;\r
-if (a.npoints == 0) {\r
-this.index = 1;\r
-}}, "java.awt.Polygon,java.awt.geom.AffineTransform");\r
-Clazz.overrideMethod (c$, "getWindingRule", \r
-function () {\r
-return 0;\r
-});\r
-Clazz.overrideMethod (c$, "isDone", \r
-function () {\r
-return this.index > this.poly.npoints;\r
-});\r
-Clazz.overrideMethod (c$, "next", \r
-function () {\r
-this.index++;\r
-});\r
-Clazz.defineMethod (c$, "currentSegment", \r
-function (a) {\r
-if (this.index >= this.poly.npoints) {\r
-return 4;\r
-}a[0] = this.poly.xpoints[this.index];\r
-a[1] = this.poly.ypoints[this.index];\r
-if (this.transform != null) {\r
-this.transform.transform (a, 0, a, 0, 1);\r
-}return (this.index == 0 ? 0 : 1);\r
-}, "~A");\r
-c$ = Clazz.p0p ();\r
-};\r
-Clazz.defineStatics (c$,\r
-"MIN_LENGTH", 4);\r
-});\r
+Clazz.declarePackage ("java.awt");
+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 () {
+c$ = Clazz.decorateAsClass (function () {
+this.npoints = 0;
+this.xpoints = null;
+this.ypoints = null;
+this.bounds = null;
+if (!Clazz.isClassDefined ("java.awt.Polygon.PolygonPathIterator")) {
+java.awt.Polygon.$Polygon$PolygonPathIterator$ ();
+}
+Clazz.instantialize (this, arguments);
+}, java.awt, "Polygon", null, java.awt.Shape);
+Clazz.makeConstructor (c$, 
+function () {
+this.xpoints =  Clazz.newIntArray (4, 0);
+this.ypoints =  Clazz.newIntArray (4, 0);
+});
+Clazz.makeConstructor (c$, 
+function (xpoints, ypoints, npoints) {
+if (npoints > xpoints.length || npoints > ypoints.length) {
+throw  new IndexOutOfBoundsException ("npoints > xpoints.length || npoints > ypoints.length");
+}if (npoints < 0) {
+throw  new NegativeArraySizeException ("npoints < 0");
+}this.npoints = npoints;
+this.xpoints = java.util.Arrays.copyOf (xpoints, npoints);
+this.ypoints = java.util.Arrays.copyOf (ypoints, npoints);
+}, "~A,~A,~N");
+Clazz.defineMethod (c$, "reset", 
+function () {
+this.npoints = 0;
+this.bounds = null;
+});
+Clazz.defineMethod (c$, "invalidate", 
+function () {
+this.bounds = null;
+});
+Clazz.defineMethod (c$, "translate", 
+function (deltaX, deltaY) {
+for (var i = 0; i < this.npoints; i++) {
+this.xpoints[i] += deltaX;
+this.ypoints[i] += deltaY;
+}
+if (this.bounds != null) {
+this.bounds.translate (deltaX, deltaY);
+}}, "~N,~N");
+Clazz.defineMethod (c$, "calculateBounds", 
+function (xpoints, ypoints, npoints) {
+var boundsMinX = 2147483647;
+var boundsMinY = 2147483647;
+var boundsMaxX = -2147483648;
+var boundsMaxY = -2147483648;
+for (var i = 0; i < npoints; i++) {
+var x = xpoints[i];
+boundsMinX = Math.min (boundsMinX, x);
+boundsMaxX = Math.max (boundsMaxX, x);
+var y = ypoints[i];
+boundsMinY = Math.min (boundsMinY, y);
+boundsMaxY = Math.max (boundsMaxY, y);
+}
+this.bounds =  new java.awt.Rectangle (boundsMinX, boundsMinY, boundsMaxX - boundsMinX, boundsMaxY - boundsMinY);
+}, "~A,~A,~N");
+Clazz.defineMethod (c$, "updateBounds", 
+function (x, y) {
+if (x < this.bounds.x) {
+this.bounds.width = this.bounds.width + (this.bounds.x - x);
+this.bounds.x = x;
+} else {
+this.bounds.width = Math.max (this.bounds.width, x - this.bounds.x);
+}if (y < this.bounds.y) {
+this.bounds.height = this.bounds.height + (this.bounds.y - y);
+this.bounds.y = y;
+} else {
+this.bounds.height = Math.max (this.bounds.height, y - this.bounds.y);
+}}, "~N,~N");
+Clazz.defineMethod (c$, "addPoint", 
+function (x, y) {
+if (this.npoints >= this.xpoints.length || this.npoints >= this.ypoints.length) {
+var newLength = this.npoints * 2;
+if (newLength < 4) {
+newLength = 4;
+} else if ((newLength & (newLength - 1)) != 0) {
+newLength = Integer.highestOneBit (newLength);
+}this.xpoints = java.util.Arrays.copyOf (this.xpoints, newLength);
+this.ypoints = java.util.Arrays.copyOf (this.ypoints, newLength);
+}this.xpoints[this.npoints] = x;
+this.ypoints[this.npoints] = y;
+this.npoints++;
+if (this.bounds != null) {
+this.updateBounds (x, y);
+}}, "~N,~N");
+Clazz.overrideMethod (c$, "getBounds", 
+function () {
+return this.getBoundingBox ();
+});
+Clazz.defineMethod (c$, "getBoundingBox", 
+function () {
+if (this.npoints == 0) {
+return  new java.awt.Rectangle ();
+}if (this.bounds == null) {
+this.calculateBounds (this.xpoints, this.ypoints, this.npoints);
+}return this.bounds.getBounds ();
+});
+Clazz.defineMethod (c$, "contains", 
+function (p) {
+return this.contains (p.x, p.y);
+}, "java.awt.Point");
+Clazz.defineMethod (c$, "contains", 
+function (x, y) {
+return this.contains (x, y);
+}, "~N,~N");
+Clazz.defineMethod (c$, "inside", 
+function (x, y) {
+return this.contains (x, y);
+}, "~N,~N");
+Clazz.overrideMethod (c$, "getBounds2D", 
+function () {
+return this.getBounds ();
+});
+Clazz.defineMethod (c$, "contains", 
+function (x, y) {
+if (this.npoints <= 2 || !this.getBoundingBox ().contains (x, y)) {
+return false;
+}var hits = 0;
+var lastx = this.xpoints[this.npoints - 1];
+var lasty = this.ypoints[this.npoints - 1];
+var curx;
+var cury;
+for (var i = 0; i < this.npoints; lastx = curx, lasty = cury, i++) {
+curx = this.xpoints[i];
+cury = this.ypoints[i];
+if (cury == lasty) {
+continue;
+}var leftx;
+if (curx < lastx) {
+if (x >= lastx) {
+continue;
+}leftx = curx;
+} else {
+if (x >= curx) {
+continue;
+}leftx = lastx;
+}var test1;
+var test2;
+if (cury < lasty) {
+if (y < cury || y >= lasty) {
+continue;
+}if (x < leftx) {
+hits++;
+continue;
+}test1 = x - curx;
+test2 = y - cury;
+} else {
+if (y < lasty || y >= cury) {
+continue;
+}if (x < leftx) {
+hits++;
+continue;
+}test1 = x - lastx;
+test2 = y - lasty;
+}if (test1 < (test2 / (lasty - cury) * (lastx - curx))) {
+hits++;
+}}
+return ((hits & 1) != 0);
+}, "~N,~N");
+Clazz.defineMethod (c$, "getCrossings", 
+ function (xlo, ylo, xhi, yhi) {
+var cross =  new jssun.awt.geom.Crossings.EvenOdd (xlo, ylo, xhi, yhi);
+var lastx = this.xpoints[this.npoints - 1];
+var lasty = this.ypoints[this.npoints - 1];
+var curx;
+var cury;
+for (var i = 0; i < this.npoints; i++) {
+curx = this.xpoints[i];
+cury = this.ypoints[i];
+if (cross.accumulateLine (lastx, lasty, curx, cury)) {
+return null;
+}lastx = curx;
+lasty = cury;
+}
+return cross;
+}, "~N,~N,~N,~N");
+Clazz.defineMethod (c$, "contains", 
+function (p) {
+return this.contains (p.getX (), p.getY ());
+}, "java.awt.geom.Point2D");
+Clazz.defineMethod (c$, "intersects", 
+function (x, y, w, h) {
+if (this.npoints <= 0 || !this.getBoundingBox ().intersects (x, y, w, h)) {
+return false;
+}var cross = this.getCrossings (x, y, x + w, y + h);
+return (cross == null || !cross.isEmpty ());
+}, "~N,~N,~N,~N");
+Clazz.defineMethod (c$, "intersects", 
+function (r) {
+return this.intersects (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
+}, "java.awt.geom.Rectangle2D");
+Clazz.defineMethod (c$, "contains", 
+function (x, y, w, h) {
+if (this.npoints <= 0 || !this.getBoundingBox ().intersects (x, y, w, h)) {
+return false;
+}var cross = this.getCrossings (x, y, x + w, y + h);
+return (cross != null && cross.covers (y, y + h));
+}, "~N,~N,~N,~N");
+Clazz.defineMethod (c$, "contains", 
+function (r) {
+return this.contains (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
+}, "java.awt.geom.Rectangle2D");
+Clazz.defineMethod (c$, "getPathIterator", 
+function (at) {
+return Clazz.innerTypeInstance (java.awt.Polygon.PolygonPathIterator, this, null, this, at);
+}, "java.awt.geom.AffineTransform");
+Clazz.defineMethod (c$, "getPathIterator", 
+function (at, flatness) {
+return this.getPathIterator (at);
+}, "java.awt.geom.AffineTransform,~N");
+c$.$Polygon$PolygonPathIterator$ = function () {
+Clazz.pu$h(self.c$);
+c$ = Clazz.decorateAsClass (function () {
+Clazz.prepareCallback (this, arguments);
+this.poly = null;
+this.transform = null;
+this.index = 0;
+Clazz.instantialize (this, arguments);
+}, java.awt.Polygon, "PolygonPathIterator", null, java.awt.geom.PathIterator);
+Clazz.makeConstructor (c$, 
+function (a, b) {
+this.poly = a;
+this.transform = b;
+if (a.npoints == 0) {
+this.index = 1;
+}}, "java.awt.Polygon,java.awt.geom.AffineTransform");
+Clazz.overrideMethod (c$, "getWindingRule", 
+function () {
+return 0;
+});
+Clazz.overrideMethod (c$, "isDone", 
+function () {
+return this.index > this.poly.npoints;
+});
+Clazz.overrideMethod (c$, "next", 
+function () {
+this.index++;
+});
+Clazz.defineMethod (c$, "currentSegment", 
+function (a) {
+if (this.index >= this.poly.npoints) {
+return 4;
+}a[0] = this.poly.xpoints[this.index];
+a[1] = this.poly.ypoints[this.index];
+if (this.transform != null) {
+this.transform.transform (a, 0, a, 0, 1);
+}return (this.index == 0 ? 0 : 1);
+}, "~A");
+c$ = Clazz.p0p ();
+};
+Clazz.defineStatics (c$,
+"MIN_LENGTH", 4);
+});