Java Code Examples for java.awt.geom.PathIterator#SEG_QUADTO
The following examples show how to use
java.awt.geom.PathIterator#SEG_QUADTO .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShapeUtils.java From pumpernickel with MIT License | 6 votes |
/** * Return false if any coordinates in this shape contain NaN or Infinite * values. */ public static boolean isValid(Shape shape) { PathIterator i = shape.getPathIterator(null); float[] coords = new float[6]; while (!i.isDone()) { int k = i.currentSegment(coords); int s = 0; if (k == PathIterator.SEG_MOVETO || k == PathIterator.SEG_LINETO) { s = 2; } else if (k == PathIterator.SEG_QUADTO) { s = 4; } else if (k == PathIterator.SEG_CUBICTO) { s = 6; } for (int a = 0; a < s; a++) { if (Float.isNaN(coords[a])) return false; if (Float.isInfinite(coords[a])) return false; } i.next(); } return true; }
Example 2
Source File: RenderingEngine.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Utility method to feed a {@link PathConsumer2D} object from a * given {@link PathIterator}. * This method deals with the details of running the iterator and * feeding the consumer a segment at a time. */ public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) { float coords[] = new float[6]; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: consumer.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: consumer.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: consumer.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: consumer.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: consumer.closePath(); break; } pi.next(); } }
Example 3
Source File: Order2.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public int getSegment(double coords[]) { coords[0] = cx0; coords[1] = cy0; if (direction == INCREASING) { coords[2] = x1; coords[3] = y1; } else { coords[2] = x0; coords[3] = y0; } return PathIterator.SEG_QUADTO; }
Example 4
Source File: RenderingEngine.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Utility method to feed a {@link PathConsumer2D} object from a * given {@link PathIterator}. * This method deals with the details of running the iterator and * feeding the consumer a segment at a time. */ public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) { float coords[] = new float[6]; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: consumer.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: consumer.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: consumer.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: consumer.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: consumer.closePath(); break; } pi.next(); } }
Example 5
Source File: Path2DCopyConstructor.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static int getLength(int type) { switch(type) { case PathIterator.SEG_CUBICTO: return 6; case PathIterator.SEG_QUADTO: return 4; case PathIterator.SEG_LINETO: case PathIterator.SEG_MOVETO: return 2; case PathIterator.SEG_CLOSE: return 0; default: throw new IllegalStateException("Invalid type: " + type); } }
Example 6
Source File: FXGraphics2D.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Maps a shape to a path in the graphics context. * * @param s the shape ({@code null} not permitted). */ private void shapeToPath(Shape s) { double[] coords = new double[6]; this.gc.beginPath(); PathIterator iterator = s.getPathIterator(null); while (!iterator.isDone()) { int segType = iterator.currentSegment(coords); switch (segType) { case PathIterator.SEG_MOVETO: this.gc.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: this.gc.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: this.gc.quadraticCurveTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: this.gc.bezierCurveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: this.gc.closePath(); break; default: throw new RuntimeException("Unrecognised segment type " + segType); } iterator.next(); } }
Example 7
Source File: Path2DCopyConstructor.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static int getLength(int type) { switch(type) { case PathIterator.SEG_CUBICTO: return 6; case PathIterator.SEG_QUADTO: return 4; case PathIterator.SEG_LINETO: case PathIterator.SEG_MOVETO: return 2; case PathIterator.SEG_CLOSE: return 0; default: throw new IllegalStateException("Invalid type: " + type); } }
Example 8
Source File: SinglePath.java From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 | 5 votes |
/** 將線段前後點順序顛倒。 */ private void reverse() { Point2DWithVector tmp = currentPoint; switch (type) { case PathIterator.SEG_MOVETO: break; case PathIterator.SEG_LINETO: currentPoint = new Point2DWithVector(controlPoint[0], controlPoint[1]); controlPoint[0] = tmp.getX(); controlPoint[1] = tmp.getY(); break; case PathIterator.SEG_QUADTO: currentPoint = new Point2DWithVector(controlPoint[2], controlPoint[3]); controlPoint[2] = tmp.getX(); controlPoint[3] = tmp.getY(); break; case PathIterator.SEG_CUBICTO: currentPoint = new Point2DWithVector(controlPoint[4], controlPoint[5]); controlPoint[4] = tmp.getX(); controlPoint[5] = tmp.getY(); double t; t = controlPoint[0]; controlPoint[0] = controlPoint[2]; controlPoint[2] = t; t = controlPoint[1]; controlPoint[1] = controlPoint[3]; controlPoint[3] = t; break; case PathIterator.SEG_CLOSE: break; } return; }
Example 9
Source File: Order2.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public int getSegment(double coords[]) { coords[0] = cx0; coords[1] = cy0; if (direction == INCREASING) { coords[2] = x1; coords[3] = y1; } else { coords[2] = x0; coords[3] = y0; } return PathIterator.SEG_QUADTO; }
Example 10
Source File: PiscesRenderingEngine.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public int currentSegment(float[] coords) { int type = src.currentSegment(coords); int lastCoord; switch(type) { case PathIterator.SEG_CUBICTO: lastCoord = 4; break; case PathIterator.SEG_QUADTO: lastCoord = 2; break; case PathIterator.SEG_LINETO: case PathIterator.SEG_MOVETO: lastCoord = 0; break; case PathIterator.SEG_CLOSE: // we don't want to deal with this case later. We just exit now curx_adjust = movx_adjust; cury_adjust = movy_adjust; return type; default: throw new InternalError("Unrecognized curve type"); } // normalize endpoint float x_adjust = (float)Math.floor(coords[lastCoord] + lval) + rval - coords[lastCoord]; float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) + rval - coords[lastCoord + 1]; coords[lastCoord ] += x_adjust; coords[lastCoord + 1] += y_adjust; // now that the end points are done, normalize the control points switch(type) { case PathIterator.SEG_CUBICTO: coords[0] += curx_adjust; coords[1] += cury_adjust; coords[2] += x_adjust; coords[3] += y_adjust; break; case PathIterator.SEG_QUADTO: coords[0] += (curx_adjust + x_adjust) / 2; coords[1] += (cury_adjust + y_adjust) / 2; break; case PathIterator.SEG_LINETO: break; case PathIterator.SEG_MOVETO: movx_adjust = x_adjust; movy_adjust = y_adjust; break; case PathIterator.SEG_CLOSE: throw new InternalError("This should be handled earlier."); } curx_adjust = x_adjust; cury_adjust = y_adjust; return type; }
Example 11
Source File: Curve.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Calculates the number of times the given path * crosses the ray extending to the right from (px,py). * If the point lies on a part of the path, * then no crossings are counted for that intersection. * +1 is added for each crossing where the Y coordinate is increasing * -1 is added for each crossing where the Y coordinate is decreasing * The return value is the sum of all crossings for every segment in * the path. * The path must start with a SEG_MOVETO, otherwise an exception is * thrown. * The caller must check p[xy] for NaN values. * The caller may also reject infinite p[xy] values as well. */ public static int pointCrossingsForPath(PathIterator pi, double px, double py) { if (pi.isDone()) { return 0; } double coords[] = new double[6]; if (pi.currentSegment(coords) != PathIterator.SEG_MOVETO) { throw new IllegalPathStateException("missing initial moveto "+ "in path definition"); } pi.next(); double movx = coords[0]; double movy = coords[1]; double curx = movx; double cury = movy; double endx, endy; int crossings = 0; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: if (cury != movy) { crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); } movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: endx = coords[0]; endy = coords[1]; crossings += pointCrossingsForLine(px, py, curx, cury, endx, endy); curx = endx; cury = endy; break; case PathIterator.SEG_QUADTO: endx = coords[2]; endy = coords[3]; crossings += pointCrossingsForQuad(px, py, curx, cury, coords[0], coords[1], endx, endy, 0); curx = endx; cury = endy; break; case PathIterator.SEG_CUBICTO: endx = coords[4]; endy = coords[5]; crossings += pointCrossingsForCubic(px, py, curx, cury, coords[0], coords[1], coords[2], coords[3], endx, endy, 0); curx = endx; cury = endy; break; case PathIterator.SEG_CLOSE: if (cury != movy) { crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); } curx = movx; cury = movy; break; } pi.next(); } if (cury != movy) { crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); } return crossings; }
Example 12
Source File: PSPrinterJob.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Given a Java2D {@code PathIterator} instance, * this method translates that into a PostScript path.. */ void convertToPSPath(PathIterator pathIter) { float[] segment = new float[6]; int segmentType; /* Map the PathIterator's fill rule into the PostScript * fill rule. */ int fillRule; if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) { fillRule = FILL_EVEN_ODD; } else { fillRule = FILL_WINDING; } beginPath(); setFillMode(fillRule); while (pathIter.isDone() == false) { segmentType = pathIter.currentSegment(segment); switch (segmentType) { case PathIterator.SEG_MOVETO: moveTo(segment[0], segment[1]); break; case PathIterator.SEG_LINETO: lineTo(segment[0], segment[1]); break; /* Convert the quad path to a bezier. */ case PathIterator.SEG_QUADTO: float lastX = getPenX(); float lastY = getPenY(); float c1x = lastX + (segment[0] - lastX) * 2 / 3; float c1y = lastY + (segment[1] - lastY) * 2 / 3; float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3; float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3; bezierTo(c1x, c1y, c2x, c2y, segment[2], segment[3]); break; case PathIterator.SEG_CUBICTO: bezierTo(segment[0], segment[1], segment[2], segment[3], segment[4], segment[5]); break; case PathIterator.SEG_CLOSE: closeSubpath(); break; } pathIter.next(); } }
Example 13
Source File: Crossings.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static Crossings findCrossings(PathIterator pi, double xlo, double ylo, double xhi, double yhi) { Crossings cross; if (pi.getWindingRule() == pi.WIND_EVEN_ODD) { cross = new EvenOdd(xlo, ylo, xhi, yhi); } else { cross = new NonZero(xlo, ylo, xhi, yhi); } // coords array is big enough for holding: // coordinates returned from currentSegment (6) // OR // two subdivided quadratic curves (2+4+4=10) // AND // 0-1 horizontal splitting parameters // OR // 2 parametric equation derivative coefficients // OR // three subdivided cubic curves (2+6+6+6=20) // AND // 0-2 horizontal splitting parameters // OR // 3 parametric equation derivative coefficients double coords[] = new double[23]; double movx = 0; double movy = 0; double curx = 0; double cury = 0; double newx, newy; while (!pi.isDone()) { int type = pi.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: if (movy != cury && cross.accumulateLine(curx, cury, movx, movy)) { return null; } movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: newx = coords[0]; newy = coords[1]; if (cross.accumulateLine(curx, cury, newx, newy)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_QUADTO: newx = coords[2]; newy = coords[3]; if (cross.accumulateQuad(curx, cury, coords)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_CUBICTO: newx = coords[4]; newy = coords[5]; if (cross.accumulateCubic(curx, cury, coords)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_CLOSE: if (movy != cury && cross.accumulateLine(curx, cury, movx, movy)) { return null; } curx = movx; cury = movy; break; } pi.next(); } if (movy != cury) { if (cross.accumulateLine(curx, cury, movx, movy)) { return null; } } if (debug) { cross.print(); } return cross; }
Example 14
Source File: ShapeDebugFrame.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Shape paint(Graphics2D g, ScreenTransform transform) { if (shape == null || (shape instanceof Area && ((Area)shape).isEmpty())) { return null; } Path2D path = new Path2D.Double(); PathIterator pi = shape.getPathIterator(null); // CHECKSTYLE:OFF:MagicNumber double[] d = new double[6]; while (!pi.isDone()) { int type = pi.currentSegment(d); switch (type) { case PathIterator.SEG_MOVETO: path.moveTo(transform.xToScreen(d[0]), transform.yToScreen(d[1])); break; case PathIterator.SEG_LINETO: path.lineTo(transform.xToScreen(d[0]), transform.yToScreen(d[1])); break; case PathIterator.SEG_CLOSE: path.closePath(); break; case PathIterator.SEG_QUADTO: path.quadTo(transform.xToScreen(d[0]), transform.yToScreen(d[1]), transform.xToScreen(d[2]), transform.yToScreen(d[3])); break; case PathIterator.SEG_CUBICTO: path.curveTo(transform.xToScreen(d[0]), transform.yToScreen(d[1]), transform.xToScreen(d[2]), transform.yToScreen(d[3]), transform.xToScreen(d[4]), transform.yToScreen(d[5])); break; default: throw new RuntimeException("Unexpected PathIterator constant: " + type); } pi.next(); } // CHECKSTYLE:ON:MagicNumber g.setColor(colour); if (fill) { g.fill(path); } else { g.draw(path); } return path.createTransformedShape(null); }
Example 15
Source File: CurveX.java From pumpernickel with MIT License | 4 votes |
/** * Accumulate the number of times the path crosses the shadow extending to * the right of the rectangle. See the comment for the RECT_INTERSECTS * constant for more complete details. The return value is the sum of all * crossings for both the top and bottom of the shadow for every segment in * the path, or the special value RECT_INTERSECTS if the path ever enters * the interior of the rectangle. The path must start with a SEG_MOVETO, * otherwise an exception is thrown. The caller must check r[xy]{min,max} * for NaN values. */ public static int rectCrossingsForPath(PathIterator pi, double rxmin, double rymin, double rxmax, double rymax) { if (rxmax <= rxmin || rymax <= rymin) { return 0; } if (pi.isDone()) { return 0; } double coords[] = new double[6]; if (pi.currentSegment(coords) != PathIterator.SEG_MOVETO) { throw new IllegalPathStateException("missing initial moveto " + "in path definition"); } pi.next(); double curx, cury, movx, movy, endx, endy; curx = movx = coords[0]; cury = movy = coords[1]; int crossings = 0; while (crossings != RECT_INTERSECTS && !pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: if (curx != movx || cury != movy) { crossings = rectCrossingsForLine(crossings, rxmin, rymin, rxmax, rymax, curx, cury, movx, movy); } // Count should always be a multiple of 2 here. // assert((crossings & 1) != 0); movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: endx = coords[0]; endy = coords[1]; crossings = rectCrossingsForLine(crossings, rxmin, rymin, rxmax, rymax, curx, cury, endx, endy); curx = endx; cury = endy; break; case PathIterator.SEG_QUADTO: endx = coords[2]; endy = coords[3]; crossings = rectCrossingsForQuad(crossings, rxmin, rymin, rxmax, rymax, curx, cury, coords[0], coords[1], endx, endy, 0); curx = endx; cury = endy; break; case PathIterator.SEG_CUBICTO: endx = coords[4]; endy = coords[5]; crossings = rectCrossingsForCubic(crossings, rxmin, rymin, rxmax, rymax, curx, cury, coords[0], coords[1], coords[2], coords[3], endx, endy, 0); curx = endx; cury = endy; break; case PathIterator.SEG_CLOSE: if (curx != movx || cury != movy) { crossings = rectCrossingsForLine(crossings, rxmin, rymin, rxmax, rymax, curx, cury, movx, movy); } curx = movx; cury = movy; // Count should always be a multiple of 2 here. // assert((crossings & 1) != 0); break; } pi.next(); } if (crossings != RECT_INTERSECTS && (curx != movx || cury != movy)) { crossings = rectCrossingsForLine(crossings, rxmin, rymin, rxmax, rymax, curx, cury, movx, movy); } // Count should always be a multiple of 2 here. // assert((crossings & 1) != 0); return crossings; }
Example 16
Source File: MarlinRenderingEngine.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public final int currentSegment(final float[] coords) { int lastCoord; final int type = src.currentSegment(coords); switch(type) { case PathIterator.SEG_MOVETO: case PathIterator.SEG_LINETO: lastCoord = 0; break; case PathIterator.SEG_QUADTO: lastCoord = 2; break; case PathIterator.SEG_CUBICTO: lastCoord = 4; break; case PathIterator.SEG_CLOSE: // we don't want to deal with this case later. We just exit now curx_adjust = movx_adjust; cury_adjust = movy_adjust; return type; default: throw new InternalError("Unrecognized curve type"); } // normalize endpoint float coord, x_adjust, y_adjust; coord = coords[lastCoord]; x_adjust = normCoord(coord); // new coord coords[lastCoord] = x_adjust; x_adjust -= coord; coord = coords[lastCoord + 1]; y_adjust = normCoord(coord); // new coord coords[lastCoord + 1] = y_adjust; y_adjust -= coord; // now that the end points are done, normalize the control points switch(type) { case PathIterator.SEG_MOVETO: movx_adjust = x_adjust; movy_adjust = y_adjust; break; case PathIterator.SEG_LINETO: break; case PathIterator.SEG_QUADTO: coords[0] += (curx_adjust + x_adjust) / 2f; coords[1] += (cury_adjust + y_adjust) / 2f; break; case PathIterator.SEG_CUBICTO: coords[0] += curx_adjust; coords[1] += cury_adjust; coords[2] += x_adjust; coords[3] += y_adjust; break; case PathIterator.SEG_CLOSE: // handled earlier default: } curx_adjust = x_adjust; cury_adjust = y_adjust; return type; }
Example 17
Source File: DuctusRenderingEngine.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private void feedConsumer(PathConsumer consumer, PathIterator pi) { try { consumer.beginPath(); boolean pathClosed = false; float mx = 0.0f; float my = 0.0f; float point[] = new float[6]; while (!pi.isDone()) { int type = pi.currentSegment(point); if (pathClosed == true) { pathClosed = false; if (type != PathIterator.SEG_MOVETO) { // Force current point back to last moveto point consumer.beginSubpath(mx, my); } } switch (type) { case PathIterator.SEG_MOVETO: mx = point[0]; my = point[1]; consumer.beginSubpath(point[0], point[1]); break; case PathIterator.SEG_LINETO: consumer.appendLine(point[0], point[1]); break; case PathIterator.SEG_QUADTO: consumer.appendQuadratic(point[0], point[1], point[2], point[3]); break; case PathIterator.SEG_CUBICTO: consumer.appendCubic(point[0], point[1], point[2], point[3], point[4], point[5]); break; case PathIterator.SEG_CLOSE: consumer.closedSubpath(); pathClosed = true; break; } pi.next(); } consumer.endPath(); } catch (PathException e) { throw new InternalError("Unable to Stroke shape ("+ e.getMessage()+")", e); } }
Example 18
Source File: Crossings.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static Crossings findCrossings(PathIterator pi, double xlo, double ylo, double xhi, double yhi) { Crossings cross; if (pi.getWindingRule() == pi.WIND_EVEN_ODD) { cross = new EvenOdd(xlo, ylo, xhi, yhi); } else { cross = new NonZero(xlo, ylo, xhi, yhi); } // coords array is big enough for holding: // coordinates returned from currentSegment (6) // OR // two subdivided quadratic curves (2+4+4=10) // AND // 0-1 horizontal splitting parameters // OR // 2 parametric equation derivative coefficients // OR // three subdivided cubic curves (2+6+6+6=20) // AND // 0-2 horizontal splitting parameters // OR // 3 parametric equation derivative coefficients double coords[] = new double[23]; double movx = 0; double movy = 0; double curx = 0; double cury = 0; double newx, newy; while (!pi.isDone()) { int type = pi.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: if (movy != cury && cross.accumulateLine(curx, cury, movx, movy)) { return null; } movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: newx = coords[0]; newy = coords[1]; if (cross.accumulateLine(curx, cury, newx, newy)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_QUADTO: newx = coords[2]; newy = coords[3]; if (cross.accumulateQuad(curx, cury, coords)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_CUBICTO: newx = coords[4]; newy = coords[5]; if (cross.accumulateCubic(curx, cury, coords)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_CLOSE: if (movy != cury && cross.accumulateLine(curx, cury, movx, movy)) { return null; } curx = movx; cury = movy; break; } pi.next(); } if (movy != cury) { if (cross.accumulateLine(curx, cury, movx, movy)) { return null; } } if (debug) { cross.print(); } return cross; }
Example 19
Source File: Curve.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Calculates the number of times the given path * crosses the ray extending to the right from (px,py). * If the point lies on a part of the path, * then no crossings are counted for that intersection. * +1 is added for each crossing where the Y coordinate is increasing * -1 is added for each crossing where the Y coordinate is decreasing * The return value is the sum of all crossings for every segment in * the path. * The path must start with a SEG_MOVETO, otherwise an exception is * thrown. * The caller must check p[xy] for NaN values. * The caller may also reject infinite p[xy] values as well. */ public static int pointCrossingsForPath(PathIterator pi, double px, double py) { if (pi.isDone()) { return 0; } double coords[] = new double[6]; if (pi.currentSegment(coords) != PathIterator.SEG_MOVETO) { throw new IllegalPathStateException("missing initial moveto "+ "in path definition"); } pi.next(); double movx = coords[0]; double movy = coords[1]; double curx = movx; double cury = movy; double endx, endy; int crossings = 0; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: if (cury != movy) { crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); } movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: endx = coords[0]; endy = coords[1]; crossings += pointCrossingsForLine(px, py, curx, cury, endx, endy); curx = endx; cury = endy; break; case PathIterator.SEG_QUADTO: endx = coords[2]; endy = coords[3]; crossings += pointCrossingsForQuad(px, py, curx, cury, coords[0], coords[1], endx, endy, 0); curx = endx; cury = endy; break; case PathIterator.SEG_CUBICTO: endx = coords[4]; endy = coords[5]; crossings += pointCrossingsForCubic(px, py, curx, cury, coords[0], coords[1], coords[2], coords[3], endx, endy, 0); curx = endx; cury = endy; break; case PathIterator.SEG_CLOSE: if (cury != movy) { crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); } curx = movx; cury = movy; break; } pi.next(); } if (cury != movy) { crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); } return crossings; }
Example 20
Source File: PiscesRenderingEngine.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public int currentSegment(float[] coords) { int type = src.currentSegment(coords); int lastCoord; switch(type) { case PathIterator.SEG_CUBICTO: lastCoord = 4; break; case PathIterator.SEG_QUADTO: lastCoord = 2; break; case PathIterator.SEG_LINETO: case PathIterator.SEG_MOVETO: lastCoord = 0; break; case PathIterator.SEG_CLOSE: // we don't want to deal with this case later. We just exit now curx_adjust = movx_adjust; cury_adjust = movy_adjust; return type; default: throw new InternalError("Unrecognized curve type"); } // normalize endpoint float x_adjust = (float)Math.floor(coords[lastCoord] + lval) + rval - coords[lastCoord]; float y_adjust = (float)Math.floor(coords[lastCoord+1] + lval) + rval - coords[lastCoord + 1]; coords[lastCoord ] += x_adjust; coords[lastCoord + 1] += y_adjust; // now that the end points are done, normalize the control points switch(type) { case PathIterator.SEG_CUBICTO: coords[0] += curx_adjust; coords[1] += cury_adjust; coords[2] += x_adjust; coords[3] += y_adjust; break; case PathIterator.SEG_QUADTO: coords[0] += (curx_adjust + x_adjust) / 2; coords[1] += (cury_adjust + y_adjust) / 2; break; case PathIterator.SEG_LINETO: break; case PathIterator.SEG_MOVETO: movx_adjust = x_adjust; movy_adjust = y_adjust; break; case PathIterator.SEG_CLOSE: throw new InternalError("This should be handled earlier."); } curx_adjust = x_adjust; cury_adjust = y_adjust; return type; }