Java Code Examples for java.awt.geom.PathIterator#SEG_CLOSE

The following examples show how to use java.awt.geom.PathIterator#SEG_CLOSE . 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: PathIteratorSegmentObjectDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parses the given string representation and returns the path iterator type or -1 if the string does not represent a
 * path iterator value.
 *
 * @param segment
 *          the string that contains the PathIterator type.
 * @return the parsed PathIterator type or -1.
 */
private int parseSegmentType( final String segment ) {
  if ( segment == null ) {
    return -1;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_CLOSE ) ) {
    return PathIterator.SEG_CLOSE;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_CUBIC_TO ) ) {
    return PathIterator.SEG_CUBICTO;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_LINE_TO ) ) {
    return PathIterator.SEG_LINETO;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_MOVE_TO ) ) {
    return PathIterator.SEG_MOVETO;
  }
  if ( segment.equals( PathIteratorSegmentObjectDescription.SEG_QUAD_TO ) ) {
    return PathIterator.SEG_QUADTO;
  }
  return -1;
}
 
Example 2
Source File: RenderingEngine.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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: DefaultProcessDiagramCanvas.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * This method calculates shape intersection with line.
 * 
 * @param shape
 * @param line
 * @return Intersection point
 */
private static Point getShapeIntersection(Shape shape, Line2D.Double line) {
    PathIterator it = shape.getPathIterator(null);
    double[] coords = new double[6];
    double[] pos = new double[2];
    Line2D.Double l = new Line2D.Double();
    while (!it.isDone()) {
        int type = it.currentSegment(coords);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            pos[0] = coords[0];
            pos[1] = coords[1];
            break;
        case PathIterator.SEG_LINETO:
            l = new Line2D.Double(pos[0], pos[1], coords[0], coords[1]);
            if (line.intersectsLine(l)) {
                return getLinesIntersection(line, l);
            }
            pos[0] = coords[0];
            pos[1] = coords[1];
            break;
        case PathIterator.SEG_CLOSE:
            break;
        default:
            // whatever
        }
        it.next();
    }
    return null;
}
 
Example 4
Source File: RenderingEngine.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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: FXGraphics2D.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: RenderingEngine.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 7
Source File: lineutility.java    From mil-sym-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GeneralPath from a Path2D
 *
 * @param shape
 * @return
 */
protected static Shape createStrokedShape(Shape shape) {
    GeneralPath newshape = new GeneralPath(); // Start with an empty shape
    try {
        // Iterate through the specified shape, perturb its coordinates, and
        // use them to build up the new shape.
        float[] coords = new float[6];
        for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) {
            int type = i.currentSegment(coords);
            switch (type) {
                case PathIterator.SEG_MOVETO:
                    //perturb(coords, 2);
                    newshape.moveTo(coords[0], coords[1]);
                    break;
                case PathIterator.SEG_LINETO:
                    //perturb(coords, 2);
                    newshape.lineTo(coords[0], coords[1]);
                    break;
                case PathIterator.SEG_QUADTO:
                    //perturb(coords, 4);
                    newshape.quadTo(coords[0], coords[1], coords[2], coords[3]);
                    break;
                case PathIterator.SEG_CUBICTO:
                    //perturb(coords, 6);
                    newshape.curveTo(coords[0], coords[1], coords[2], coords[3],
                            coords[4], coords[5]);
                    break;
                case PathIterator.SEG_CLOSE:
                    newshape.closePath();
                    break;
            }

        }
    } catch (Exception exc) {
        ErrorLogger.LogException(_className, "createStrokedShape",
                new RendererException("Failed inside createStrokedShape", exc));
    }
    return newshape;
}
 
Example 8
Source File: FXGraphics2D.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: SinglePath.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
/** 建立線段物件 */
public SinglePath()
{
	type = PathIterator.SEG_CLOSE;
	currentPoint = new Point2DWithVector();
	controlPoint = new double[6];
}
 
Example 10
Source File: DefaultCaseDiagramCanvas.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * This method calculates shape intersection with line.
 *
 * @param shape
 * @param line
 * @return Intersection point
 */
private static Point getShapeIntersection(Shape shape, Line2D.Double line) {
    PathIterator it = shape.getPathIterator(null);
    double[] coords = new double[6];
    double[] pos = new double[2];
    Line2D.Double l = new Line2D.Double();
    while (!it.isDone()) {
        int type = it.currentSegment(coords);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            pos[0] = coords[0];
            pos[1] = coords[1];
            break;
        case PathIterator.SEG_LINETO:
            l = new Line2D.Double(pos[0], pos[1], coords[0], coords[1]);
            if (line.intersectsLine(l)) {
                return getLinesIntersection(line, l);
            }
            pos[0] = coords[0];
            pos[1] = coords[1];
            break;
        case PathIterator.SEG_CLOSE:
            break;
        default:
            // whatever
        }
        it.next();
    }
    return null;
}
 
