1 /*
2 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
199 }
200
201 public Curve getSubCurve(double ystart, double yend, int dir) {
202 if (ystart == y0 && yend == y1) {
203 return getWithDirection(dir);
204 }
205 if (x0 == x1) {
206 return new Order1(x0, ystart, x1, yend, dir);
207 }
208 double num = x0 - x1;
209 double denom = y0 - y1;
210 double xstart = (x0 + (ystart - y0) * num / denom);
211 double xend = (x0 + (yend - y0) * num / denom);
212 return new Order1(xstart, ystart, xend, yend, dir);
213 }
214
215 public Curve getReversedCurve() {
216 return new Order1(x0, y0, x1, y1, -direction);
217 }
218
219 public int compareTo(Curve other, double yrange[]) {
220 if (!(other instanceof Order1)) {
221 return super.compareTo(other, yrange);
222 }
223 Order1 c1 = (Order1) other;
224 if (yrange[1] <= yrange[0]) {
225 throw new InternalError("yrange already screwed up...");
226 }
227 yrange[1] = Math.min(Math.min(yrange[1], y1), c1.y1);
228 if (yrange[1] <= yrange[0]) {
229 throw new InternalError("backstepping from "+yrange[0]+" to "+yrange[1]);
230 }
231 if (xmax <= c1.xmin) {
232 return (xmin == c1.xmax) ? 0 : -1;
233 }
234 if (xmin >= c1.xmax) {
235 return 1;
236 }
237 /*
238 * If "this" is curve A and "other" is curve B, then...
239 * xA(y) = x0A + (y - y0A) (x1A - x0A) / (y1A - y0A)
282 // Use bottom-most common y for comparison
283 y = Math.min(y1, c1.y1);
284 } else {
285 // intersection is below the top of our range
286 if (y < yrange[1]) {
287 // If intersection is in our range, adjust valid range
288 yrange[1] = y;
289 }
290 // Use top-most common y for comparison
291 y = Math.max(y0, c1.y0);
292 }
293 } else {
294 // lines are parallel, choose any common y for comparison
295 // Note - prefer an endpoint for speed of calculating the X
296 // (see shortcuts in Order1.XforY())
297 y = Math.max(y0, c1.y0);
298 }
299 return orderof(XforY(y), c1.XforY(y));
300 }
301
302 public int getSegment(double coords[]) {
303 if (direction == INCREASING) {
304 coords[0] = x1;
305 coords[1] = y1;
306 } else {
307 coords[0] = x0;
308 coords[1] = y0;
309 }
310 return PathIterator.SEG_LINETO;
311 }
312 }
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
199 }
200
201 public Curve getSubCurve(double ystart, double yend, int dir) {
202 if (ystart == y0 && yend == y1) {
203 return getWithDirection(dir);
204 }
205 if (x0 == x1) {
206 return new Order1(x0, ystart, x1, yend, dir);
207 }
208 double num = x0 - x1;
209 double denom = y0 - y1;
210 double xstart = (x0 + (ystart - y0) * num / denom);
211 double xend = (x0 + (yend - y0) * num / denom);
212 return new Order1(xstart, ystart, xend, yend, dir);
213 }
214
215 public Curve getReversedCurve() {
216 return new Order1(x0, y0, x1, y1, -direction);
217 }
218
219 public int compareTo(Curve other, double[] yrange) {
220 if (!(other instanceof Order1)) {
221 return super.compareTo(other, yrange);
222 }
223 Order1 c1 = (Order1) other;
224 if (yrange[1] <= yrange[0]) {
225 throw new InternalError("yrange already screwed up...");
226 }
227 yrange[1] = Math.min(Math.min(yrange[1], y1), c1.y1);
228 if (yrange[1] <= yrange[0]) {
229 throw new InternalError("backstepping from "+yrange[0]+" to "+yrange[1]);
230 }
231 if (xmax <= c1.xmin) {
232 return (xmin == c1.xmax) ? 0 : -1;
233 }
234 if (xmin >= c1.xmax) {
235 return 1;
236 }
237 /*
238 * If "this" is curve A and "other" is curve B, then...
239 * xA(y) = x0A + (y - y0A) (x1A - x0A) / (y1A - y0A)
282 // Use bottom-most common y for comparison
283 y = Math.min(y1, c1.y1);
284 } else {
285 // intersection is below the top of our range
286 if (y < yrange[1]) {
287 // If intersection is in our range, adjust valid range
288 yrange[1] = y;
289 }
290 // Use top-most common y for comparison
291 y = Math.max(y0, c1.y0);
292 }
293 } else {
294 // lines are parallel, choose any common y for comparison
295 // Note - prefer an endpoint for speed of calculating the X
296 // (see shortcuts in Order1.XforY())
297 y = Math.max(y0, c1.y0);
298 }
299 return orderof(XforY(y), c1.XforY(y));
300 }
301
302 public int getSegment(double[] coords) {
303 if (direction == INCREASING) {
304 coords[0] = x1;
305 coords[1] = y1;
306 } else {
307 coords[0] = x0;
308 coords[1] = y0;
309 }
310 return PathIterator.SEG_LINETO;
311 }
312 }
|