Example usage for java.awt.geom PathIterator SEG_LINETO

List of usage examples for java.awt.geom PathIterator SEG_LINETO

Introduction

In this page you can find the example usage for java.awt.geom PathIterator SEG_LINETO.

Prototype

int SEG_LINETO

To view the source code for java.awt.geom PathIterator SEG_LINETO.

Click Source Link

Document

The segment type constant for a point that specifies the end point of a line to be drawn from the most recently specified point.

Usage

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

private AbstractImageMapEntry createMapEntry(final Shape area, final Rectangle2D dataArea) {
    if (buggyDrawArea) {
        if (area instanceof Ellipse2D) {
            final Ellipse2D ellipse2D = (Ellipse2D) area;
            if (ellipse2D.getWidth() == ellipse2D.getHeight()) {
                return new CircleImageMapEntry((float) (ellipse2D.getCenterX() + dataArea.getX()),
                        (float) (ellipse2D.getCenterY() + dataArea.getY()), (float) (ellipse2D.getWidth() / 2));
            }//from  w w  w  .  jav a  2 s .com
        } else if (area instanceof Rectangle2D) {
            final Rectangle2D rect = (Rectangle2D) area;
            return (new RectangleImageMapEntry((float) (rect.getX() + dataArea.getX()),
                    (float) (rect.getY() + dataArea.getY()), (float) (rect.getX() + rect.getWidth()),
                    (float) (rect.getY() + rect.getHeight())));
        }
    } else {
        if (area instanceof Ellipse2D) {
            final Ellipse2D ellipse2D = (Ellipse2D) area;
            if (ellipse2D.getWidth() == ellipse2D.getHeight()) {
                return new CircleImageMapEntry((float) (ellipse2D.getCenterX()),
                        (float) (ellipse2D.getCenterY()), (float) (ellipse2D.getWidth() / 2));
            }
        } else if (area instanceof Rectangle2D) {
            final Rectangle2D rect = (Rectangle2D) area;
            return (new RectangleImageMapEntry((float) (rect.getX()), (float) (rect.getY()),
                    (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight())));
        }
    }

    final Area a = new Area(area);
    if (buggyDrawArea) {
        a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY()));
    }
    if (dataArea.isEmpty() == false) {
        a.intersect(new Area(dataArea));
    }
    final PathIterator pathIterator = a.getPathIterator(null, 2);
    final FloatList floats = new FloatList(100);
    final float[] coords = new float[6];
    while (pathIterator.isDone() == false) {
        final int retval = pathIterator.currentSegment(coords);
        if (retval == PathIterator.SEG_MOVETO || retval == PathIterator.SEG_LINETO) {
            floats.add(coords[0]);
            floats.add(coords[1]);
        }
        pathIterator.next();
    }

    if (floats.size() == 0) {
        return null;
    }
    return (new PolygonImageMapEntry(floats.toArray()));
}

From source file:com.projity.pm.graphic.network.NetworkRenderer.java

protected void updateLinkConnections(GraphicNode node, double[] linkPoints) {
    GeneralPath shape = getShape(node);
    if (shape == null)
        return;/*from  w w  w  .j  a  va  2 s .c  o  m*/
    Point2D center = getCenter(node);
    linkPoints[0] = center.getX();
    linkPoints[1] = center.getX();
    linkPoints[2] = center.getY();
    linkPoints[3] = center.getY();
    double x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, x, y;
    for (PathIterator j = shape.getPathIterator(null); !j.isDone(); j.next()) {
        int segmentType = j.currentSegment(segment);
        switch (segmentType) {
        case PathIterator.SEG_MOVETO:
            x0 = segment[0];
            y0 = segment[1];
            x2 = x0;
            y2 = y0;
            break;
        case PathIterator.SEG_LINETO:
            x2 = segment[0];
            y2 = segment[1];
        case PathIterator.SEG_CLOSE:
            if (segmentType == PathIterator.SEG_CLOSE) {
                x2 = x0;
                y2 = y0;
            }
            //works only convex shapes
            double lambda;
            if (y2 != y1) {
                x = (center.getY() - y1) * (x2 - x1) / (y2 - y1) + x1;
                lambda = (x2 == x1) ? 0 : (x - x1) / (x2 - x1);
                if (x1 == x2 || (lambda >= 0 && lambda <= 1)) {
                    if (x < linkPoints[0])
                        linkPoints[0] = x;
                    if (x > linkPoints[1])
                        linkPoints[1] = x;
                }
            }
            if (x2 != x1) {
                y = (center.getX() - x1) * (y2 - y1) / (x2 - x1) + y1;
                lambda = (y2 == x1) ? 0 : (y - y1) / (y2 - y1);
                if (y1 == y2 || (lambda >= 0 && lambda <= 1)) {
                    if (y < linkPoints[2])
                        linkPoints[2] = y;
                    if (y > linkPoints[3])
                        linkPoints[3] = y;
                }
            }

            break;
        }
        x1 = x2;
        y1 = y2;
    }
}

