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