Example 11
Source File: SVGGraphics2D.java    From jfreesvg with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates an SVG path string for the supplied Java2D path.
 * 
 * @param path  the path ({@code null} not permitted).
 * 
 * @return An SVG path string. 
 */
private String getSVGPathData(Path2D path) {
    StringBuilder b = new StringBuilder();
    if (path.getWindingRule() == Path2D.WIND_EVEN_ODD) {
        b.append("fill-rule=\"evenodd\" ");
    }
    b.append("d=\"");
    float[] coords = new float[6];
    boolean first = true;
    PathIterator iterator = path.getPathIterator(null);
    while (!iterator.isDone()) {
        int type = iterator.currentSegment(coords);
        if (!first) {
            b.append(" ");
        }
        first = false;
        switch (type) {
        case (PathIterator.SEG_MOVETO):
            b.append("M ").append(geomDP(coords[0])).append(" ")
                    .append(geomDP(coords[1]));
            break;
        case (PathIterator.SEG_LINETO):
            b.append("L ").append(geomDP(coords[0])).append(" ")
                    .append(geomDP(coords[1]));
            break;
        case (PathIterator.SEG_QUADTO):
            b.append("Q ").append(geomDP(coords[0]))
                    .append(" ").append(geomDP(coords[1]))
                    .append(" ").append(geomDP(coords[2]))
                    .append(" ").append(geomDP(coords[3]));
            break;
        case (PathIterator.SEG_CUBICTO):
            b.append("C ").append(geomDP(coords[0])).append(" ")
                    .append(geomDP(coords[1])).append(" ")
                    .append(geomDP(coords[2])).append(" ")
                    .append(geomDP(coords[3])).append(" ")
                    .append(geomDP(coords[4])).append(" ")
                    .append(geomDP(coords[5]));
            break;
        case (PathIterator.SEG_CLOSE):
            b.append("Z ");
            break;
        default:
            break;
        }
        iterator.next();
    }  
    return b.append("\"").toString();
}
 
Example 12
Source File: BlockLetter.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public void paintDepth(Graphics2D g, float x, float y) {
	Graphics2D g2 = prep(g, x, y);

	Set<Sheet> sheets = new TreeSet<Sheet>(new SheetComparator());

	PathIterator iter = outline.getPathIterator(null, .1);
	float[] coords = new float[6];
	float lastX = 0;
	float lastY = 0;
	float moveX = 0;
	float moveY = 0;
	while (!iter.isDone()) {
		int k = iter.currentSegment(coords);
		if (k == PathIterator.SEG_CLOSE) {
			k = PathIterator.SEG_LINETO;
			coords[0] = moveX;
			coords[1] = moveY;
		}
		if (k == PathIterator.SEG_MOVETO) {
			lastX = coords[0];
			lastY = coords[1];
			moveX = lastX;
			moveY = lastY;
		} else if (k == PathIterator.SEG_LINETO) {
			sheets.add(new Sheet(lastX, lastY, coords[0], coords[1]));
			lastX = coords[0];
			lastY = coords[1];
		}
		iter.next();
	}

	GeneralPath body = new GeneralPath();
	for (Sheet sh : sheets) {
		sh.apply(body, this);
		Color[] colors = getGradientColors(sh.theta);

		if (colors.length == 1) {
			g2.setColor(colors[0]);
			g2.fill(body);
		} else {
			final AffineTransform tx = TransformUtils
					.createAffineTransform(0, 0, 1, 0, 0, 1, sh.x1,
							sh.y1, sh.x1 + Math.cos(angle) * depth,
							sh.y1 + Math.sin(angle) * depth, sh.x2,
							sh.y2);
			GradientPaint paint = new GradientPaint(0, 0, colors[0], 1,
					0, colors[1]) {

				@Override
				public PaintContext createContext(ColorModel cm,
						Rectangle deviceBounds, Rectangle2D userBounds,
						AffineTransform xform, RenderingHints hints) {
					AffineTransform t = new AffineTransform();
					t.concatenate(xform);
					t.concatenate(tx);
					return super.createContext(cm, deviceBounds,
							userBounds, t, hints);
				}
			};
			g2.setPaint(paint);

			g2.fill(body);
		}
	}

	g2.dispose();
}
 
Example 13
Source File: Crossings.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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: PSPrinterJob.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
* Given a Java2D <code>PathIterator</code> 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 15
Source File: CurveX.java    From pumpernickel with MIT License 4 votes vote down vote up
/**
 * 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: Crossings.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static Crossings findCrossings(PathIterator pi,
                                      double xlo, double ylo,
                                      double xhi, double yhi)
{
    Crossings cross;
    if (pi.getWindingRule() == PathIterator.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 17
Source File: PiscesRenderingEngine.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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 18
Source File: OutlineWobbleEffect.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
 */
