JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / geom / FlatteningPathIterator.js
1 Clazz.declarePackage ("java.awt.geom");\r
2 Clazz.load (["java.awt.geom.PathIterator"], "java.awt.geom.FlatteningPathIterator", ["java.lang.IllegalArgumentException", "java.util.NoSuchElementException", "java.awt.geom.CubicCurve2D", "$.QuadCurve2D"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.src = null;\r
5 this.squareflat = 0;\r
6 this.limit = 0;\r
7 this.hold = null;\r
8 this.curx = 0;\r
9 this.cury = 0;\r
10 this.movx = 0;\r
11 this.movy = 0;\r
12 this.holdType = 0;\r
13 this.holdEnd = 0;\r
14 this.holdIndex = 0;\r
15 this.levels = null;\r
16 this.levelIndex = 0;\r
17 this.done = false;\r
18 Clazz.instantialize (this, arguments);\r
19 }, java.awt.geom, "FlatteningPathIterator", null, java.awt.geom.PathIterator);\r
20 Clazz.prepareFields (c$, function () {\r
21 this.hold =  Clazz.newDoubleArray (14, 0);\r
22 });\r
23 Clazz.makeConstructor (c$, \r
24 function (src, flatness) {\r
25 this.construct (src, flatness, 10);\r
26 }, "java.awt.geom.PathIterator,~N");\r
27 Clazz.makeConstructor (c$, \r
28 function (src, flatness, limit) {\r
29 if (flatness < 0.0) {\r
30 throw  new IllegalArgumentException ("flatness must be >= 0");\r
31 }if (limit < 0) {\r
32 throw  new IllegalArgumentException ("limit must be >= 0");\r
33 }this.src = src;\r
34 this.squareflat = flatness * flatness;\r
35 this.limit = limit;\r
36 this.levels =  Clazz.newIntArray (limit + 1, 0);\r
37 this.next (false);\r
38 }, "java.awt.geom.PathIterator,~N,~N");\r
39 Clazz.defineMethod (c$, "getFlatness", \r
40 function () {\r
41 return Math.sqrt (this.squareflat);\r
42 });\r
43 Clazz.defineMethod (c$, "getRecursionLimit", \r
44 function () {\r
45 return this.limit;\r
46 });\r
47 Clazz.defineMethod (c$, "getWindingRule", \r
48 function () {\r
49 return this.src.getWindingRule ();\r
50 });\r
51 Clazz.defineMethod (c$, "isDone", \r
52 function () {\r
53 return this.done;\r
54 });\r
55 Clazz.defineMethod (c$, "ensureHoldCapacity", \r
56 function (want) {\r
57 if (this.holdIndex - want < 0) {\r
58 var have = this.hold.length - this.holdIndex;\r
59 var newsize = this.hold.length + 24;\r
60 var newhold =  Clazz.newDoubleArray (newsize, 0);\r
61 System.arraycopy (this.hold, this.holdIndex, newhold, this.holdIndex + 24, have);\r
62 this.hold = newhold;\r
63 this.holdIndex += 24;\r
64 this.holdEnd += 24;\r
65 }}, "~N");\r
66 Clazz.defineMethod (c$, "next", \r
67 function () {\r
68 this.next (true);\r
69 });\r
70 Clazz.defineMethod (c$, "next", \r
71  function (doNext) {\r
72 var level;\r
73 if (this.holdIndex >= this.holdEnd) {\r
74 if (doNext) {\r
75 this.src.next ();\r
76 }if (this.src.isDone ()) {\r
77 this.done = true;\r
78 return;\r
79 }this.holdType = this.src.currentSegment (this.hold);\r
80 this.levelIndex = 0;\r
81 this.levels[0] = 0;\r
82 }switch (this.holdType) {\r
83 case 0:\r
84 case 1:\r
85 this.curx = this.hold[0];\r
86 this.cury = this.hold[1];\r
87 if (this.holdType == 0) {\r
88 this.movx = this.curx;\r
89 this.movy = this.cury;\r
90 }this.holdIndex = 0;\r
91 this.holdEnd = 0;\r
92 break;\r
93 case 4:\r
94 this.curx = this.movx;\r
95 this.cury = this.movy;\r
96 this.holdIndex = 0;\r
97 this.holdEnd = 0;\r
98 break;\r
99 case 2:\r
100 if (this.holdIndex >= this.holdEnd) {\r
101 this.holdIndex = this.hold.length - 6;\r
102 this.holdEnd = this.hold.length - 2;\r
103 this.hold[this.holdIndex + 0] = this.curx;\r
104 this.hold[this.holdIndex + 1] = this.cury;\r
105 this.hold[this.holdIndex + 2] = this.hold[0];\r
106 this.hold[this.holdIndex + 3] = this.hold[1];\r
107 this.hold[this.holdIndex + 4] = this.curx = this.hold[2];\r
108 this.hold[this.holdIndex + 5] = this.cury = this.hold[3];\r
109 }level = this.levels[this.levelIndex];\r
110 while (level < this.limit) {\r
111 if (java.awt.geom.QuadCurve2D.getFlatnessSq (this.hold, this.holdIndex) < this.squareflat) {\r
112 break;\r
113 }this.ensureHoldCapacity (4);\r
114 java.awt.geom.QuadCurve2D.subdivide (this.hold, this.holdIndex, this.hold, this.holdIndex - 4, this.hold, this.holdIndex);\r
115 this.holdIndex -= 4;\r
116 level++;\r
117 this.levels[this.levelIndex] = level;\r
118 this.levelIndex++;\r
119 this.levels[this.levelIndex] = level;\r
120 }\r
121 this.holdIndex += 4;\r
122 this.levelIndex--;\r
123 break;\r
124 case 3:\r
125 if (this.holdIndex >= this.holdEnd) {\r
126 this.holdIndex = this.hold.length - 8;\r
127 this.holdEnd = this.hold.length - 2;\r
128 this.hold[this.holdIndex + 0] = this.curx;\r
129 this.hold[this.holdIndex + 1] = this.cury;\r
130 this.hold[this.holdIndex + 2] = this.hold[0];\r
131 this.hold[this.holdIndex + 3] = this.hold[1];\r
132 this.hold[this.holdIndex + 4] = this.hold[2];\r
133 this.hold[this.holdIndex + 5] = this.hold[3];\r
134 this.hold[this.holdIndex + 6] = this.curx = this.hold[4];\r
135 this.hold[this.holdIndex + 7] = this.cury = this.hold[5];\r
136 }level = this.levels[this.levelIndex];\r
137 while (level < this.limit) {\r
138 if (java.awt.geom.CubicCurve2D.getFlatnessSq (this.hold, this.holdIndex) < this.squareflat) {\r
139 break;\r
140 }this.ensureHoldCapacity (6);\r
141 java.awt.geom.CubicCurve2D.subdivide (this.hold, this.holdIndex, this.hold, this.holdIndex - 6, this.hold, this.holdIndex);\r
142 this.holdIndex -= 6;\r
143 level++;\r
144 this.levels[this.levelIndex] = level;\r
145 this.levelIndex++;\r
146 this.levels[this.levelIndex] = level;\r
147 }\r
148 this.holdIndex += 6;\r
149 this.levelIndex--;\r
150 break;\r
151 }\r
152 }, "~B");\r
153 Clazz.defineMethod (c$, "currentSegment", \r
154 function (coords) {\r
155 if (this.isDone ()) {\r
156 throw  new java.util.NoSuchElementException ("flattening iterator out of bounds");\r
157 }var type = this.holdType;\r
158 if (type != 4) {\r
159 coords[0] = this.hold[this.holdIndex + 0];\r
160 coords[1] = this.hold[this.holdIndex + 1];\r
161 if (type != 0) {\r
162 type = 1;\r
163 }}return type;\r
164 }, "~A");\r
165 Clazz.defineMethod (c$, "currentSegment", \r
166 function (coords) {\r
167 if (this.isDone ()) {\r
168 throw  new java.util.NoSuchElementException ("flattening iterator out of bounds");\r
169 }var type = this.holdType;\r
170 if (type != 4) {\r
171 coords[0] = this.hold[this.holdIndex + 0];\r
172 coords[1] = this.hold[this.holdIndex + 1];\r
173 if (type != 0) {\r
174 type = 1;\r
175 }}return type;\r
176 }, "~A");\r
177 Clazz.defineStatics (c$,\r
178 "GROW_SIZE", 24);\r
179 });\r