Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / geom / ArcIterator.js
1 Clazz.declarePackage ("java.awt.geom");
2 Clazz.load (["java.awt.geom.PathIterator"], "java.awt.geom.ArcIterator", ["java.util.NoSuchElementException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.x = 0;
5 this.y = 0;
6 this.w = 0;
7 this.h = 0;
8 this.angStRad = 0;
9 this.increment = 0;
10 this.cv = 0;
11 this.affine = null;
12 this.index = 0;
13 this.arcSegs = 0;
14 this.lineSegs = 0;
15 Clazz.instantialize (this, arguments);
16 }, java.awt.geom, "ArcIterator", null, java.awt.geom.PathIterator);
17 Clazz.makeConstructor (c$, 
18 function (a, at) {
19 this.w = a.getWidth () / 2;
20 this.h = a.getHeight () / 2;
21 this.x = a.getX () + this.w;
22 this.y = a.getY () + this.h;
23 this.angStRad = -Math.toRadians (a.getAngleStart ());
24 this.affine = at;
25 var ext = -a.getAngleExtent ();
26 if (ext >= 360.0 || ext <= -360) {
27 this.arcSegs = 4;
28 this.increment = 1.5707963267948966;
29 this.cv = 0.5522847498307933;
30 if (ext < 0) {
31 this.increment = -this.increment;
32 this.cv = -this.cv;
33 }} else {
34 this.arcSegs = Clazz.doubleToInt (Math.ceil (Math.abs (ext) / 90.0));
35 this.increment = Math.toRadians (ext / this.arcSegs);
36 this.cv = java.awt.geom.ArcIterator.btan (this.increment);
37 if (this.cv == 0) {
38 this.arcSegs = 0;
39 }}switch (a.getArcType ()) {
40 case 0:
41 this.lineSegs = 0;
42 break;
43 case 1:
44 this.lineSegs = 1;
45 break;
46 case 2:
47 this.lineSegs = 2;
48 break;
49 }
50 if (this.w < 0 || this.h < 0) {
51 this.arcSegs = this.lineSegs = -1;
52 }}, "java.awt.geom.Arc2D,java.awt.geom.AffineTransform");
53 Clazz.overrideMethod (c$, "getWindingRule", 
54 function () {
55 return 1;
56 });
57 Clazz.overrideMethod (c$, "isDone", 
58 function () {
59 return this.index > this.arcSegs + this.lineSegs;
60 });
61 Clazz.overrideMethod (c$, "next", 
62 function () {
63 this.index++;
64 });
65 c$.btan = Clazz.defineMethod (c$, "btan", 
66  function (increment) {
67 increment /= 2.0;
68 return 1.3333333333333333 * Math.sin (increment) / (1.0 + Math.cos (increment));
69 }, "~N");
70 Clazz.defineMethod (c$, "currentSegment", 
71 function (coords) {
72 if (this.isDone ()) {
73 throw  new java.util.NoSuchElementException ("arc iterator out of bounds");
74 }var angle = this.angStRad;
75 if (this.index == 0) {
76 coords[0] = (this.x + Math.cos (angle) * this.w);
77 coords[1] = (this.y + Math.sin (angle) * this.h);
78 if (this.affine != null) {
79 this.affine.transform (coords, 0, coords, 0, 1);
80 }return 0;
81 }if (this.index > this.arcSegs) {
82 if (this.index == this.arcSegs + this.lineSegs) {
83 return 4;
84 }coords[0] = this.x;
85 coords[1] = this.y;
86 if (this.affine != null) {
87 this.affine.transform (coords, 0, coords, 0, 1);
88 }return 1;
89 }angle += this.increment * (this.index - 1);
90 var relx = Math.cos (angle);
91 var rely = Math.sin (angle);
92 coords[0] = (this.x + (relx - this.cv * rely) * this.w);
93 coords[1] = (this.y + (rely + this.cv * relx) * this.h);
94 angle += this.increment;
95 relx = Math.cos (angle);
96 rely = Math.sin (angle);
97 coords[2] = (this.x + (relx + this.cv * rely) * this.w);
98 coords[3] = (this.y + (rely - this.cv * relx) * this.h);
99 coords[4] = (this.x + relx * this.w);
100 coords[5] = (this.y + rely * this.h);
101 if (this.affine != null) {
102 this.affine.transform (coords, 0, coords, 0, 3);
103 }return 3;
104 }, "~A");
105 Clazz.defineMethod (c$, "currentSegment", 
106 function (coords) {
107 if (this.isDone ()) {
108 throw  new java.util.NoSuchElementException ("arc iterator out of bounds");
109 }var angle = this.angStRad;
110 if (this.index == 0) {
111 coords[0] = this.x + Math.cos (angle) * this.w;
112 coords[1] = this.y + Math.sin (angle) * this.h;
113 if (this.affine != null) {
114 this.affine.transform (coords, 0, coords, 0, 1);
115 }return 0;
116 }if (this.index > this.arcSegs) {
117 if (this.index == this.arcSegs + this.lineSegs) {
118 return 4;
119 }coords[0] = this.x;
120 coords[1] = this.y;
121 if (this.affine != null) {
122 this.affine.transform (coords, 0, coords, 0, 1);
123 }return 1;
124 }angle += this.increment * (this.index - 1);
125 var relx = Math.cos (angle);
126 var rely = Math.sin (angle);
127 coords[0] = this.x + (relx - this.cv * rely) * this.w;
128 coords[1] = this.y + (rely + this.cv * relx) * this.h;
129 angle += this.increment;
130 relx = Math.cos (angle);
131 rely = Math.sin (angle);
132 coords[2] = this.x + (relx + this.cv * rely) * this.w;
133 coords[3] = this.y + (rely - this.cv * relx) * this.h;
134 coords[4] = this.x + relx * this.w;
135 coords[5] = this.y + rely * this.h;
136 if (this.affine != null) {
137 this.affine.transform (coords, 0, coords, 0, 3);
138 }return 3;
139 }, "~A");
140 });