Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / Rectangle.js
1 Clazz.declarePackage ("java.awt");
2 Clazz.load (["java.awt.Shape", "java.awt.geom.Rectangle2D"], "java.awt.Rectangle", ["java.awt.Dimension", "$.Point"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.x = 0;
5 this.y = 0;
6 this.width = 0;
7 this.height = 0;
8 Clazz.instantialize (this, arguments);
9 }, java.awt, "Rectangle", java.awt.geom.Rectangle2D, java.awt.Shape);
10 Clazz.makeConstructor (c$, 
11 function () {
12 this.construct (0, 0, 0, 0);
13 });
14 Clazz.makeConstructor (c$, 
15 function (r) {
16 this.construct (r.x, r.y, r.width, r.height);
17 }, "java.awt.Rectangle");
18 Clazz.makeConstructor (c$, 
19 function (x, y, width, height) {
20 Clazz.superConstructor (this, java.awt.Rectangle, []);
21 this.x = x;
22 this.y = y;
23 this.width = width;
24 this.height = height;
25 }, "~N,~N,~N,~N");
26 Clazz.makeConstructor (c$, 
27 function (width, height) {
28 this.construct (0, 0, width, height);
29 }, "~N,~N");
30 Clazz.makeConstructor (c$, 
31 function (p, d) {
32 this.construct (p.x, p.y, d.width, d.height);
33 }, "java.awt.Point,java.awt.Dimension");
34 Clazz.makeConstructor (c$, 
35 function (p) {
36 this.construct (p.x, p.y, 0, 0);
37 }, "java.awt.Point");
38 Clazz.makeConstructor (c$, 
39 function (d) {
40 this.construct (0, 0, d.width, d.height);
41 }, "java.awt.Dimension");
42 Clazz.overrideMethod (c$, "getX", 
43 function () {
44 return this.x;
45 });
46 Clazz.overrideMethod (c$, "getY", 
47 function () {
48 return this.y;
49 });
50 Clazz.overrideMethod (c$, "getWidth", 
51 function () {
52 return this.width;
53 });
54 Clazz.overrideMethod (c$, "getHeight", 
55 function () {
56 return this.height;
57 });
58 Clazz.overrideMethod (c$, "getBounds", 
59 function () {
60 return  new java.awt.Rectangle (this.x, this.y, this.width, this.height);
61 });
62 Clazz.overrideMethod (c$, "getBounds2D", 
63 function () {
64 return  new java.awt.Rectangle (this.x, this.y, this.width, this.height);
65 });
66 Clazz.defineMethod (c$, "setBounds", 
67 function (r) {
68 this.reshape (r.x, r.y, r.width, r.height);
69 }, "java.awt.Rectangle");
70 Clazz.defineMethod (c$, "setBounds", 
71 function (x, y, width, height) {
72 this.reshape (x, y, width, height);
73 }, "~N,~N,~N,~N");
74 Clazz.defineMethod (c$, "setRect", 
75 function (x, y, width, height) {
76 var newx;
77 var newy;
78 var neww;
79 var newh;
80 if (x > 4.294967294E9) {
81 newx = 2147483647;
82 neww = -1;
83 } else {
84 newx = java.awt.Rectangle.clip (x, false);
85 if (width >= 0) width += x - newx;
86 neww = java.awt.Rectangle.clip (width, width >= 0);
87 }if (y > 4.294967294E9) {
88 newy = 2147483647;
89 newh = -1;
90 } else {
91 newy = java.awt.Rectangle.clip (y, false);
92 if (height >= 0) height += y - newy;
93 newh = java.awt.Rectangle.clip (height, height >= 0);
94 }this.reshape (newx, newy, neww, newh);
95 }, "~N,~N,~N,~N");
96 c$.clip = Clazz.defineMethod (c$, "clip", 
97  function (v, doceil) {
98 if (v <= -2147483648) {
99 return -2147483648;
100 }if (v >= 2147483647) {
101 return 2147483647;
102 }return Clazz.doubleToInt (doceil ? Math.ceil (v) : Math.floor (v));
103 }, "~N,~B");
104 Clazz.defineMethod (c$, "reshape", 
105 function (x, y, width, height) {
106 this.x = x;
107 this.y = y;
108 this.width = width;
109 this.height = height;
110 }, "~N,~N,~N,~N");
111 Clazz.defineMethod (c$, "getLocation", 
112 function () {
113 return  new java.awt.Point (this.x, this.y);
114 });
115 Clazz.defineMethod (c$, "setLocation", 
116 function (p) {
117 this.setLocation (p.x, p.y);
118 }, "java.awt.Point");
119 Clazz.defineMethod (c$, "setLocation", 
120 function (x, y) {
121 this.move (x, y);
122 }, "~N,~N");
123 Clazz.defineMethod (c$, "move", 
124 function (x, y) {
125 this.x = x;
126 this.y = y;
127 }, "~N,~N");
128 Clazz.defineMethod (c$, "translate", 
129 function (dx, dy) {
130 var oldv = this.x;
131 var newv = oldv + dx;
132 if (dx < 0) {
133 if (newv > oldv) {
134 if (this.width >= 0) {
135 this.width += newv - -2147483648;
136 }newv = -2147483648;
137 }} else {
138 if (newv < oldv) {
139 if (this.width >= 0) {
140 this.width += newv - 2147483647;
141 if (this.width < 0) this.width = 2147483647;
142 }newv = 2147483647;
143 }}this.x = newv;
144 oldv = this.y;
145 newv = oldv + dy;
146 if (dy < 0) {
147 if (newv > oldv) {
148 if (this.height >= 0) {
149 this.height += newv - -2147483648;
150 }newv = -2147483648;
151 }} else {
152 if (newv < oldv) {
153 if (this.height >= 0) {
154 this.height += newv - 2147483647;
155 if (this.height < 0) this.height = 2147483647;
156 }newv = 2147483647;
157 }}this.y = newv;
158 }, "~N,~N");
159 Clazz.defineMethod (c$, "getSize", 
160 function () {
161 return  new java.awt.Dimension (this.width, this.height);
162 });
163 Clazz.defineMethod (c$, "setSize", 
164 function (d) {
165 this.setSize (d.width, d.height);
166 }, "java.awt.Dimension");
167 Clazz.defineMethod (c$, "setSize", 
168 function (width, height) {
169 this.resize (width, height);
170 }, "~N,~N");
171 Clazz.defineMethod (c$, "resize", 
172 function (width, height) {
173 this.width = width;
174 this.height = height;
175 }, "~N,~N");
176 Clazz.defineMethod (c$, "contains", 
177 function (p) {
178 return this.contains (p.x, p.y);
179 }, "java.awt.Point");
180 Clazz.defineMethod (c$, "contains", 
181 function (x, y) {
182 return this.inside (x, y);
183 }, "~N,~N");
184 Clazz.defineMethod (c$, "contains", 
185 function (r) {
186 return this.contains (r.x, r.y, r.width, r.height);
187 }, "java.awt.Rectangle");
188 Clazz.defineMethod (c$, "contains", 
189 function (X, Y, W, H) {
190 var w = this.width;
191 var h = this.height;
192 if ((w | h | W | H) < 0) {
193 return false;
194 }var x = this.x;
195 var y = this.y;
196 if (X < x || Y < y) {
197 return false;
198 }w += x;
199 W += X;
200 if (W <= X) {
201 if (w >= x || W > w) return false;
202 } else {
203 if (w >= x && W > w) return false;
204 }h += y;
205 H += Y;
206 if (H <= Y) {
207 if (h >= y || H > h) return false;
208 } else {
209 if (h >= y && H > h) return false;
210 }return true;
211 }, "~N,~N,~N,~N");
212 Clazz.defineMethod (c$, "inside", 
213 function (X, Y) {
214 var w = this.width;
215 var h = this.height;
216 if ((w | h) < 0) {
217 return false;
218 }var x = this.x;
219 var y = this.y;
220 if (X < x || Y < y) {
221 return false;
222 }w += x;
223 h += y;
224 return ((w < x || w > X) && (h < y || h > Y));
225 }, "~N,~N");
226 Clazz.defineMethod (c$, "intersects", 
227 function (r) {
228 var tw = this.width;
229 var th = this.height;
230 var rw = r.width;
231 var rh = r.height;
232 if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
233 return false;
234 }var tx = this.x;
235 var ty = this.y;
236 var rx = r.x;
237 var ry = r.y;
238 rw += rx;
239 rh += ry;
240 tw += tx;
241 th += ty;
242 return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
243 }, "java.awt.Rectangle");
244 Clazz.defineMethod (c$, "intersection", 
245 function (r) {
246 var tx1 = this.x;
247 var ty1 = this.y;
248 var rx1 = r.x;
249 var ry1 = r.y;
250 var tx2 = tx1;
251 tx2 += this.width;
252 var ty2 = ty1;
253 ty2 += this.height;
254 var rx2 = rx1;
255 rx2 += r.width;
256 var ry2 = ry1;
257 ry2 += r.height;
258 if (tx1 < rx1) tx1 = rx1;
259 if (ty1 < ry1) ty1 = ry1;
260 if (tx2 > rx2) tx2 = rx2;
261 if (ty2 > ry2) ty2 = ry2;
262 tx2 -= tx1;
263 ty2 -= ty1;
264 if (tx2 < -2147483648) tx2 = -2147483648;
265 if (ty2 < -2147483648) ty2 = -2147483648;
266 return  new java.awt.Rectangle (tx1, ty1, tx2, ty2);
267 }, "java.awt.Rectangle");
268 Clazz.defineMethod (c$, "union", 
269 function (r) {
270 var tx2 = this.width;
271 var ty2 = this.height;
272 if ((tx2 | ty2) < 0) {
273 return  new java.awt.Rectangle (r);
274 }var rx2 = r.width;
275 var ry2 = r.height;
276 if ((rx2 | ry2) < 0) {
277 return  new java.awt.Rectangle (this);
278 }var tx1 = this.x;
279 var ty1 = this.y;
280 tx2 += tx1;
281 ty2 += ty1;
282 var rx1 = r.x;
283 var ry1 = r.y;
284 rx2 += rx1;
285 ry2 += ry1;
286 if (tx1 > rx1) tx1 = rx1;
287 if (ty1 > ry1) ty1 = ry1;
288 if (tx2 < rx2) tx2 = rx2;
289 if (ty2 < ry2) ty2 = ry2;
290 tx2 -= tx1;
291 ty2 -= ty1;
292 if (tx2 > 2147483647) tx2 = 2147483647;
293 if (ty2 > 2147483647) ty2 = 2147483647;
294 return  new java.awt.Rectangle (tx1, ty1, tx2, ty2);
295 }, "java.awt.Rectangle");
296 Clazz.defineMethod (c$, "add", 
297 function (newx, newy) {
298 if ((this.width | this.height) < 0) {
299 this.x = newx;
300 this.y = newy;
301 this.width = this.height = 0;
302 return;
303 }var x1 = this.x;
304 var y1 = this.y;
305 var x2 = this.width;
306 var y2 = this.height;
307 x2 += x1;
308 y2 += y1;
309 if (x1 > newx) x1 = newx;
310 if (y1 > newy) y1 = newy;
311 if (x2 < newx) x2 = newx;
312 if (y2 < newy) y2 = newy;
313 x2 -= x1;
314 y2 -= y1;
315 if (x2 > 2147483647) x2 = 2147483647;
316 if (y2 > 2147483647) y2 = 2147483647;
317 this.reshape (x1, y1, x2, y2);
318 }, "~N,~N");
319 Clazz.defineMethod (c$, "add", 
320 function (pt) {
321 this.add (pt.x, pt.y);
322 }, "java.awt.Point");
323 Clazz.defineMethod (c$, "add", 
324 function (r) {
325 var tx2 = this.width;
326 var ty2 = this.height;
327 if ((tx2 | ty2) < 0) {
328 this.reshape (r.x, r.y, r.width, r.height);
329 }var rx2 = r.width;
330 var ry2 = r.height;
331 if ((rx2 | ry2) < 0) {
332 return;
333 }var tx1 = this.x;
334 var ty1 = this.y;
335 tx2 += tx1;
336 ty2 += ty1;
337 var rx1 = r.x;
338 var ry1 = r.y;
339 rx2 += rx1;
340 ry2 += ry1;
341 if (tx1 > rx1) tx1 = rx1;
342 if (ty1 > ry1) ty1 = ry1;
343 if (tx2 < rx2) tx2 = rx2;
344 if (ty2 < ry2) ty2 = ry2;
345 tx2 -= tx1;
346 ty2 -= ty1;
347 if (tx2 > 2147483647) tx2 = 2147483647;
348 if (ty2 > 2147483647) ty2 = 2147483647;
349 this.reshape (tx1, ty1, tx2, ty2);
350 }, "java.awt.Rectangle");
351 Clazz.defineMethod (c$, "grow", 
352 function (h, v) {
353 var x0 = this.x;
354 var y0 = this.y;
355 var x1 = this.width;
356 var y1 = this.height;
357 x1 += x0;
358 y1 += y0;
359 x0 -= h;
360 y0 -= v;
361 x1 += h;
362 y1 += v;
363 if (x1 < x0) {
364 x1 -= x0;
365 if (x1 < -2147483648) x1 = -2147483648;
366 if (x0 < -2147483648) x0 = -2147483648;
367  else if (x0 > 2147483647) x0 = 2147483647;
368 } else {
369 if (x0 < -2147483648) x0 = -2147483648;
370  else if (x0 > 2147483647) x0 = 2147483647;
371 x1 -= x0;
372 if (x1 < -2147483648) x1 = -2147483648;
373  else if (x1 > 2147483647) x1 = 2147483647;
374 }if (y1 < y0) {
375 y1 -= y0;
376 if (y1 < -2147483648) y1 = -2147483648;
377 if (y0 < -2147483648) y0 = -2147483648;
378  else if (y0 > 2147483647) y0 = 2147483647;
379 } else {
380 if (y0 < -2147483648) y0 = -2147483648;
381  else if (y0 > 2147483647) y0 = 2147483647;
382 y1 -= y0;
383 if (y1 < -2147483648) y1 = -2147483648;
384  else if (y1 > 2147483647) y1 = 2147483647;
385 }this.reshape (x0, y0, x1, y1);
386 }, "~N,~N");
387 Clazz.overrideMethod (c$, "isEmpty", 
388 function () {
389 return (this.width <= 0) || (this.height <= 0);
390 });
391 Clazz.defineMethod (c$, "outcode", 
392 function (x, y) {
393 var out = 0;
394 if (this.width <= 0) {
395 out |= 5;
396 } else if (x < this.x) {
397 out |= 1;
398 } else if (x > this.x + this.width) {
399 out |= 4;
400 }if (this.height <= 0) {
401 out |= 10;
402 } else if (y < this.y) {
403 out |= 2;
404 } else if (y > this.y + this.height) {
405 out |= 8;
406 }return out;
407 }, "~N,~N");
408 Clazz.overrideMethod (c$, "createIntersection", 
409 function (r) {
410 if (Clazz.instanceOf (r, java.awt.Rectangle)) {
411 return this.intersection (r);
412 }var dest =  new java.awt.geom.Rectangle2D.Double ();
413 java.awt.geom.Rectangle2D.intersect (this, r, dest);
414 return dest;
415 }, "java.awt.geom.Rectangle2D");
416 Clazz.overrideMethod (c$, "createUnion", 
417 function (r) {
418 if (Clazz.instanceOf (r, java.awt.Rectangle)) {
419 return this.union (r);
420 }var dest =  new java.awt.geom.Rectangle2D.Double ();
421 java.awt.geom.Rectangle2D.union (this, r, dest);
422 return dest;
423 }, "java.awt.geom.Rectangle2D");
424 Clazz.defineMethod (c$, "equals", 
425 function (obj) {
426 if (Clazz.instanceOf (obj, java.awt.Rectangle)) {
427 var r = obj;
428 return ((this.x == r.x) && (this.y == r.y) && (this.width == r.width) && (this.height == r.height));
429 }return Clazz.superCall (this, java.awt.Rectangle, "equals", [obj]);
430 }, "~O");
431 Clazz.overrideMethod (c$, "toString", 
432 function () {
433 return this.getClass ().getName () + "[x=" + this.x + ",y=" + this.y + ",width=" + this.width + ",height=" + this.height + "]";
434 });
435 });