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