Example usage for java.awt.geom PathIterator isDone

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

Introduction

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

Prototype

public boolean isDone();

Source Link

Document

Tests if the iteration is complete.

Usage

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

protected Element createShape(Shape shape) {
    PathIterator pathIter = shape.getPathIterator(null);
    StringBuffer pathStr = new StringBuffer();
    while (!pathIter.isDone()) {
        float[] points = new float[6];
        int TYPE = pathIter.currentSegment(points);
        switch (TYPE) {
        case PathIterator.SEG_CLOSE:
            pathStr.append(" Z"); //$NON-NLS-1$
            break;
        case PathIterator.SEG_LINETO:
            pathStr.append(" L").append(toString(points, 2, ' ')); //$NON-NLS-1$ 
            break;
        case PathIterator.SEG_QUADTO:
            pathStr.append(" Q").append(toString(points, 4, ' ')); //$NON-NLS-1$ 
            break;
        case PathIterator.SEG_CUBICTO:
            pathStr.append(" C").append(toString(points, 6, ' ')); //$NON-NLS-1$ 
            break;
        case PathIterator.SEG_MOVETO:
            pathStr.append(" M").append(toString(points, 2, ' ')); //$NON-NLS-1$ 
            break;
        }//from   w ww.  j  a va 2s . c  o  m
        pathIter.next();
    }
    Element elem = dom.createElement("path"); //$NON-NLS-1$
    elem.setAttribute("d", pathStr.toString()); //$NON-NLS-1$
    return elem;
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

public static GeneralPath areaToPath(final Area negativeArea, final double deltaX,
        final GeneralPath pixelPath) {

    final float[] floats = new float[6];
    // move to correct rectangle
    final AffineTransform transform = AffineTransform.getTranslateInstance(deltaX, 0.0);
    final PathIterator iterator = negativeArea.getPathIterator(transform);

    while (!iterator.isDone()) {
        final int segmentType = iterator.currentSegment(floats);
        if (segmentType == PathIterator.SEG_LINETO) {
            pixelPath.lineTo(floats[0], floats[1]);
        } else if (segmentType == PathIterator.SEG_MOVETO) {
            pixelPath.moveTo(floats[0], floats[1]);
        } else if (segmentType == PathIterator.SEG_CLOSE) {
            pixelPath.closePath();// w  w w.  ja v a  2 s .co  m
        }
        iterator.next();
    }
    return pixelPath;
}

From source file:org.geotools.gce.imagemosaic.Utils.java

/**
 * Checks if the Shape equates to a Rectangle, if it does it performs a conversion, otherwise
 * returns null/*  ww w.j ava2  s. com*/
 * @param shape
 * @return
 */
static Rectangle toRectangle(Shape shape) {
    if (shape instanceof Rectangle) {
        return (Rectangle) shape;
    }

    if (shape == null) {
        return null;
    }

    // check if it's equivalent to a rectangle
    PathIterator iter = shape.getPathIterator(new AffineTransform());
    double[] coords = new double[2];

    // not enough points?
    if (iter.isDone()) {
        return null;
    }

    // get the first and init the data structures
    iter.next();
    int action = iter.currentSegment(coords);
    if (action != PathIterator.SEG_MOVETO && action != PathIterator.SEG_LINETO) {
        return null;
    }
    double minx = coords[0];
    double miny = coords[1];
    double maxx = minx;
    double maxy = miny;
    double prevx = minx;
    double prevy = miny;
    int i = 0;

    // at most 4 steps, if more it's not a strict rectangle
    for (; i < 4 && !iter.isDone(); i++) {
        iter.next();
        action = iter.currentSegment(coords);

        if (action == PathIterator.SEG_CLOSE) {
            break;
        }
        if (action != PathIterator.SEG_LINETO) {
            return null;
        }

        // check orthogonal step (x does not change and y does, or vice versa)
        double x = coords[0];
        double y = coords[1];
        if (!(prevx == x && prevy != y) && !(prevx != x && prevy == y)) {
            return null;
        }

        // update mins and maxes
        if (x < minx) {
            minx = x;
        } else if (x > maxx) {
            maxx = x;
        }
        if (y < miny) {
            miny = y;
        } else if (y > maxy) {
            maxy = y;
        }

        // keep track of prev step
        prevx = x;
        prevy = y;
    }

    // if more than 4 other points it's not a standard rectangle
    iter.next();
    if (!iter.isDone() || i != 3) {
        return null;
    }

    // turn it into a rectangle
    return new Rectangle2D.Double(minx, miny, maxx - minx, maxy - miny).getBounds();
}

From source file:org.opensha.commons.geo.RegionTest.java

private static void readArea(Area area) {
    PathIterator pi = area.getPathIterator(null);
    double[] vertex = new double[6];
    while (!pi.isDone()) {
        pi.currentSegment(vertex);//from  w w  w.j  av  a2s.co  m
        System.out.println("AreaCoord: " + vertex[1] + " " + vertex[0]);
        pi.next();
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void followPath(Shape s, final int drawType) {
    if (s == null) {
        return;/*w ww.ja v a 2  s . com*/
    }
    if (drawType == PdfGraphics2D.STROKE) {
        if (!(stroke instanceof BasicStroke)) {
            s = stroke.createStrokedShape(s);
            followPath(s, PdfGraphics2D.FILL);
            return;
        }
    }
    if (drawType == PdfGraphics2D.STROKE) {
        setStrokeDiff(stroke, oldStroke);
        oldStroke = stroke;
        setStrokePaint();
    } else if (drawType == PdfGraphics2D.FILL) {
        setFillPaint();
    }
    final PathIterator points;
    if (drawType == PdfGraphics2D.CLIP) {
        points = s.getPathIterator(PdfGraphics2D.IDENTITY);
    } else {
        points = s.getPathIterator(transform);
    }
    final float[] coords = new float[6];
    int traces = 0;
    while (!points.isDone()) {
        ++traces;
        final int segtype = points.currentSegment(coords);
        normalizeY(coords);
        switch (segtype) {
        case PathIterator.SEG_CLOSE:
            cb.closePath();
            break;

        case PathIterator.SEG_CUBICTO:
            cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;

        case PathIterator.SEG_LINETO:
            cb.lineTo(coords[0], coords[1]);
            break;

        case PathIterator.SEG_MOVETO:
            cb.moveTo(coords[0], coords[1]);
            break;

        case PathIterator.SEG_QUADTO:
            cb.curveTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        default:
            throw new IllegalStateException("Invalid segment type in path");
        }
        points.next();
    }
    switch (drawType) {
    case PdfGraphics2D.FILL:
        if (traces > 0) {
            if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
                cb.eoFill();
            } else {
                cb.fill();
            }
        }
        break;
    case PdfGraphics2D.STROKE:
        if (traces > 0) {
            cb.stroke();
        }
        break;
    default: // drawType==CLIP
        if (traces == 0) {
            cb.rectangle(0, 0, 0, 0);
        }
        if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
            cb.eoClip();
        } else {
            cb.clip();
        }
        cb.newPath();
    }
}