e1d494060e4d20e5b4f21c08f216e630abc7c7ba
[jalviewjs.git] / site / swingjs / j2s / jssun / awt / geom / Order2.js
1 Clazz.declarePackage ("jssun.awt.geom");
2 Clazz.load (["jssun.awt.geom.Curve"], "jssun.awt.geom.Order2", null, function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.x0 = 0;
5 this.y0 = 0;
6 this.cx0 = 0;
7 this.cy0 = 0;
8 this.x1 = 0;
9 this.y1 = 0;
10 this.xmin = 0;
11 this.xmax = 0;
12 this.xcoeff0 = 0;
13 this.xcoeff1 = 0;
14 this.xcoeff2 = 0;
15 this.ycoeff0 = 0;
16 this.ycoeff1 = 0;
17 this.ycoeff2 = 0;
18 Clazz.instantialize (this, arguments);
19 }, jssun.awt.geom, "Order2", jssun.awt.geom.Curve);
20 c$.insert = Clazz.defineMethod (c$, "insert", 
21 function (curves, tmp, x0, y0, cx0, cy0, x1, y1, direction) {
22 var numparams = jssun.awt.geom.Order2.getHorizontalParams (y0, cy0, y1, tmp);
23 if (numparams == 0) {
24 jssun.awt.geom.Order2.addInstance (curves, x0, y0, cx0, cy0, x1, y1, direction);
25 return;
26 }var t = tmp[0];
27 tmp[0] = x0;
28 tmp[1] = y0;
29 tmp[2] = cx0;
30 tmp[3] = cy0;
31 tmp[4] = x1;
32 tmp[5] = y1;
33 jssun.awt.geom.Order2.split (tmp, 0, t);
34 var i0 = (direction == 1) ? 0 : 4;
35 var i1 = 4 - i0;
36 jssun.awt.geom.Order2.addInstance (curves, tmp[i0], tmp[i0 + 1], tmp[i0 + 2], tmp[i0 + 3], tmp[i0 + 4], tmp[i0 + 5], direction);
37 jssun.awt.geom.Order2.addInstance (curves, tmp[i1], tmp[i1 + 1], tmp[i1 + 2], tmp[i1 + 3], tmp[i1 + 4], tmp[i1 + 5], direction);
38 }, "java.util.Vector,~A,~N,~N,~N,~N,~N,~N,~N");
39 c$.addInstance = Clazz.defineMethod (c$, "addInstance", 
40 function (curves, x0, y0, cx0, cy0, x1, y1, direction) {
41 if (y0 > y1) {
42 curves.add ( new jssun.awt.geom.Order2 (x1, y1, cx0, cy0, x0, y0, -direction));
43 } else if (y1 > y0) {
44 curves.add ( new jssun.awt.geom.Order2 (x0, y0, cx0, cy0, x1, y1, direction));
45 }}, "java.util.Vector,~N,~N,~N,~N,~N,~N,~N");
46 c$.getHorizontalParams = Clazz.defineMethod (c$, "getHorizontalParams", 
47 function (c0, cp, c1, ret) {
48 if (c0 <= cp && cp <= c1) {
49 return 0;
50 }c0 -= cp;
51 c1 -= cp;
52 var denom = c0 + c1;
53 if (denom == 0) {
54 return 0;
55 }var t = c0 / denom;
56 if (t <= 0 || t >= 1) {
57 return 0;
58 }ret[0] = t;
59 return 1;
60 }, "~N,~N,~N,~A");
61 c$.split = Clazz.defineMethod (c$, "split", 
62 function (coords, pos, t) {
63 var x0;
64 var y0;
65 var cx;
66 var cy;
67 var x1;
68 var y1;
69 coords[pos + 8] = x1 = coords[pos + 4];
70 coords[pos + 9] = y1 = coords[pos + 5];
71 cx = coords[pos + 2];
72 cy = coords[pos + 3];
73 x1 = cx + (x1 - cx) * t;
74 y1 = cy + (y1 - cy) * t;
75 x0 = coords[pos + 0];
76 y0 = coords[pos + 1];
77 x0 = x0 + (cx - x0) * t;
78 y0 = y0 + (cy - y0) * t;
79 cx = x0 + (x1 - x0) * t;
80 cy = y0 + (y1 - y0) * t;
81 coords[pos + 2] = x0;
82 coords[pos + 3] = y0;
83 coords[pos + 4] = cx;
84 coords[pos + 5] = cy;
85 coords[pos + 6] = x1;
86 coords[pos + 7] = y1;
87 }, "~A,~N,~N");
88 Clazz.makeConstructor (c$, 
89 function (x0, y0, cx0, cy0, x1, y1, direction) {
90 Clazz.superConstructor (this, jssun.awt.geom.Order2, [direction]);
91 if (cy0 < y0) {
92 cy0 = y0;
93 } else if (cy0 > y1) {
94 cy0 = y1;
95 }this.x0 = x0;
96 this.y0 = y0;
97 this.cx0 = cx0;
98 this.cy0 = cy0;
99 this.x1 = x1;
100 this.y1 = y1;
101 this.xmin = Math.min (Math.min (x0, x1), cx0);
102 this.xmax = Math.max (Math.max (x0, x1), cx0);
103 this.xcoeff0 = x0;
104 this.xcoeff1 = cx0 + cx0 - x0 - x0;
105 this.xcoeff2 = x0 - cx0 - cx0 + x1;
106 this.ycoeff0 = y0;
107 this.ycoeff1 = cy0 + cy0 - y0 - y0;
108 this.ycoeff2 = y0 - cy0 - cy0 + y1;
109 }, "~N,~N,~N,~N,~N,~N,~N");
110 Clazz.overrideMethod (c$, "getOrder", 
111 function () {
112 return 2;
113 });
114 Clazz.overrideMethod (c$, "getXTop", 
115 function () {
116 return this.x0;
117 });
118 Clazz.overrideMethod (c$, "getYTop", 
119 function () {
120 return this.y0;
121 });
122 Clazz.overrideMethod (c$, "getXBot", 
123 function () {
124 return this.x1;
125 });
126 Clazz.overrideMethod (c$, "getYBot", 
127 function () {
128 return this.y1;
129 });
130 Clazz.overrideMethod (c$, "getXMin", 
131 function () {
132 return this.xmin;
133 });
134 Clazz.overrideMethod (c$, "getXMax", 
135 function () {
136 return this.xmax;
137 });
138 Clazz.overrideMethod (c$, "getX0", 
139 function () {
140 return (this.direction == 1) ? this.x0 : this.x1;
141 });
142 Clazz.overrideMethod (c$, "getY0", 
143 function () {
144 return (this.direction == 1) ? this.y0 : this.y1;
145 });
146 Clazz.defineMethod (c$, "getCX0", 
147 function () {
148 return this.cx0;
149 });
150 Clazz.defineMethod (c$, "getCY0", 
151 function () {
152 return this.cy0;
153 });
154 Clazz.overrideMethod (c$, "getX1", 
155 function () {
156 return (this.direction == -1) ? this.x0 : this.x1;
157 });
158 Clazz.overrideMethod (c$, "getY1", 
159 function () {
160 return (this.direction == -1) ? this.y0 : this.y1;
161 });
162 Clazz.overrideMethod (c$, "XforY", 
163 function (y) {
164 if (y <= this.y0) {
165 return this.x0;
166 }if (y >= this.y1) {
167 return this.x1;
168 }return this.XforT (this.TforY (y));
169 }, "~N");
170 Clazz.defineMethod (c$, "TforY", 
171 function (y) {
172 if (y <= this.y0) {
173 return 0;
174 }if (y >= this.y1) {
175 return 1;
176 }return jssun.awt.geom.Order2.TforY (y, this.ycoeff0, this.ycoeff1, this.ycoeff2);
177 }, "~N");
178 c$.TforY = Clazz.defineMethod (c$, "TforY", 
179 function (y, ycoeff0, ycoeff1, ycoeff2) {
180 ycoeff0 -= y;
181 if (ycoeff2 == 0.0) {
182 var root = -ycoeff0 / ycoeff1;
183 if (root >= 0 && root <= 1) {
184 return root;
185 }} else {
186 var d = ycoeff1 * ycoeff1 - 4.0 * ycoeff2 * ycoeff0;
187 if (d >= 0.0) {
188 d = Math.sqrt (d);
189 if (ycoeff1 < 0.0) {
190 d = -d;
191 }var q = (ycoeff1 + d) / -2.0;
192 var root = q / ycoeff2;
193 if (root >= 0 && root <= 1) {
194 return root;
195 }if (q != 0.0) {
196 root = ycoeff0 / q;
197 if (root >= 0 && root <= 1) {
198 return root;
199 }}}}var y0 = ycoeff0;
200 var y1 = ycoeff0 + ycoeff1 + ycoeff2;
201 return (0 < (y0 + y1) / 2) ? 0.0 : 1.0;
202 }, "~N,~N,~N,~N");
203 Clazz.overrideMethod (c$, "XforT", 
204 function (t) {
205 return (this.xcoeff2 * t + this.xcoeff1) * t + this.xcoeff0;
206 }, "~N");
207 Clazz.overrideMethod (c$, "YforT", 
208 function (t) {
209 return (this.ycoeff2 * t + this.ycoeff1) * t + this.ycoeff0;
210 }, "~N");
211 Clazz.overrideMethod (c$, "dXforT", 
212 function (t, deriv) {
213 switch (deriv) {
214 case 0:
215 return (this.xcoeff2 * t + this.xcoeff1) * t + this.xcoeff0;
216 case 1:
217 return 2 * this.xcoeff2 * t + this.xcoeff1;
218 case 2:
219 return 2 * this.xcoeff2;
220 default:
221 return 0;
222 }
223 }, "~N,~N");
224 Clazz.overrideMethod (c$, "dYforT", 
225 function (t, deriv) {
226 switch (deriv) {
227 case 0:
228 return (this.ycoeff2 * t + this.ycoeff1) * t + this.ycoeff0;
229 case 1:
230 return 2 * this.ycoeff2 * t + this.ycoeff1;
231 case 2:
232 return 2 * this.ycoeff2;
233 default:
234 return 0;
235 }
236 }, "~N,~N");
237 Clazz.overrideMethod (c$, "nextVertical", 
238 function (t0, t1) {
239 var t = -this.xcoeff1 / (2 * this.xcoeff2);
240 if (t > t0 && t < t1) {
241 return t;
242 }return t1;
243 }, "~N,~N");
244 Clazz.overrideMethod (c$, "enlarge", 
245 function (r) {
246 r.add (this.x0, this.y0);
247 var t = -this.xcoeff1 / (2 * this.xcoeff2);
248 if (t > 0 && t < 1) {
249 r.add (this.XforT (t), this.YforT (t));
250 }r.add (this.x1, this.y1);
251 }, "java.awt.geom.Rectangle2D");
252 Clazz.defineMethod (c$, "getSubCurve", 
253 function (ystart, yend, dir) {
254 var t0;
255 var t1;
256 if (ystart <= this.y0) {
257 if (yend >= this.y1) {
258 return this.getWithDirection (dir);
259 }t0 = 0;
260 } else {
261 t0 = jssun.awt.geom.Order2.TforY (ystart, this.ycoeff0, this.ycoeff1, this.ycoeff2);
262 }if (yend >= this.y1) {
263 t1 = 1;
264 } else {
265 t1 = jssun.awt.geom.Order2.TforY (yend, this.ycoeff0, this.ycoeff1, this.ycoeff2);
266 }var eqn =  Clazz.newDoubleArray (10, 0);
267 eqn[0] = this.x0;
268 eqn[1] = this.y0;
269 eqn[2] = this.cx0;
270 eqn[3] = this.cy0;
271 eqn[4] = this.x1;
272 eqn[5] = this.y1;
273 if (t1 < 1) {
274 jssun.awt.geom.Order2.split (eqn, 0, t1);
275 }var i;
276 if (t0 <= 0) {
277 i = 0;
278 } else {
279 jssun.awt.geom.Order2.split (eqn, 0, t0 / t1);
280 i = 4;
281 }return  new jssun.awt.geom.Order2 (eqn[i + 0], ystart, eqn[i + 2], eqn[i + 3], eqn[i + 4], yend, dir);
282 }, "~N,~N,~N");
283 Clazz.overrideMethod (c$, "getReversedCurve", 
284 function () {
285 return  new jssun.awt.geom.Order2 (this.x0, this.y0, this.cx0, this.cy0, this.x1, this.y1, -this.direction);
286 });
287 Clazz.overrideMethod (c$, "getSegment", 
288 function (coords) {
289 coords[0] = this.cx0;
290 coords[1] = this.cy0;
291 if (this.direction == 1) {
292 coords[2] = this.x1;
293 coords[3] = this.y1;
294 } else {
295 coords[2] = this.x0;
296 coords[3] = this.y0;
297 }return 2;
298 }, "~A");
299 Clazz.overrideMethod (c$, "controlPointString", 
300 function () {
301 return ("(" + jssun.awt.geom.Curve.round (this.cx0) + ", " + jssun.awt.geom.Curve.round (this.cy0) + "), ");
302 });
303 });