Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / geom / Arc2D.js
1 Clazz.declarePackage ("java.awt.geom");
2 Clazz.load (["java.awt.geom.RectangularShape"], "java.awt.geom.Arc2D", ["java.lang.Double", "$.IllegalArgumentException", "java.awt.geom.ArcIterator", "$.Line2D", "$.Point2D", "$.Rectangle2D"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.type = 0;
5 Clazz.instantialize (this, arguments);
6 }, java.awt.geom, "Arc2D", java.awt.geom.RectangularShape);
7 Clazz.makeConstructor (c$, 
8 function () {
9 this.construct (0);
10 });
11 Clazz.makeConstructor (c$, 
12 function (type) {
13 Clazz.superConstructor (this, java.awt.geom.Arc2D, []);
14 this.setArcType (type);
15 }, "~N");
16 Clazz.defineMethod (c$, "getArcType", 
17 function () {
18 return this.type;
19 });
20 Clazz.defineMethod (c$, "getStartPoint", 
21 function () {
22 var angle = Math.toRadians (-this.getAngleStart ());
23 var x = this.getX () + (Math.cos (angle) * 0.5 + 0.5) * this.getWidth ();
24 var y = this.getY () + (Math.sin (angle) * 0.5 + 0.5) * this.getHeight ();
25 return  new java.awt.geom.Point2D.Double (x, y);
26 });
27 Clazz.defineMethod (c$, "getEndPoint", 
28 function () {
29 var angle = Math.toRadians (-this.getAngleStart () - this.getAngleExtent ());
30 var x = this.getX () + (Math.cos (angle) * 0.5 + 0.5) * this.getWidth ();
31 var y = this.getY () + (Math.sin (angle) * 0.5 + 0.5) * this.getHeight ();
32 return  new java.awt.geom.Point2D.Double (x, y);
33 });
34 Clazz.defineMethod (c$, "setArc", 
35 function (loc, size, angSt, angExt, closure) {
36 this.setArc (loc.getX (), loc.getY (), size.getWidth (), size.getHeight (), angSt, angExt, closure);
37 }, "java.awt.geom.Point2D,java.awt.geom.Dimension2D,~N,~N,~N");
38 Clazz.defineMethod (c$, "setArc", 
39 function (rect, angSt, angExt, closure) {
40 this.setArc (rect.getX (), rect.getY (), rect.getWidth (), rect.getHeight (), angSt, angExt, closure);
41 }, "java.awt.geom.Rectangle2D,~N,~N,~N");
42 Clazz.defineMethod (c$, "setArc", 
43 function (a) {
44 this.setArc (a.getX (), a.getY (), a.getWidth (), a.getHeight (), a.getAngleStart (), a.getAngleExtent (), a.type);
45 }, "java.awt.geom.Arc2D");
46 Clazz.defineMethod (c$, "setArcByCenter", 
47 function (x, y, radius, angSt, angExt, closure) {
48 this.setArc (x - radius, y - radius, radius * 2.0, radius * 2.0, angSt, angExt, closure);
49 }, "~N,~N,~N,~N,~N,~N");
50 Clazz.defineMethod (c$, "setArcByTangent", 
51 function (p1, p2, p3, radius) {
52 var ang1 = Math.atan2 (p1.getY () - p2.getY (), p1.getX () - p2.getX ());
53 var ang2 = Math.atan2 (p3.getY () - p2.getY (), p3.getX () - p2.getX ());
54 var diff = ang2 - ang1;
55 if (diff > 3.141592653589793) {
56 ang2 -= 6.283185307179586;
57 } else if (diff < -3.141592653589793) {
58 ang2 += 6.283185307179586;
59 }var bisect = (ang1 + ang2) / 2.0;
60 var theta = Math.abs (ang2 - bisect);
61 var dist = radius / Math.sin (theta);
62 var x = p2.getX () + dist * Math.cos (bisect);
63 var y = p2.getY () + dist * Math.sin (bisect);
64 if (ang1 < ang2) {
65 ang1 -= 1.5707963267948966;
66 ang2 += 1.5707963267948966;
67 } else {
68 ang1 += 1.5707963267948966;
69 ang2 -= 1.5707963267948966;
70 }ang1 = Math.toDegrees (-ang1);
71 ang2 = Math.toDegrees (-ang2);
72 diff = ang2 - ang1;
73 if (diff < 0) {
74 diff += 360;
75 } else {
76 diff -= 360;
77 }this.setArcByCenter (x, y, radius, ang1, diff, this.type);
78 }, "java.awt.geom.Point2D,java.awt.geom.Point2D,java.awt.geom.Point2D,~N");
79 Clazz.defineMethod (c$, "setAngleStart", 
80 function (p) {
81 var dx = this.getHeight () * (p.getX () - this.getCenterX ());
82 var dy = this.getWidth () * (p.getY () - this.getCenterY ());
83 this.setAngleStart (-Math.toDegrees (Math.atan2 (dy, dx)));
84 }, "java.awt.geom.Point2D");
85 Clazz.defineMethod (c$, "setAngles", 
86 function (x1, y1, x2, y2) {
87 var x = this.getCenterX ();
88 var y = this.getCenterY ();
89 var w = this.getWidth ();
90 var h = this.getHeight ();
91 var ang1 = Math.atan2 (w * (y - y1), h * (x1 - x));
92 var ang2 = Math.atan2 (w * (y - y2), h * (x2 - x));
93 ang2 -= ang1;
94 if (ang2 <= 0.0) {
95 ang2 += 6.283185307179586;
96 }this.setAngleStart (Math.toDegrees (ang1));
97 this.setAngleExtent (Math.toDegrees (ang2));
98 }, "~N,~N,~N,~N");
99 Clazz.defineMethod (c$, "setAngles", 
100 function (p1, p2) {
101 this.setAngles (p1.getX (), p1.getY (), p2.getX (), p2.getY ());
102 }, "java.awt.geom.Point2D,java.awt.geom.Point2D");
103 Clazz.defineMethod (c$, "setArcType", 
104 function (type) {
105 if (type < 0 || type > 2) {
106 throw  new IllegalArgumentException ("invalid type for Arc: " + type);
107 }this.type = type;
108 }, "~N");
109 Clazz.defineMethod (c$, "setFrame", 
110 function (x, y, w, h) {
111 this.setArc (x, y, w, h, this.getAngleStart (), this.getAngleExtent (), this.type);
112 }, "~N,~N,~N,~N");
113 Clazz.overrideMethod (c$, "getBounds2D", 
114 function () {
115 if (this.isEmpty ()) {
116 return this.makeBounds (this.getX (), this.getY (), this.getWidth (), this.getHeight ());
117 }var x1;
118 var y1;
119 var x2;
120 var y2;
121 if (this.getArcType () == 2) {
122 x1 = y1 = x2 = y2 = 0.0;
123 } else {
124 x1 = y1 = 1.0;
125 x2 = y2 = -1.0;
126 }var angle = 0.0;
127 for (var i = 0; i < 6; i++) {
128 if (i < 4) {
129 angle += 90.0;
130 if (!this.containsAngle (angle)) {
131 continue;
132 }} else if (i == 4) {
133 angle = this.getAngleStart ();
134 } else {
135 angle += this.getAngleExtent ();
136 }var rads = Math.toRadians (-angle);
137 var xe = Math.cos (rads);
138 var ye = Math.sin (rads);
139 x1 = Math.min (x1, xe);
140 y1 = Math.min (y1, ye);
141 x2 = Math.max (x2, xe);
142 y2 = Math.max (y2, ye);
143 }
144 var w = this.getWidth ();
145 var h = this.getHeight ();
146 x2 = (x2 - x1) * 0.5 * w;
147 y2 = (y2 - y1) * 0.5 * h;
148 x1 = this.getX () + (x1 * 0.5 + 0.5) * w;
149 y1 = this.getY () + (y1 * 0.5 + 0.5) * h;
150 return this.makeBounds (x1, y1, x2, y2);
151 });
152 c$.normalizeDegrees = Clazz.defineMethod (c$, "normalizeDegrees", 
153 function (angle) {
154 if (angle > 180.0) {
155 if (angle <= (540.0)) {
156 angle = angle - 360.0;
157 } else {
158 angle = Math.IEEEremainder (angle, 360.0);
159 if (angle == -180.0) {
160 angle = 180.0;
161 }}} else if (angle <= -180.0) {
162 if (angle > (-540.0)) {
163 angle = angle + 360.0;
164 } else {
165 angle = Math.IEEEremainder (angle, 360.0);
166 if (angle == -180.0) {
167 angle = 180.0;
168 }}}return angle;
169 }, "~N");
170 Clazz.defineMethod (c$, "containsAngle", 
171 function (angle) {
172 var angExt = this.getAngleExtent ();
173 var backwards = (angExt < 0.0);
174 if (backwards) {
175 angExt = -angExt;
176 }if (angExt >= 360.0) {
177 return true;
178 }angle = java.awt.geom.Arc2D.normalizeDegrees (angle) - java.awt.geom.Arc2D.normalizeDegrees (this.getAngleStart ());
179 if (backwards) {
180 angle = -angle;
181 }if (angle < 0.0) {
182 angle += 360.0;
183 }return (angle >= 0.0) && (angle < angExt);
184 }, "~N");
185 Clazz.defineMethod (c$, "contains", 
186 function (x, y) {
187 var ellw = this.getWidth ();
188 if (ellw <= 0.0) {
189 return false;
190 }var normx = (x - this.getX ()) / ellw - 0.5;
191 var ellh = this.getHeight ();
192 if (ellh <= 0.0) {
193 return false;
194 }var normy = (y - this.getY ()) / ellh - 0.5;
195 var distSq = (normx * normx + normy * normy);
196 if (distSq >= 0.25) {
197 return false;
198 }var angExt = Math.abs (this.getAngleExtent ());
199 if (angExt >= 360.0) {
200 return true;
201 }var inarc = this.containsAngle (-Math.toDegrees (Math.atan2 (normy, normx)));
202 if (this.type == 2) {
203 return inarc;
204 }if (inarc) {
205 if (angExt >= 180.0) {
206 return true;
207 }} else {
208 if (angExt <= 180.0) {
209 return false;
210 }}var angle = Math.toRadians (-this.getAngleStart ());
211 var x1 = Math.cos (angle);
212 var y1 = Math.sin (angle);
213 angle += Math.toRadians (-this.getAngleExtent ());
214 var x2 = Math.cos (angle);
215 var y2 = Math.sin (angle);
216 var inside = (java.awt.geom.Line2D.relativeCCW (x1, y1, x2, y2, 2 * normx, 2 * normy) * java.awt.geom.Line2D.relativeCCW (x1, y1, x2, y2, 0, 0) >= 0);
217 return inarc ? !inside : inside;
218 }, "~N,~N");
219 Clazz.defineMethod (c$, "intersects", 
220 function (x, y, w, h) {
221 var aw = this.getWidth ();
222 var ah = this.getHeight ();
223 if (w <= 0 || h <= 0 || aw <= 0 || ah <= 0) {
224 return false;
225 }var ext = this.getAngleExtent ();
226 if (ext == 0) {
227 return false;
228 }var ax = this.getX ();
229 var ay = this.getY ();
230 var axw = ax + aw;
231 var ayh = ay + ah;
232 var xw = x + w;
233 var yh = y + h;
234 if (x >= axw || y >= ayh || xw <= ax || yh <= ay) {
235 return false;
236 }var axc = this.getCenterX ();
237 var ayc = this.getCenterY ();
238 var sp = this.getStartPoint ();
239 var ep = this.getEndPoint ();
240 var sx = sp.getX ();
241 var sy = sp.getY ();
242 var ex = ep.getX ();
243 var ey = ep.getY ();
244 if (ayc >= y && ayc <= yh) {
245 if ((sx < xw && ex < xw && axc < xw && axw > x && this.containsAngle (0)) || (sx > x && ex > x && axc > x && ax < xw && this.containsAngle (180))) {
246 return true;
247 }}if (axc >= x && axc <= xw) {
248 if ((sy > y && ey > y && ayc > y && ay < yh && this.containsAngle (90)) || (sy < yh && ey < yh && ayc < yh && ayh > y && this.containsAngle (270))) {
249 return true;
250 }}var rect =  new java.awt.geom.Rectangle2D.Double (x, y, w, h);
251 if (this.type == 2 || Math.abs (ext) > 180) {
252 if (rect.intersectsLine (axc, ayc, sx, sy) || rect.intersectsLine (axc, ayc, ex, ey)) {
253 return true;
254 }} else {
255 if (rect.intersectsLine (sx, sy, ex, ey)) {
256 return true;
257 }}if (this.contains (x, y) || this.contains (x + w, y) || this.contains (x, y + h) || this.contains (x + w, y + h)) {
258 return true;
259 }return false;
260 }, "~N,~N,~N,~N");
261 Clazz.defineMethod (c$, "contains", 
262 function (x, y, w, h) {
263 return this.contains (x, y, w, h, null);
264 }, "~N,~N,~N,~N");
265 Clazz.defineMethod (c$, "contains", 
266 function (r) {
267 return this.contains (r.getX (), r.getY (), r.getWidth (), r.getHeight (), r);
268 }, "java.awt.geom.Rectangle2D");
269 Clazz.defineMethod (c$, "contains", 
270  function (x, y, w, h, origrect) {
271 if (!(this.contains (x, y) && this.contains (x + w, y) && this.contains (x, y + h) && this.contains (x + w, y + h))) {
272 return false;
273 }if (this.type != 2 || Math.abs (this.getAngleExtent ()) <= 180.0) {
274 return true;
275 }if (origrect == null) {
276 origrect =  new java.awt.geom.Rectangle2D.Double (x, y, w, h);
277 }var halfW = this.getWidth () / 2.0;
278 var halfH = this.getHeight () / 2.0;
279 var xc = this.getX () + halfW;
280 var yc = this.getY () + halfH;
281 var angle = Math.toRadians (-this.getAngleStart ());
282 var xe = xc + halfW * Math.cos (angle);
283 var ye = yc + halfH * Math.sin (angle);
284 if (origrect.intersectsLine (xc, yc, xe, ye)) {
285 return false;
286 }angle += Math.toRadians (-this.getAngleExtent ());
287 xe = xc + halfW * Math.cos (angle);
288 ye = yc + halfH * Math.sin (angle);
289 return !origrect.intersectsLine (xc, yc, xe, ye);
290 }, "~N,~N,~N,~N,java.awt.geom.Rectangle2D");
291 Clazz.defineMethod (c$, "getPathIterator", 
292 function (at) {
293 return  new java.awt.geom.ArcIterator (this, at);
294 }, "java.awt.geom.AffineTransform");
295 Clazz.overrideMethod (c$, "hashCode", 
296 function () {
297 var bits = java.lang.Double.doubleToLongBits (this.getX ());
298 bits += java.lang.Double.doubleToLongBits (this.getY ()) * 37;
299 bits += java.lang.Double.doubleToLongBits (this.getWidth ()) * 43;
300 bits += java.lang.Double.doubleToLongBits (this.getHeight ()) * 47;
301 bits += java.lang.Double.doubleToLongBits (this.getAngleStart ()) * 53;
302 bits += java.lang.Double.doubleToLongBits (this.getAngleExtent ()) * 59;
303 bits += this.getArcType () * 61;
304 return ((bits) ^ ((bits >> 32)));
305 });
306 Clazz.overrideMethod (c$, "equals", 
307 function (obj) {
308 if (obj === this) {
309 return true;
310 }if (Clazz.instanceOf (obj, java.awt.geom.Arc2D)) {
311 var a2d = obj;
312 return ((this.getX () == a2d.getX ()) && (this.getY () == a2d.getY ()) && (this.getWidth () == a2d.getWidth ()) && (this.getHeight () == a2d.getHeight ()) && (this.getAngleStart () == a2d.getAngleStart ()) && (this.getAngleExtent () == a2d.getAngleExtent ()) && (this.getArcType () == a2d.getArcType ()));
313 }return false;
314 }, "~O");
315 Clazz.pu$h(self.c$);
316 c$ = Clazz.decorateAsClass (function () {
317 this.x = 0;
318 this.y = 0;
319 this.width = 0;
320 this.height = 0;
321 this.start = 0;
322 this.extent = 0;
323 Clazz.instantialize (this, arguments);
324 }, java.awt.geom.Arc2D, "Float", java.awt.geom.Arc2D);
325 Clazz.makeConstructor (c$, 
326 function () {
327 Clazz.superConstructor (this, java.awt.geom.Arc2D.Float, [0]);
328 });
329 Clazz.makeConstructor (c$, 
330 function (a, b, c, d, e, f, g) {
331 Clazz.superConstructor (this, java.awt.geom.Arc2D.Float, [g]);
332 this.x = a;
333 this.y = b;
334 this.width = c;
335 this.height = d;
336 this.start = e;
337 this.extent = f;
338 }, "~N,~N,~N,~N,~N,~N,~N");
339 Clazz.makeConstructor (c$, 
340 function (a, b, c, d) {
341 Clazz.superConstructor (this, java.awt.geom.Arc2D.Float, [d]);
342 this.x = a.getX ();
343 this.y = a.getY ();
344 this.width = a.getWidth ();
345 this.height = a.getHeight ();
346 this.start = b;
347 this.extent = c;
348 }, "java.awt.geom.Rectangle2D,~N,~N,~N");
349 Clazz.defineMethod (c$, "getX", 
350 function () {
351 return this.x;
352 });
353 Clazz.defineMethod (c$, "getY", 
354 function () {
355 return this.y;
356 });
357 Clazz.defineMethod (c$, "getWidth", 
358 function () {
359 return this.width;
360 });
361 Clazz.defineMethod (c$, "getHeight", 
362 function () {
363 return this.height;
364 });
365 Clazz.overrideMethod (c$, "getAngleStart", 
366 function () {
367 return this.start;
368 });
369 Clazz.overrideMethod (c$, "getAngleExtent", 
370 function () {
371 return this.extent;
372 });
373 Clazz.overrideMethod (c$, "isEmpty", 
374 function () {
375 return (this.width <= 0.0 || this.height <= 0.0);
376 });
377 Clazz.defineMethod (c$, "setArc", 
378 function (a, b, c, d, e, f, g) {
379 this.setArcType (g);
380 this.x = a;
381 this.y = b;
382 this.width = c;
383 this.height = d;
384 this.start = e;
385 this.extent = f;
386 }, "~N,~N,~N,~N,~N,~N,~N");
387 Clazz.defineMethod (c$, "setAngleStart", 
388 function (a) {
389 this.start = a;
390 }, "~N");
391 Clazz.overrideMethod (c$, "setAngleExtent", 
392 function (a) {
393 this.extent = a;
394 }, "~N");
395 Clazz.overrideMethod (c$, "makeBounds", 
396 function (a, b, c, d) {
397 return  new java.awt.geom.Rectangle2D.Float (a, b, c, d);
398 }, "~N,~N,~N,~N");
399 c$ = Clazz.p0p ();
400 Clazz.pu$h(self.c$);
401 c$ = Clazz.decorateAsClass (function () {
402 this.x = 0;
403 this.y = 0;
404 this.width = 0;
405 this.height = 0;
406 this.start = 0;
407 this.extent = 0;
408 Clazz.instantialize (this, arguments);
409 }, java.awt.geom.Arc2D, "Double", java.awt.geom.Arc2D);
410 Clazz.makeConstructor (c$, 
411 function () {
412 Clazz.superConstructor (this, java.awt.geom.Arc2D.Double, [0]);
413 });
414 Clazz.makeConstructor (c$, 
415 function (a, b, c, d, e, f, g) {
416 Clazz.superConstructor (this, java.awt.geom.Arc2D.Double, [g]);
417 this.x = a;
418 this.y = b;
419 this.width = c;
420 this.height = d;
421 this.start = e;
422 this.extent = f;
423 }, "~N,~N,~N,~N,~N,~N,~N");
424 Clazz.makeConstructor (c$, 
425 function (a, b, c, d) {
426 Clazz.superConstructor (this, java.awt.geom.Arc2D.Double, [d]);
427 this.x = a.getX ();
428 this.y = a.getY ();
429 this.width = a.getWidth ();
430 this.height = a.getHeight ();
431 this.start = b;
432 this.extent = c;
433 }, "java.awt.geom.Rectangle2D,~N,~N,~N");
434 Clazz.defineMethod (c$, "getX", 
435 function () {
436 return this.x;
437 });
438 Clazz.defineMethod (c$, "getY", 
439 function () {
440 return this.y;
441 });
442 Clazz.defineMethod (c$, "getWidth", 
443 function () {
444 return this.width;
445 });
446 Clazz.defineMethod (c$, "getHeight", 
447 function () {
448 return this.height;
449 });
450 Clazz.overrideMethod (c$, "getAngleStart", 
451 function () {
452 return this.start;
453 });
454 Clazz.overrideMethod (c$, "getAngleExtent", 
455 function () {
456 return this.extent;
457 });
458 Clazz.overrideMethod (c$, "isEmpty", 
459 function () {
460 return (this.width <= 0.0 || this.height <= 0.0);
461 });
462 Clazz.defineMethod (c$, "setArc", 
463 function (a, b, c, d, e, f, g) {
464 this.setArcType (g);
465 this.x = a;
466 this.y = b;
467 this.width = c;
468 this.height = d;
469 this.start = e;
470 this.extent = f;
471 }, "~N,~N,~N,~N,~N,~N,~N");
472 Clazz.defineMethod (c$, "setAngleStart", 
473 function (a) {
474 this.start = a;
475 }, "~N");
476 Clazz.overrideMethod (c$, "setAngleExtent", 
477 function (a) {
478 this.extent = a;
479 }, "~N");
480 Clazz.overrideMethod (c$, "makeBounds", 
481 function (a, b, c, d) {
482 return  new java.awt.geom.Rectangle2D.Double (a, b, c, d);
483 }, "~N,~N,~N,~N");
484 c$ = Clazz.p0p ();
485 Clazz.defineStatics (c$,
486 "OPEN", 0,
487 "CHORD", 1,
488 "PIE", 2);
489 });