1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3
4
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 *
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation. Oracle designates this
10 * particular file as subject to the "Classpath" exception as provided
11 * by Oracle in the LICENSE file that accompanied this code.
12 *
13 * This code is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * version 2 for more details (a copy is included in the LICENSE file that
17 * accompanied this code).
18 *
19 * You should have received a copy of the GNU General Public License version
20 * 2 along with this work; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24 * or visit www.oracle.com if you need additional information or have any
232
233 if (outcode1 != 0) {
234 if ((outcode1 & (OUTCODE_TOP | OUTCODE_BOTTOM)) != 0) {
235 if ((outcode1 & OUTCODE_TOP) != 0) {
236 y1 = cymin;
237 } else {
238 y1 = cymax;
239 }
240 ysteps = y1 - ucY1;
241 if (ysteps < 0) {
242 ysteps = -ysteps;
243 }
244 xsteps = 2 * ysteps * ax + ay;
245 if (xmajor) {
246 xsteps += ay - ax - 1;
247 }
248 xsteps = xsteps / (2 * ay);
249 if (dx < 0) {
250 xsteps = -xsteps;
251 }
252 x1 = ucX1 + (int) xsteps;
253 } else if ((outcode1 & (OUTCODE_LEFT | OUTCODE_RIGHT)) != 0) {
254 if ((outcode1 & OUTCODE_LEFT) != 0) {
255 x1 = cxmin;
256 } else {
257 x1 = cxmax;
258 }
259 xsteps = x1 - ucX1;
260 if (xsteps < 0) {
261 xsteps = -xsteps;
262 }
263 ysteps = 2 * xsteps * ay + ax;
264 if (!xmajor) {
265 ysteps += ax - ay - 1;
266 }
267 ysteps = ysteps / (2 * ax);
268 if (dy < 0) {
269 ysteps = -ysteps;
270 }
271 y1 = ucY1 + (int) ysteps;
272 }
273 outcode1 = outcode(x1, y1, cxmin, cymin, cxmax, cymax);
274 } else {
275 if ((outcode2 & (OUTCODE_TOP | OUTCODE_BOTTOM)) != 0) {
276 if ((outcode2 & OUTCODE_TOP) != 0) {
277 y2 = cymin;
278 } else {
279 y2 = cymax;
280 }
281 ysteps = y2 - ucY2;
282 if (ysteps < 0) {
283 ysteps = -ysteps;
284 }
285 xsteps = 2 * ysteps * ax + ay;
286 if (xmajor) {
287 xsteps += ay - ax;
288 } else {
289 xsteps -= 1;
290 }
291 xsteps = xsteps / (2 * ay);
292 if (dx > 0) {
293 xsteps = -xsteps;
294 }
295 x2 = ucX2 + (int) xsteps;
296 } else if ((outcode2 & (OUTCODE_LEFT | OUTCODE_RIGHT)) != 0) {
297 if ((outcode2 & OUTCODE_LEFT) != 0) {
298 x2 = cxmin;
299 } else {
300 x2 = cxmax;
301 }
302 xsteps = x2 - ucX2;
303 if (xsteps < 0) {
304 xsteps = -xsteps;
305 }
306 ysteps = 2 * xsteps * ay + ax;
307 if (xmajor) {
308 ysteps -= 1;
309 } else {
310 ysteps += ax - ay;
311 }
312 ysteps = ysteps / (2 * ax);
313 if (dy > 0) {
314 ysteps = -ysteps;
315 }
316 y2 = ucY2 + (int) ysteps;
317 }
318 outcode2 = outcode(x2, y2, cxmin, cymin, cxmax, cymax);
319 }
320 }
321
322 return true;
323 }
324
325 private void initCoordinates(int x1, int y1, int x2, int y2,
326 boolean checkOverflow) {
327 /*
328 * Part of calculating the Bresenham parameters for line stepping
329 * involves being able to store numbers that are twice the magnitude of
330 * the biggest absolute difference in coordinates. Since we want the
331 * stepping parameters to be stored in jints, we then need to avoid any
332 * absolute differences more than 30 bits. Thus, we need to preprocess
333 * the coordinates to reduce their range to 30 bits regardless of
334 * clipping. We need to cut their range back before we do the clipping
335 * because the Bresenham stepping values need to be calculated based on
336 * the "unclipped" coordinates.
|
1 /*
2 * Copyright (c) 2013, 2014, 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
230
231 if (outcode1 != 0) {
232 if ((outcode1 & (OUTCODE_TOP | OUTCODE_BOTTOM)) != 0) {
233 if ((outcode1 & OUTCODE_TOP) != 0) {
234 y1 = cymin;
235 } else {
236 y1 = cymax;
237 }
238 ysteps = y1 - ucY1;
239 if (ysteps < 0) {
240 ysteps = -ysteps;
241 }
242 xsteps = 2 * ysteps * ax + ay;
243 if (xmajor) {
244 xsteps += ay - ax - 1;
245 }
246 xsteps = xsteps / (2 * ay);
247 if (dx < 0) {
248 xsteps = -xsteps;
249 }
250 x1 = ucX1 + xsteps;
251 } else if ((outcode1 & (OUTCODE_LEFT | OUTCODE_RIGHT)) != 0) {
252 if ((outcode1 & OUTCODE_LEFT) != 0) {
253 x1 = cxmin;
254 } else {
255 x1 = cxmax;
256 }
257 xsteps = x1 - ucX1;
258 if (xsteps < 0) {
259 xsteps = -xsteps;
260 }
261 ysteps = 2 * xsteps * ay + ax;
262 if (!xmajor) {
263 ysteps += ax - ay - 1;
264 }
265 ysteps = ysteps / (2 * ax);
266 if (dy < 0) {
267 ysteps = -ysteps;
268 }
269 y1 = ucY1 + ysteps;
270 }
271 outcode1 = outcode(x1, y1, cxmin, cymin, cxmax, cymax);
272 } else {
273 if ((outcode2 & (OUTCODE_TOP | OUTCODE_BOTTOM)) != 0) {
274 if ((outcode2 & OUTCODE_TOP) != 0) {
275 y2 = cymin;
276 } else {
277 y2 = cymax;
278 }
279 ysteps = y2 - ucY2;
280 if (ysteps < 0) {
281 ysteps = -ysteps;
282 }
283 xsteps = 2 * ysteps * ax + ay;
284 if (xmajor) {
285 xsteps += ay - ax;
286 } else {
287 xsteps -= 1;
288 }
289 xsteps = xsteps / (2 * ay);
290 if (dx > 0) {
291 xsteps = -xsteps;
292 }
293 x2 = ucX2 + xsteps;
294 } else if ((outcode2 & (OUTCODE_LEFT | OUTCODE_RIGHT)) != 0) {
295 if ((outcode2 & OUTCODE_LEFT) != 0) {
296 x2 = cxmin;
297 } else {
298 x2 = cxmax;
299 }
300 xsteps = x2 - ucX2;
301 if (xsteps < 0) {
302 xsteps = -xsteps;
303 }
304 ysteps = 2 * xsteps * ay + ax;
305 if (xmajor) {
306 ysteps -= 1;
307 } else {
308 ysteps += ax - ay;
309 }
310 ysteps = ysteps / (2 * ax);
311 if (dy > 0) {
312 ysteps = -ysteps;
313 }
314 y2 = ucY2 + ysteps;
315 }
316 outcode2 = outcode(x2, y2, cxmin, cymin, cxmax, cymax);
317 }
318 }
319
320 return true;
321 }
322
323 private void initCoordinates(int x1, int y1, int x2, int y2,
324 boolean checkOverflow) {
325 /*
326 * Part of calculating the Bresenham parameters for line stepping
327 * involves being able to store numbers that are twice the magnitude of
328 * the biggest absolute difference in coordinates. Since we want the
329 * stepping parameters to be stored in jints, we then need to avoid any
330 * absolute differences more than 30 bits. Thus, we need to preprocess
331 * the coordinates to reduce their range to 30 bits regardless of
332 * clipping. We need to cut their range back before we do the clipping
333 * because the Bresenham stepping values need to be calculated based on
334 * the "unclipped" coordinates.
|