From source file:ExtendedGeneralPath.java

/**
 * Delegates to the enclosed <code>GeneralPath</code>.
 *///from ww  w.j av  a 2 s .c  o  m
public void append(PathIterator pi, boolean connect) {
    double[] vals = new double[6];

    while (!pi.isDone()) {
        Arrays.fill(vals, 0);
        int type = pi.currentSegment(vals);
        pi.next();
        if (connect && (numVals != 0)) {
            if (type == PathIterator.SEG_MOVETO) {
                double x = vals[0];
                double y = vals[1];
                if ((x != cx) || (y != cy)) {
                    // Change MOVETO to LINETO.
                    type = PathIterator.SEG_LINETO;
                } else {
                    // Redundent segment (move to current loc) drop it...
                    if (pi.isDone())
                        break; // Nothing interesting
                    type = pi.currentSegment(vals);
                    pi.next();
                }
            }
            connect = false;
        }

        switch (type) {
        case PathIterator.SEG_CLOSE:
            closePath();
            break;
        case PathIterator.SEG_MOVETO:
            moveTo((float) vals[0], (float) vals[1]);
            break;
        case PathIterator.SEG_LINETO:
            lineTo((float) vals[0], (float) vals[1]);
            break;
        case PathIterator.SEG_QUADTO:
            quadTo((float) vals[0], (float) vals[1], (float) vals[2], (float) vals[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            curveTo((float) vals[0], (float) vals[1], (float) vals[2], (float) vals[3], (float) vals[4],
                    (float) vals[5]);
            break;
        }
    }
}

From source file:ExtendedGeneralPath.java

/**
 * Delegates to the enclosed <code>GeneralPath</code>.
 *///from   w  ww . j a  va 2 s .co  m
public void append(ExtendedPathIterator epi, boolean connect) {
    float[] vals = new float[7];
    while (!epi.isDone()) {
        Arrays.fill(vals, 0);
        int type = epi.currentSegment(vals);
        epi.next();
        if (connect && (numVals != 0)) {
            if (type == PathIterator.SEG_MOVETO) {
                float x = vals[0];
                float y = vals[1];
                if ((x != cx) || (y != cy)) {
                    // Change MOVETO to LINETO.
                    type = PathIterator.SEG_LINETO;
                } else {
                    // Redundant segment (move to current loc) drop it...
                    if (epi.isDone())
                        break; // Nothing interesting
                    type = epi.currentSegment(vals);
                    epi.next();
                }
            }
            connect = false;
        }

        switch (type) {
        case PathIterator.SEG_CLOSE:
            closePath();
            break;
        case PathIterator.SEG_MOVETO:
            moveTo(vals[0], vals[1]);
            break;
        case PathIterator.SEG_LINETO:
            lineTo(vals[0], vals[1]);
            break;
        case PathIterator.SEG_QUADTO:
            quadTo(vals[0], vals[1], vals[2], vals[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            curveTo(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]);
            break;
        case ExtendedPathIterator.SEG_ARCTO:
            arcTo(vals[0], vals[1], vals[2], (vals[3] != 0), (vals[4] != 0), vals[5], vals[6]);
            break;
        }
    }
}

From source file:com.t_oster.visicut.misc.Helper.java

public static Rectangle2D smallestBoundingBox(Shape s, AffineTransform t) {
    double minX = 0;
    double maxX = 0;
    double minY = 0;
    double maxY = 0;
    PathIterator pi = s.getPathIterator(t, 1);
    double[] last = null;
    boolean first = true;
    while (!pi.isDone()) {
        double[] d = new double[8];
        switch (pi.currentSegment(d)) {
        case PathIterator.SEG_LINETO: {
            if (last != null) {
                if (first) {
                    minX = last[0];/*from   w w  w.  ja  va 2s  .  c  om*/
                    maxX = last[0];
                    minY = last[1];
                    maxY = last[1];
                    first = false;
                } else {
                    if (last[0] < minX) {
                        minX = last[0];
                    }
                    if (last[0] > maxX) {
                        maxX = last[0];
                    }
                    if (last[1] < minY) {
                        minY = last[1];
                    }
                    if (last[1] > maxY) {
                        maxY = last[1];
                    }
                }
            }
            if (first) {
                minX = d[0];
                maxX = d[0];
                minY = d[1];
                maxY = d[1];
                first = false;
            } else {
                if (d[0] < minX) {
                    minX = d[0];
                }
                if (d[0] > maxX) {
                    maxX = d[0];
                }
                if (d[1] < minY) {
                    minY = d[1];
                }
                if (d[1] > maxY) {
                    maxY = d[1];
                }
            }
            break;
        }
        case PathIterator.SEG_MOVETO: {
            last = d;
            break;
        }
        }
        pi.next();
    }
    return new Rectangle.Double(minX, minY, maxX - minX, maxY - minY);
}

From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java

/**
 * Returns a transform to position the arrowhead on this edge shape at the
 * point where it intersects the passed vertex shape.
 *///from   www.j  a va  2  s. co  m
public AffineTransform getArrowTransform(GeneralPath edgeShape, Shape vertexShape) {
    float[] seg = new float[6];
    Point2D p1 = null;
    Point2D p2 = null;
    AffineTransform at = new AffineTransform();
    // when the PathIterator is done, switch to the line-subdivide
    // method to get the arrowhead closer.
    for (PathIterator i = edgeShape.getPathIterator(null, 1); !i.isDone(); i.next()) {
        int ret = i.currentSegment(seg);
        if (ret == PathIterator.SEG_MOVETO) {
            p2 = new Point2D.Float(seg[0], seg[1]);
        } else if (ret == PathIterator.SEG_LINETO) {
            p1 = p2;
            p2 = new Point2D.Float(seg[0], seg[1]);
            if (vertexShape.contains(p2)) {
                at = getArrowTransform(new Line2D.Float(p1, p2), vertexShape);
                break;
            }
        }
    }
    return at;
}

From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java

/**
 * <p>Returns a transform to position the arrowhead on this edge shape at the
 * point where it intersects the passed vertex shape.</p>
 * //from  w  w  w  . j  a  va2s  .  co m
 * <p>The Loop edge is a special case because its staring point is not inside
 * the vertex. The passedGo flag handles this case.</p>
 * 
 * @param edgeShape
 * @param vertexShape
 * @param passedGo - used only for Loop edges
 */
public AffineTransform getReverseArrowTransform(GeneralPath edgeShape, Shape vertexShape, boolean passedGo) {
    float[] seg = new float[6];
    Point2D p1 = null;
    Point2D p2 = null;

    AffineTransform at = new AffineTransform();
    for (PathIterator i = edgeShape.getPathIterator(null, 1); !i.isDone(); i.next()) {
        int ret = i.currentSegment(seg);
        if (ret == PathIterator.SEG_MOVETO) {
            p2 = new Point2D.Float(seg[0], seg[1]);
        } else if (ret == PathIterator.SEG_LINETO) {
            p1 = p2;
            p2 = new Point2D.Float(seg[0], seg[1]);
            if (passedGo == false && vertexShape.contains(p2)) {
                passedGo = true;
            } else if (passedGo == true && vertexShape.contains(p2) == false) {
                at = getReverseArrowTransform(new Line2D.Float(p1, p2), vertexShape);
                break;
            }
        }
    }
    return at;
}

From source file:SWTGraphics2D.java

/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path./*from   w w w.ja  v a 2s. co  m*/
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
        case (PathIterator.SEG_MOVETO):
            path.moveTo(coords[0], coords[1]);
            break;
        case (PathIterator.SEG_LINETO):
            path.lineTo(coords[0], coords[1]);
            break;
        case (PathIterator.SEG_QUADTO):
            path.quadTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        case (PathIterator.SEG_CUBICTO):
            path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;
        case (PathIterator.SEG_CLOSE):
            path.close();
            break;
        default:
            break;
        }
        pit.next();
    }
    return path;
}

