8458d0563f0209c7d675fa1bb361b85a5b2944fb
[jalviewjs.git] / site / j2s / jssun / awt / geom / Crossings.js
1 Clazz.declarePackage ("jssun.awt.geom");\r
2 Clazz.load (["java.util.Vector"], "jssun.awt.geom.Crossings", ["jssun.awt.geom.Curve"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.limit = 0;\r
5 this.yranges = null;\r
6 this.xlo = 0;\r
7 this.ylo = 0;\r
8 this.xhi = 0;\r
9 this.yhi = 0;\r
10 this.tmp = null;\r
11 Clazz.instantialize (this, arguments);\r
12 }, jssun.awt.geom, "Crossings");\r
13 Clazz.prepareFields (c$, function () {\r
14 this.yranges =  Clazz.newDoubleArray (10, 0);\r
15 this.tmp =  new java.util.Vector ();\r
16 });\r
17 Clazz.makeConstructor (c$, \r
18 function (xlo, ylo, xhi, yhi) {\r
19 this.xlo = xlo;\r
20 this.ylo = ylo;\r
21 this.xhi = xhi;\r
22 this.yhi = yhi;\r
23 }, "~N,~N,~N,~N");\r
24 Clazz.defineMethod (c$, "getXLo", \r
25 function () {\r
26 return this.xlo;\r
27 });\r
28 Clazz.defineMethod (c$, "getYLo", \r
29 function () {\r
30 return this.ylo;\r
31 });\r
32 Clazz.defineMethod (c$, "getXHi", \r
33 function () {\r
34 return this.xhi;\r
35 });\r
36 Clazz.defineMethod (c$, "getYHi", \r
37 function () {\r
38 return this.yhi;\r
39 });\r
40 Clazz.defineMethod (c$, "print", \r
41 function () {\r
42 System.out.println ("Crossings [");\r
43 System.out.println ("  bounds = [" + this.ylo + ", " + this.yhi + "]");\r
44 for (var i = 0; i < this.limit; i += 2) {\r
45 System.out.println ("  [" + this.yranges[i] + ", " + this.yranges[i + 1] + "]");\r
46 }\r
47 System.out.println ("]");\r
48 });\r
49 Clazz.defineMethod (c$, "isEmpty", \r
50 function () {\r
51 return (this.limit == 0);\r
52 });\r
53 c$.findCrossings = Clazz.defineMethod (c$, "findCrossings", \r
54 function (curves, xlo, ylo, xhi, yhi) {\r
55 var cross =  new jssun.awt.geom.Crossings.EvenOdd (xlo, ylo, xhi, yhi);\r
56 var enum_ = curves.elements ();\r
57 while (enum_.hasMoreElements ()) {\r
58 var c = enum_.nextElement ();\r
59 if (c.accumulateCrossings (cross)) {\r
60 return null;\r
61 }}\r
62 return cross;\r
63 }, "java.util.Vector,~N,~N,~N,~N");\r
64 Clazz.defineMethod (c$, "accumulateLine", \r
65 function (x0, y0, x1, y1) {\r
66 if (y0 <= y1) {\r
67 return this.accumulateLine (x0, y0, x1, y1, 1);\r
68 } else {\r
69 return this.accumulateLine (x1, y1, x0, y0, -1);\r
70 }}, "~N,~N,~N,~N");\r
71 Clazz.defineMethod (c$, "accumulateLine", \r
72 function (x0, y0, x1, y1, direction) {\r
73 if (this.yhi <= y0 || this.ylo >= y1) {\r
74 return false;\r
75 }if (x0 >= this.xhi && x1 >= this.xhi) {\r
76 return false;\r
77 }if (y0 == y1) {\r
78 return (x0 >= this.xlo || x1 >= this.xlo);\r
79 }var xstart;\r
80 var ystart;\r
81 var xend;\r
82 var yend;\r
83 var dx = (x1 - x0);\r
84 var dy = (y1 - y0);\r
85 if (y0 < this.ylo) {\r
86 xstart = x0 + (this.ylo - y0) * dx / dy;\r
87 ystart = this.ylo;\r
88 } else {\r
89 xstart = x0;\r
90 ystart = y0;\r
91 }if (this.yhi < y1) {\r
92 xend = x0 + (this.yhi - y0) * dx / dy;\r
93 yend = this.yhi;\r
94 } else {\r
95 xend = x1;\r
96 yend = y1;\r
97 }if (xstart >= this.xhi && xend >= this.xhi) {\r
98 return false;\r
99 }if (xstart > this.xlo || xend > this.xlo) {\r
100 return true;\r
101 }this.record (ystart, yend, direction);\r
102 return false;\r
103 }, "~N,~N,~N,~N,~N");\r
104 Clazz.defineMethod (c$, "accumulateQuad", \r
105 function (x0, y0, coords) {\r
106 if (y0 < this.ylo && coords[1] < this.ylo && coords[3] < this.ylo) {\r
107 return false;\r
108 }if (y0 > this.yhi && coords[1] > this.yhi && coords[3] > this.yhi) {\r
109 return false;\r
110 }if (x0 > this.xhi && coords[0] > this.xhi && coords[2] > this.xhi) {\r
111 return false;\r
112 }if (x0 < this.xlo && coords[0] < this.xlo && coords[2] < this.xlo) {\r
113 if (y0 < coords[3]) {\r
114 this.record (Math.max (y0, this.ylo), Math.min (coords[3], this.yhi), 1);\r
115 } else if (y0 > coords[3]) {\r
116 this.record (Math.max (coords[3], this.ylo), Math.min (y0, this.yhi), -1);\r
117 }return false;\r
118 }jssun.awt.geom.Curve.insertQuad (this.tmp, x0, y0, coords);\r
119 var enum_ = this.tmp.elements ();\r
120 while (enum_.hasMoreElements ()) {\r
121 var c = enum_.nextElement ();\r
122 if (c.accumulateCrossings (this)) {\r
123 return true;\r
124 }}\r
125 this.tmp.clear ();\r
126 return false;\r
127 }, "~N,~N,~A");\r
128 Clazz.defineMethod (c$, "accumulateCubic", \r
129 function (x0, y0, coords) {\r
130 if (y0 < this.ylo && coords[1] < this.ylo && coords[3] < this.ylo && coords[5] < this.ylo) {\r
131 return false;\r
132 }if (y0 > this.yhi && coords[1] > this.yhi && coords[3] > this.yhi && coords[5] > this.yhi) {\r
133 return false;\r
134 }if (x0 > this.xhi && coords[0] > this.xhi && coords[2] > this.xhi && coords[4] > this.xhi) {\r
135 return false;\r
136 }if (x0 < this.xlo && coords[0] < this.xlo && coords[2] < this.xlo && coords[4] < this.xlo) {\r
137 if (y0 <= coords[5]) {\r
138 this.record (Math.max (y0, this.ylo), Math.min (coords[5], this.yhi), 1);\r
139 } else {\r
140 this.record (Math.max (coords[5], this.ylo), Math.min (y0, this.yhi), -1);\r
141 }return false;\r
142 }jssun.awt.geom.Curve.insertCubic (this.tmp, x0, y0, coords);\r
143 var enum_ = this.tmp.elements ();\r
144 while (enum_.hasMoreElements ()) {\r
145 var c = enum_.nextElement ();\r
146 if (c.accumulateCrossings (this)) {\r
147 return true;\r
148 }}\r
149 this.tmp.clear ();\r
150 return false;\r
151 }, "~N,~N,~A");\r
152 Clazz.pu$h(self.c$);\r
153 c$ = Clazz.declareType (jssun.awt.geom.Crossings, "EvenOdd", jssun.awt.geom.Crossings);\r
154 Clazz.overrideMethod (c$, "covers", \r
155 function (a, b) {\r
156 return (this.limit == 2 && this.yranges[0] <= a && this.yranges[1] >= b);\r
157 }, "~N,~N");\r
158 Clazz.overrideMethod (c$, "record", \r
159 function (a, b, c) {\r
160 if (a >= b) {\r
161 return;\r
162 }var d = 0;\r
163 while (d < this.limit && a > this.yranges[d + 1]) {\r
164 d += 2;\r
165 }\r
166 var e = d;\r
167 while (d < this.limit) {\r
168 var f = this.yranges[d++];\r
169 var g = this.yranges[d++];\r
170 if (b < f) {\r
171 this.yranges[e++] = a;\r
172 this.yranges[e++] = b;\r
173 a = f;\r
174 b = g;\r
175 continue;\r
176 }var h;\r
177 var i;\r
178 var j;\r
179 var k;\r
180 if (a < f) {\r
181 h = a;\r
182 i = f;\r
183 } else {\r
184 h = f;\r
185 i = a;\r
186 }if (b < g) {\r
187 j = b;\r
188 k = g;\r
189 } else {\r
190 j = g;\r
191 k = b;\r
192 }if (i == j) {\r
193 a = h;\r
194 b = k;\r
195 } else {\r
196 if (i > j) {\r
197 a = j;\r
198 j = i;\r
199 i = a;\r
200 }if (h != i) {\r
201 this.yranges[e++] = h;\r
202 this.yranges[e++] = i;\r
203 }a = j;\r
204 b = k;\r
205 }if (a >= b) {\r
206 break;\r
207 }}\r
208 if (e < d && d < this.limit) {\r
209 System.arraycopy (this.yranges, d, this.yranges, e, this.limit - d);\r
210 }e += (this.limit - d);\r
211 if (a < b) {\r
212 if (e >= this.yranges.length) {\r
213 var f =  Clazz.newDoubleArray (e + 10, 0);\r
214 System.arraycopy (this.yranges, 0, f, 0, e);\r
215 this.yranges = f;\r
216 }this.yranges[e++] = a;\r
217 this.yranges[e++] = b;\r
218 }this.limit = e;\r
219 }, "~N,~N,~N");\r
220 c$ = Clazz.p0p ();\r
221 Clazz.pu$h(self.c$);\r
222 c$ = Clazz.decorateAsClass (function () {\r
223 this.crosscounts = null;\r
224 Clazz.instantialize (this, arguments);\r
225 }, jssun.awt.geom.Crossings, "NonZero", jssun.awt.geom.Crossings);\r
226 Clazz.makeConstructor (c$, \r
227 function (a, b, c, d) {\r
228 Clazz.superConstructor (this, jssun.awt.geom.Crossings.NonZero, [a, b, c, d]);\r
229 this.crosscounts =  Clazz.newIntArray (Clazz.doubleToInt (this.yranges.length / 2), 0);\r
230 }, "~N,~N,~N,~N");\r
231 Clazz.overrideMethod (c$, "covers", \r
232 function (a, b) {\r
233 var c = 0;\r
234 while (c < this.limit) {\r
235 var d = this.yranges[c++];\r
236 var e = this.yranges[c++];\r
237 if (a >= e) {\r
238 continue;\r
239 }if (a < d) {\r
240 return false;\r
241 }if (b <= e) {\r
242 return true;\r
243 }a = e;\r
244 }\r
245 return (a >= b);\r
246 }, "~N,~N");\r
247 Clazz.defineMethod (c$, "remove", \r
248 function (a) {\r
249 this.limit -= 2;\r
250 var b = this.limit - a;\r
251 if (b > 0) {\r
252 System.arraycopy (this.yranges, a + 2, this.yranges, a, b);\r
253 System.arraycopy (this.crosscounts, Clazz.doubleToInt (a / 2) + 1, this.crosscounts, Clazz.doubleToInt (a / 2), Clazz.doubleToInt (b / 2));\r
254 }}, "~N");\r
255 Clazz.defineMethod (c$, "insert", \r
256 function (a, b, c, d) {\r
257 var e = this.limit - a;\r
258 var f = this.yranges;\r
259 var g = this.crosscounts;\r
260 if (this.limit >= this.yranges.length) {\r
261 this.yranges =  Clazz.newDoubleArray (this.limit + 10, 0);\r
262 System.arraycopy (f, 0, this.yranges, 0, a);\r
263 this.crosscounts =  Clazz.newIntArray (Clazz.doubleToInt ((this.limit + 10) / 2), 0);\r
264 System.arraycopy (g, 0, this.crosscounts, 0, Clazz.doubleToInt (a / 2));\r
265 }if (e > 0) {\r
266 System.arraycopy (f, a, this.yranges, a + 2, e);\r
267 System.arraycopy (g, Clazz.doubleToInt (a / 2), this.crosscounts, Clazz.doubleToInt (a / 2) + 1, Clazz.doubleToInt (e / 2));\r
268 }this.yranges[a + 0] = b;\r
269 this.yranges[a + 1] = c;\r
270 this.crosscounts[Clazz.doubleToInt (a / 2)] = d;\r
271 this.limit += 2;\r
272 }, "~N,~N,~N,~N");\r
273 Clazz.overrideMethod (c$, "record", \r
274 function (a, b, c) {\r
275 if (a >= b) {\r
276 return;\r
277 }var d = 0;\r
278 while (d < this.limit && a > this.yranges[d + 1]) {\r
279 d += 2;\r
280 }\r
281 if (d < this.limit) {\r
282 var e = this.crosscounts[Clazz.doubleToInt (d / 2)];\r
283 var f = this.yranges[d + 0];\r
284 var g = this.yranges[d + 1];\r
285 if (g == a && e == c) {\r
286 if (d + 2 == this.limit) {\r
287 this.yranges[d + 1] = b;\r
288 return;\r
289 }this.remove (d);\r
290 a = f;\r
291 e = this.crosscounts[Clazz.doubleToInt (d / 2)];\r
292 f = this.yranges[d + 0];\r
293 g = this.yranges[d + 1];\r
294 }if (b < f) {\r
295 this.insert (d, a, b, c);\r
296 return;\r
297 }if (b == f && e == c) {\r
298 this.yranges[d] = a;\r
299 return;\r
300 }if (a < f) {\r
301 this.insert (d, a, f, c);\r
302 d += 2;\r
303 a = f;\r
304 } else if (f < a) {\r
305 this.insert (d, f, a, e);\r
306 d += 2;\r
307 f = a;\r
308 }var h = e + c;\r
309 var i = Math.min (b, g);\r
310 if (h == 0) {\r
311 this.remove (d);\r
312 } else {\r
313 this.crosscounts[Clazz.doubleToInt (d / 2)] = h;\r
314 this.yranges[d++] = a;\r
315 this.yranges[d++] = i;\r
316 }a = f = i;\r
317 if (f < g) {\r
318 this.insert (d, f, g, e);\r
319 }}if (a < b) {\r
320 this.insert (d, a, b, c);\r
321 }}, "~N,~N,~N");\r
322 c$ = Clazz.p0p ();\r
323 });\r