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