From source file:org.apache.fop.afp.AFPGraphics2D.java

/**
 * Processes a path iterator generating the necessary painting operations.
 *
 * @param iter PathIterator to process/*from w  ww .j a v  a  2s  .  c  o m*/
 */
private void processPathIterator(PathIterator iter) {
    double[] dstPts = new double[6];
    double[] currentPosition = new double[2];
    for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) {
        switch (iter.currentSegment(dstPts)) {
        case PathIterator.SEG_LINETO:
            graphicsObj.addLine(new int[] { (int) Math.round(dstPts[X]), (int) Math.round(dstPts[Y]) }, true);
            currentPosition = new double[] { dstPts[X], dstPts[Y] };
            break;
        case PathIterator.SEG_QUADTO:
            graphicsObj.addFillet(new int[] { (int) Math.round(dstPts[X1]), (int) Math.round(dstPts[Y1]),
                    (int) Math.round(dstPts[X2]), (int) Math.round(dstPts[Y2]) }, true);
            currentPosition = new double[] { dstPts[X2], dstPts[Y2] };
            break;
        case PathIterator.SEG_CUBICTO:
            double[] cubicCoords = new double[] { currentPosition[0], currentPosition[1], dstPts[X1],
                    dstPts[Y1], dstPts[X2], dstPts[Y2], dstPts[X3], dstPts[Y3] };
            double[][] quadParts = CubicBezierApproximator.fixedMidPointApproximation(cubicCoords);
            if (quadParts.length >= 4) {
                for (int segIndex = 0; segIndex < quadParts.length; segIndex++) {
                    double[] quadPts = quadParts[segIndex];
                    if (quadPts != null && quadPts.length == 4) {
                        graphicsObj.addFillet(
                                new int[] { (int) Math.round(quadPts[X1]), (int) Math.round(quadPts[Y1]),
                                        (int) Math.round(quadPts[X2]), (int) Math.round(quadPts[Y2]) },
                                true);
                        currentPosition = new double[] { quadPts[X2], quadPts[Y2] };
                    }
                }
            }
            break;
        case PathIterator.SEG_MOVETO:
            openingCoords = new int[] { (int) Math.round(dstPts[X]), (int) Math.round(dstPts[Y]) };
            currentPosition = new double[] { dstPts[X], dstPts[Y] };
            graphicsObj.setCurrentPosition(openingCoords);
            break;
        case PathIterator.SEG_CLOSE:
            graphicsObj.addLine(openingCoords, true);
            currentPosition = new double[] { openingCoords[0], openingCoords[1] };
            break;
        default:
            LOG.debug("Unrecognised path iterator type");
            break;
        }
    }
}

From source file:org.apache.pdfbox.pdfviewer.font.CFFGlyph2D.java

private GeneralPath transformGlyph(GeneralPath glyph) {
    // we have to invert all y-coordinates due to the moved 0,0-reference
    PathIterator iter = glyph.getPathIterator(null);
    float[] currentSegment = new float[6];
    Path2D.Float path = new Path2D.Float(iter.getWindingRule());
    boolean glyphTransformed = false;
    while (!iter.isDone()) {
        glyphTransformed = true;//from w  ww.j av  a2 s.co m
        int type = iter.currentSegment(currentSegment);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            path.moveTo(currentSegment[0], -currentSegment[1]);
            break;
        case PathIterator.SEG_LINETO:
            path.lineTo(currentSegment[0], -currentSegment[1]);
            break;
        case PathIterator.SEG_QUADTO:
            path.quadTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            path.curveTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3],
                    currentSegment[4], -currentSegment[5]);
            break;
        case PathIterator.SEG_CLOSE:
            path.closePath();
            break;
        }
        iter.next();
    }
    if (glyphTransformed) {
        return new GeneralPath(path);
    } else {
        return glyph;
    }
}