Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / geom / Line2D.js
1 Clazz.declarePackage ("java.awt.geom");
2 Clazz.load (["java.awt.Shape"], "java.awt.geom.Line2D", ["java.lang.InternalError", "java.awt.geom.LineIterator", "$.Point2D", "$.Rectangle2D"], function () {
3 c$ = Clazz.declareType (java.awt.geom, "Line2D", null, [java.awt.Shape, Cloneable]);
4 Clazz.makeConstructor (c$, 
5 function () {
6 });
7 Clazz.defineMethod (c$, "setLine", 
8 function (p1, p2) {
9 this.setLine (p1.getX (), p1.getY (), p2.getX (), p2.getY ());
10 }, "java.awt.geom.Point2D,java.awt.geom.Point2D");
11 Clazz.defineMethod (c$, "setLine", 
12 function (l) {
13 this.setLine (l.getX1 (), l.getY1 (), l.getX2 (), l.getY2 ());
14 }, "java.awt.geom.Line2D");
15 c$.relativeCCW = Clazz.defineMethod (c$, "relativeCCW", 
16 function (x1, y1, x2, y2, px, py) {
17 x2 -= x1;
18 y2 -= y1;
19 px -= x1;
20 py -= y1;
21 var ccw = px * y2 - py * x2;
22 if (ccw == 0.0) {
23 ccw = px * x2 + py * y2;
24 if (ccw > 0.0) {
25 px -= x2;
26 py -= y2;
27 ccw = px * x2 + py * y2;
28 if (ccw < 0.0) {
29 ccw = 0.0;
30 }}}return (ccw < 0.0) ? -1 : ((ccw > 0.0) ? 1 : 0);
31 }, "~N,~N,~N,~N,~N,~N");
32 Clazz.defineMethod (c$, "relativeCCW", 
33 function (px, py) {
34 return java.awt.geom.Line2D.relativeCCW (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), px, py);
35 }, "~N,~N");
36 Clazz.defineMethod (c$, "relativeCCW", 
37 function (p) {
38 return java.awt.geom.Line2D.relativeCCW (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), p.getX (), p.getY ());
39 }, "java.awt.geom.Point2D");
40 c$.linesIntersect = Clazz.defineMethod (c$, "linesIntersect", 
41 function (x1, y1, x2, y2, x3, y3, x4, y4) {
42 return ((java.awt.geom.Line2D.relativeCCW (x1, y1, x2, y2, x3, y3) * java.awt.geom.Line2D.relativeCCW (x1, y1, x2, y2, x4, y4) <= 0) && (java.awt.geom.Line2D.relativeCCW (x3, y3, x4, y4, x1, y1) * java.awt.geom.Line2D.relativeCCW (x3, y3, x4, y4, x2, y2) <= 0));
43 }, "~N,~N,~N,~N,~N,~N,~N,~N");
44 Clazz.defineMethod (c$, "intersectsLine", 
45 function (x1, y1, x2, y2) {
46 return java.awt.geom.Line2D.linesIntersect (x1, y1, x2, y2, this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 ());
47 }, "~N,~N,~N,~N");
48 Clazz.defineMethod (c$, "intersectsLine", 
49 function (l) {
50 return java.awt.geom.Line2D.linesIntersect (l.getX1 (), l.getY1 (), l.getX2 (), l.getY2 (), this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 ());
51 }, "java.awt.geom.Line2D");
52 c$.ptSegDistSq = Clazz.defineMethod (c$, "ptSegDistSq", 
53 function (x1, y1, x2, y2, px, py) {
54 x2 -= x1;
55 y2 -= y1;
56 px -= x1;
57 py -= y1;
58 var dotprod = px * x2 + py * y2;
59 var projlenSq;
60 if (dotprod <= 0.0) {
61 projlenSq = 0.0;
62 } else {
63 px = x2 - px;
64 py = y2 - py;
65 dotprod = px * x2 + py * y2;
66 if (dotprod <= 0.0) {
67 projlenSq = 0.0;
68 } else {
69 projlenSq = dotprod * dotprod / (x2 * x2 + y2 * y2);
70 }}var lenSq = px * px + py * py - projlenSq;
71 if (lenSq < 0) {
72 lenSq = 0;
73 }return lenSq;
74 }, "~N,~N,~N,~N,~N,~N");
75 c$.ptSegDist = Clazz.defineMethod (c$, "ptSegDist", 
76 function (x1, y1, x2, y2, px, py) {
77 return Math.sqrt (java.awt.geom.Line2D.ptSegDistSq (x1, y1, x2, y2, px, py));
78 }, "~N,~N,~N,~N,~N,~N");
79 Clazz.defineMethod (c$, "ptSegDistSq", 
80 function (px, py) {
81 return java.awt.geom.Line2D.ptSegDistSq (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), px, py);
82 }, "~N,~N");
83 Clazz.defineMethod (c$, "ptSegDistSq", 
84 function (pt) {
85 return java.awt.geom.Line2D.ptSegDistSq (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), pt.getX (), pt.getY ());
86 }, "java.awt.geom.Point2D");
87 Clazz.defineMethod (c$, "ptSegDist", 
88 function (px, py) {
89 return java.awt.geom.Line2D.ptSegDist (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), px, py);
90 }, "~N,~N");
91 Clazz.defineMethod (c$, "ptSegDist", 
92 function (pt) {
93 return java.awt.geom.Line2D.ptSegDist (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), pt.getX (), pt.getY ());
94 }, "java.awt.geom.Point2D");
95 c$.ptLineDistSq = Clazz.defineMethod (c$, "ptLineDistSq", 
96 function (x1, y1, x2, y2, px, py) {
97 x2 -= x1;
98 y2 -= y1;
99 px -= x1;
100 py -= y1;
101 var dotprod = px * x2 + py * y2;
102 var projlenSq = dotprod * dotprod / (x2 * x2 + y2 * y2);
103 var lenSq = px * px + py * py - projlenSq;
104 if (lenSq < 0) {
105 lenSq = 0;
106 }return lenSq;
107 }, "~N,~N,~N,~N,~N,~N");
108 c$.ptLineDist = Clazz.defineMethod (c$, "ptLineDist", 
109 function (x1, y1, x2, y2, px, py) {
110 return Math.sqrt (java.awt.geom.Line2D.ptLineDistSq (x1, y1, x2, y2, px, py));
111 }, "~N,~N,~N,~N,~N,~N");
112 Clazz.defineMethod (c$, "ptLineDistSq", 
113 function (px, py) {
114 return java.awt.geom.Line2D.ptLineDistSq (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), px, py);
115 }, "~N,~N");
116 Clazz.defineMethod (c$, "ptLineDistSq", 
117 function (pt) {
118 return java.awt.geom.Line2D.ptLineDistSq (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), pt.getX (), pt.getY ());
119 }, "java.awt.geom.Point2D");
120 Clazz.defineMethod (c$, "ptLineDist", 
121 function (px, py) {
122 return java.awt.geom.Line2D.ptLineDist (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), px, py);
123 }, "~N,~N");
124 Clazz.defineMethod (c$, "ptLineDist", 
125 function (pt) {
126 return java.awt.geom.Line2D.ptLineDist (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 (), pt.getX (), pt.getY ());
127 }, "java.awt.geom.Point2D");
128 Clazz.defineMethod (c$, "contains", 
129 function (x, y) {
130 return false;
131 }, "~N,~N");
132 Clazz.defineMethod (c$, "contains", 
133 function (p) {
134 return false;
135 }, "java.awt.geom.Point2D");
136 Clazz.defineMethod (c$, "intersects", 
137 function (x, y, w, h) {
138 return this.intersects ( new java.awt.geom.Rectangle2D.Double (x, y, w, h));
139 }, "~N,~N,~N,~N");
140 Clazz.defineMethod (c$, "intersects", 
141 function (r) {
142 return r.intersectsLine (this.getX1 (), this.getY1 (), this.getX2 (), this.getY2 ());
143 }, "java.awt.geom.Rectangle2D");
144 Clazz.defineMethod (c$, "contains", 
145 function (x, y, w, h) {
146 return false;
147 }, "~N,~N,~N,~N");
148 Clazz.defineMethod (c$, "contains", 
149 function (r) {
150 return false;
151 }, "java.awt.geom.Rectangle2D");
152 Clazz.overrideMethod (c$, "getBounds", 
153 function () {
154 return this.getBounds2D ().getBounds ();
155 });
156 Clazz.defineMethod (c$, "getPathIterator", 
157 function (at) {
158 return  new java.awt.geom.LineIterator (this, at);
159 }, "java.awt.geom.AffineTransform");
160 Clazz.defineMethod (c$, "getPathIterator", 
161 function (at, flatness) {
162 return  new java.awt.geom.LineIterator (this, at);
163 }, "java.awt.geom.AffineTransform,~N");
164 Clazz.defineMethod (c$, "clone", 
165 function () {
166 try {
167 return Clazz.superCall (this, java.awt.geom.Line2D, "clone", []);
168 } catch (e) {
169 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
170 throw  new InternalError ();
171 } else {
172 throw e;
173 }
174 }
175 });
176 Clazz.pu$h(self.c$);
177 c$ = Clazz.decorateAsClass (function () {
178 this.x1 = 0;
179 this.y1 = 0;
180 this.x2 = 0;
181 this.y2 = 0;
182 Clazz.instantialize (this, arguments);
183 }, java.awt.geom.Line2D, "Float", java.awt.geom.Line2D);
184 Clazz.makeConstructor (c$, 
185 function () {
186 Clazz.superConstructor (this, java.awt.geom.Line2D.Float, []);
187 });
188 Clazz.makeConstructor (c$, 
189 function (a, b, c, d) {
190 Clazz.superConstructor (this, java.awt.geom.Line2D.Float, []);
191 this.setLine (a, b, c, d);
192 }, "~N,~N,~N,~N");
193 Clazz.makeConstructor (c$, 
194 function (a, b) {
195 Clazz.superConstructor (this, java.awt.geom.Line2D.Float, []);
196 this.setLine (a, b);
197 }, "java.awt.geom.Point2D,java.awt.geom.Point2D");
198 Clazz.overrideMethod (c$, "getX1", 
199 function () {
200 return this.x1;
201 });
202 Clazz.overrideMethod (c$, "getY1", 
203 function () {
204 return this.y1;
205 });
206 Clazz.overrideMethod (c$, "getP1", 
207 function () {
208 return  new java.awt.geom.Point2D.Float (this.x1, this.y1);
209 });
210 Clazz.overrideMethod (c$, "getX2", 
211 function () {
212 return this.x2;
213 });
214 Clazz.overrideMethod (c$, "getY2", 
215 function () {
216 return this.y2;
217 });
218 Clazz.overrideMethod (c$, "getP2", 
219 function () {
220 return  new java.awt.geom.Point2D.Float (this.x2, this.y2);
221 });
222 Clazz.defineMethod (c$, "setLine", 
223 function (a, b, c, d) {
224 this.x1 = a;
225 this.y1 = b;
226 this.x2 = c;
227 this.y2 = d;
228 }, "~N,~N,~N,~N");
229 Clazz.defineMethod (c$, "setLine", 
230 function (a, b, c, d) {
231 this.x1 = a;
232 this.y1 = b;
233 this.x2 = c;
234 this.y2 = d;
235 }, "~N,~N,~N,~N");
236 Clazz.overrideMethod (c$, "getBounds2D", 
237 function () {
238 var a;
239 var b;
240 var c;
241 var d;
242 if (this.x1 < this.x2) {
243 a = this.x1;
244 c = this.x2 - this.x1;
245 } else {
246 a = this.x2;
247 c = this.x1 - this.x2;
248 }if (this.y1 < this.y2) {
249 b = this.y1;
250 d = this.y2 - this.y1;
251 } else {
252 b = this.y2;
253 d = this.y1 - this.y2;
254 }return  new java.awt.geom.Rectangle2D.Float (a, b, c, d);
255 });
256 c$ = Clazz.p0p ();
257 Clazz.pu$h(self.c$);
258 c$ = Clazz.decorateAsClass (function () {
259 this.x1 = 0;
260 this.y1 = 0;
261 this.x2 = 0;
262 this.y2 = 0;
263 Clazz.instantialize (this, arguments);
264 }, java.awt.geom.Line2D, "Double", java.awt.geom.Line2D);
265 Clazz.makeConstructor (c$, 
266 function () {
267 Clazz.superConstructor (this, java.awt.geom.Line2D.Double, []);
268 });
269 Clazz.makeConstructor (c$, 
270 function (a, b, c, d) {
271 Clazz.superConstructor (this, java.awt.geom.Line2D.Double, []);
272 this.setLine (a, b, c, d);
273 }, "~N,~N,~N,~N");
274 Clazz.makeConstructor (c$, 
275 function (a, b) {
276 Clazz.superConstructor (this, java.awt.geom.Line2D.Double, []);
277 this.setLine (a, b);
278 }, "java.awt.geom.Point2D,java.awt.geom.Point2D");
279 Clazz.overrideMethod (c$, "getX1", 
280 function () {
281 return this.x1;
282 });
283 Clazz.overrideMethod (c$, "getY1", 
284 function () {
285 return this.y1;
286 });
287 Clazz.overrideMethod (c$, "getP1", 
288 function () {
289 return  new java.awt.geom.Point2D.Double (this.x1, this.y1);
290 });
291 Clazz.overrideMethod (c$, "getX2", 
292 function () {
293 return this.x2;
294 });
295 Clazz.overrideMethod (c$, "getY2", 
296 function () {
297 return this.y2;
298 });
299 Clazz.overrideMethod (c$, "getP2", 
300 function () {
301 return  new java.awt.geom.Point2D.Double (this.x2, this.y2);
302 });
303 Clazz.defineMethod (c$, "setLine", 
304 function (a, b, c, d) {
305 this.x1 = a;
306 this.y1 = b;
307 this.x2 = c;
308 this.y2 = d;
309 }, "~N,~N,~N,~N");
310 Clazz.overrideMethod (c$, "getBounds2D", 
311 function () {
312 var a;
313 var b;
314 var c;
315 var d;
316 if (this.x1 < this.x2) {
317 a = this.x1;
318 c = this.x2 - this.x1;
319 } else {
320 a = this.x2;
321 c = this.x1 - this.x2;
322 }if (this.y1 < this.y2) {
323 b = this.y1;
324 d = this.y2 - this.y1;
325 } else {
326 b = this.y2;
327 d = this.y1 - this.y2;
328 }return  new java.awt.geom.Rectangle2D.Double (a, b, c, d);
329 });
330 c$ = Clazz.p0p ();
331 });