f11b8a3e9391411bd9e9cf9ba04d0f01ac8d09d2
[jalviewjs.git] / site / j2s / jssun / awt / geom / Order1.js
1 Clazz.declarePackage ("jssun.awt.geom");
2 Clazz.load (["jssun.awt.geom.Curve"], "jssun.awt.geom.Order1", ["java.lang.InternalError"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.x0 = 0;
5 this.y0 = 0;
6 this.x1 = 0;
7 this.y1 = 0;
8 this.xmin = 0;
9 this.xmax = 0;
10 Clazz.instantialize (this, arguments);
11 }, jssun.awt.geom, "Order1", jssun.awt.geom.Curve);
12 Clazz.makeConstructor (c$, 
13 function (x0, y0, x1, y1, direction) {
14 Clazz.superConstructor (this, jssun.awt.geom.Order1, [direction]);
15 this.x0 = x0;
16 this.y0 = y0;
17 this.x1 = x1;
18 this.y1 = y1;
19 if (x0 < x1) {
20 this.xmin = x0;
21 this.xmax = x1;
22 } else {
23 this.xmin = x1;
24 this.xmax = x0;
25 }}, "~N,~N,~N,~N,~N");
26 Clazz.overrideMethod (c$, "getOrder", 
27 function () {
28 return 1;
29 });
30 Clazz.overrideMethod (c$, "getXTop", 
31 function () {
32 return this.x0;
33 });
34 Clazz.overrideMethod (c$, "getYTop", 
35 function () {
36 return this.y0;
37 });
38 Clazz.overrideMethod (c$, "getXBot", 
39 function () {
40 return this.x1;
41 });
42 Clazz.overrideMethod (c$, "getYBot", 
43 function () {
44 return this.y1;
45 });
46 Clazz.overrideMethod (c$, "getXMin", 
47 function () {
48 return this.xmin;
49 });
50 Clazz.overrideMethod (c$, "getXMax", 
51 function () {
52 return this.xmax;
53 });
54 Clazz.overrideMethod (c$, "getX0", 
55 function () {
56 return (this.direction == 1) ? this.x0 : this.x1;
57 });
58 Clazz.overrideMethod (c$, "getY0", 
59 function () {
60 return (this.direction == 1) ? this.y0 : this.y1;
61 });
62 Clazz.overrideMethod (c$, "getX1", 
63 function () {
64 return (this.direction == -1) ? this.x0 : this.x1;
65 });
66 Clazz.overrideMethod (c$, "getY1", 
67 function () {
68 return (this.direction == -1) ? this.y0 : this.y1;
69 });
70 Clazz.overrideMethod (c$, "XforY", 
71 function (y) {
72 if (this.x0 == this.x1 || y <= this.y0) {
73 return this.x0;
74 }if (y >= this.y1) {
75 return this.x1;
76 }return (this.x0 + (y - this.y0) * (this.x1 - this.x0) / (this.y1 - this.y0));
77 }, "~N");
78 Clazz.overrideMethod (c$, "TforY", 
79 function (y) {
80 if (y <= this.y0) {
81 return 0;
82 }if (y >= this.y1) {
83 return 1;
84 }return (y - this.y0) / (this.y1 - this.y0);
85 }, "~N");
86 Clazz.overrideMethod (c$, "XforT", 
87 function (t) {
88 return this.x0 + t * (this.x1 - this.x0);
89 }, "~N");
90 Clazz.overrideMethod (c$, "YforT", 
91 function (t) {
92 return this.y0 + t * (this.y1 - this.y0);
93 }, "~N");
94 Clazz.overrideMethod (c$, "dXforT", 
95 function (t, deriv) {
96 switch (deriv) {
97 case 0:
98 return this.x0 + t * (this.x1 - this.x0);
99 case 1:
100 return (this.x1 - this.x0);
101 default:
102 return 0;
103 }
104 }, "~N,~N");
105 Clazz.overrideMethod (c$, "dYforT", 
106 function (t, deriv) {
107 switch (deriv) {
108 case 0:
109 return this.y0 + t * (this.y1 - this.y0);
110 case 1:
111 return (this.y1 - this.y0);
112 default:
113 return 0;
114 }
115 }, "~N,~N");
116 Clazz.overrideMethod (c$, "nextVertical", 
117 function (t0, t1) {
118 return t1;
119 }, "~N,~N");
120 Clazz.overrideMethod (c$, "accumulateCrossings", 
121 function (c) {
122 var xlo = c.getXLo ();
123 var ylo = c.getYLo ();
124 var xhi = c.getXHi ();
125 var yhi = c.getYHi ();
126 if (this.xmin >= xhi) {
127 return false;
128 }var xstart;
129 var ystart;
130 var xend;
131 var yend;
132 if (this.y0 < ylo) {
133 if (this.y1 <= ylo) {
134 return false;
135 }ystart = ylo;
136 xstart = this.XforY (ylo);
137 } else {
138 if (this.y0 >= yhi) {
139 return false;
140 }ystart = this.y0;
141 xstart = this.x0;
142 }if (this.y1 > yhi) {
143 yend = yhi;
144 xend = this.XforY (yhi);
145 } else {
146 yend = this.y1;
147 xend = this.x1;
148 }if (xstart >= xhi && xend >= xhi) {
149 return false;
150 }if (xstart > xlo || xend > xlo) {
151 return true;
152 }c.record (ystart, yend, this.direction);
153 return false;
154 }, "jssun.awt.geom.Crossings");
155 Clazz.overrideMethod (c$, "enlarge", 
156 function (r) {
157 r.add (this.x0, this.y0);
158 r.add (this.x1, this.y1);
159 }, "java.awt.geom.Rectangle2D");
160 Clazz.defineMethod (c$, "getSubCurve", 
161 function (ystart, yend, dir) {
162 if (ystart == this.y0 && yend == this.y1) {
163 return this.getWithDirection (dir);
164 }if (this.x0 == this.x1) {
165 return  new jssun.awt.geom.Order1 (this.x0, ystart, this.x1, yend, dir);
166 }var num = this.x0 - this.x1;
167 var denom = this.y0 - this.y1;
168 var xstart = (this.x0 + (ystart - this.y0) * num / denom);
169 var xend = (this.x0 + (yend - this.y0) * num / denom);
170 return  new jssun.awt.geom.Order1 (xstart, ystart, xend, yend, dir);
171 }, "~N,~N,~N");
172 Clazz.overrideMethod (c$, "getReversedCurve", 
173 function () {
174 return  new jssun.awt.geom.Order1 (this.x0, this.y0, this.x1, this.y1, -this.direction);
175 });
176 Clazz.defineMethod (c$, "compareTo", 
177 function (other, yrange) {
178 if (!(Clazz.instanceOf (other, jssun.awt.geom.Order1))) {
179 return Clazz.superCall (this, jssun.awt.geom.Order1, "compareTo", [other, yrange]);
180 }var c1 = other;
181 if (yrange[1] <= yrange[0]) {
182 throw  new InternalError ("yrange already screwed up...");
183 }yrange[1] = Math.min (Math.min (yrange[1], this.y1), c1.y1);
184 if (yrange[1] <= yrange[0]) {
185 throw  new InternalError ("backstepping from " + yrange[0] + " to " + yrange[1]);
186 }if (this.xmax <= c1.xmin) {
187 return (this.xmin == c1.xmax) ? 0 : -1;
188 }if (this.xmin >= c1.xmax) {
189 return 1;
190 }var dxa = this.x1 - this.x0;
191 var dya = this.y1 - this.y0;
192 var dxb = c1.x1 - c1.x0;
193 var dyb = c1.y1 - c1.y0;
194 var denom = dxb * dya - dxa * dyb;
195 var y;
196 if (denom != 0) {
197 var num = ((this.x0 - c1.x0) * dya * dyb - this.y0 * dxa * dyb + c1.y0 * dxb * dya);
198 y = num / denom;
199 if (y <= yrange[0]) {
200 y = Math.min (this.y1, c1.y1);
201 } else {
202 if (y < yrange[1]) {
203 yrange[1] = y;
204 }y = Math.max (this.y0, c1.y0);
205 }} else {
206 y = Math.max (this.y0, c1.y0);
207 }return jssun.awt.geom.Curve.orderof (this.XforY (y), c1.XforY (y));
208 }, "jssun.awt.geom.Curve,~A");
209 Clazz.overrideMethod (c$, "getSegment", 
210 function (coords) {
211 if (this.direction == 1) {
212 coords[0] = this.x1;
213 coords[1] = this.y1;
214 } else {
215 coords[0] = this.x0;
216 coords[1] = this.y0;
217 }return 1;
218 }, "~A");
219 });