public Shape createStrokedShape (Shape shape) {
	GeneralPath result = new GeneralPath();
	shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape);
	PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
	float points[] = new float[6];
	float moveX = 0, moveY = 0;
	float lastX = 0, lastY = 0;
	float thisX = 0, thisY = 0;
	int type = 0;
	float next = 0;
	while (!it.isDone()) {
		type = it.currentSegment(points);
		switch (type) {
		case PathIterator.SEG_MOVETO:
			moveX = lastX = randomize(points[0]);
			moveY = lastY = randomize(points[1]);
			result.moveTo(moveX, moveY);
			next = 0;
			break;

		case PathIterator.SEG_CLOSE:
			points[0] = moveX;
			points[1] = moveY;
			// Fall into....

		case PathIterator.SEG_LINETO:
			thisX = randomize(points[0]);
			thisY = randomize(points[1]);
			float dx = thisX - lastX;
			float dy = thisY - lastY;
			float distance = (float)Math.sqrt(dx * dx + dy * dy);
			if (distance >= next) {
				float r = 1.0f / distance;
				while (distance >= next) {
					float x = lastX + next * dx * r;
					float y = lastY + next * dy * r;
					result.lineTo(randomize(x), randomize(y));
					next += detail;
				}
			}
			next -= distance;
			lastX = thisX;
			lastY = thisY;
			break;
		}
		it.next();
	}

	return result;
}
 
Example 19
Source File: EpsGraphics2D.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Appends the commands required to draw a shape on the EPS document.
 */
private void draw(Shape s, String action) {
  if(s!=null) {
    if(!_transform.isIdentity()) {
      s = _transform.createTransformedShape(s);
    }
    // Update the bounds.
    if(!action.equals("clip")) {                                  //$NON-NLS-1$
      Rectangle2D shapeBounds = s.getBounds2D();
      Rectangle2D visibleBounds = shapeBounds;
      if(_clip!=null) {
        Rectangle2D clipBounds = _clip.getBounds2D();
        visibleBounds = shapeBounds.createIntersection(clipBounds);
      }
      float lineRadius = _stroke.getLineWidth()/2;
      float minX = (float) visibleBounds.getMinX()-lineRadius;
      float minY = (float) visibleBounds.getMinY()-lineRadius;
      float maxX = (float) visibleBounds.getMaxX()+lineRadius;
      float maxY = (float) visibleBounds.getMaxY()+lineRadius;
      _document.updateBounds(minX, -minY);
      _document.updateBounds(maxX, -maxY);
    }
    append("newpath");                                            //$NON-NLS-1$
    int type = 0;
    float[] coords = new float[6];
    PathIterator it = s.getPathIterator(null);
    float x0 = 0;
    float y0 = 0;
    while(!it.isDone()) {
      type = it.currentSegment(coords);
      float x1 = coords[0];
      float y1 = -coords[1];
      float x2 = coords[2];
      float y2 = -coords[3];
      float x3 = coords[4];
      float y3 = -coords[5];
      if(type==PathIterator.SEG_CLOSE) {
        append("closepath");                                      //$NON-NLS-1$
      } else if(type==PathIterator.SEG_CUBICTO) {
        append(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3+" curveto"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
        x0 = x3;
        y0 = y3;
      } else if(type==PathIterator.SEG_LINETO) {
        append(x1+" "+y1+" lineto");                                    //$NON-NLS-1$ //$NON-NLS-2$
        x0 = x1;
        y0 = y1;
      } else if(type==PathIterator.SEG_MOVETO) {
        append(x1+" "+y1+" moveto");                                    //$NON-NLS-1$ //$NON-NLS-2$
        x0 = x1;
        y0 = y1;
      } else if(type==PathIterator.SEG_QUADTO) {
        // Convert the quad curve into a cubic.
        float _x1 = x0+2/3f*(x1-x0);
        float _y1 = y0+2/3f*(y1-y0);
        float _x2 = x1+1/3f*(x2-x1);
        float _y2 = y1+1/3f*(y2-y1);
        float _x3 = x2;
        float _y3 = y2;
        append(_x1+" "+_y1+" "+_x2+" "+_y2+" "+_x3+" "+_y3+" curveto"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
        x0 = _x3;
        y0 = _y3;
      } else if(type==PathIterator.WIND_EVEN_ODD) {
        // Ignore.
      } else if(type==PathIterator.WIND_NON_ZERO) {
        // Ignore.
      }
      it.next();
    }
    append(action);
    append("newpath"); //$NON-NLS-1$
  }
}
 
Example 20
Source File: Curve.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}