Search in sources :

Example 46 with PathIterator

use of java.awt.geom.PathIterator in project android_frameworks_base by ResurrectionRemix.

the class Path_Delegate method isEmpty.

/**
     * Returns whether the path is empty (contains no lines or curves).
     * @see Path#isEmpty
     */
public boolean isEmpty() {
    if (!mCachedIsEmpty) {
        return false;
    }
    float[] coords = new float[6];
    mCachedIsEmpty = Boolean.TRUE;
    for (PathIterator it = mPath.getPathIterator(null); !it.isDone(); it.next()) {
        int type = it.currentSegment(coords);
        if (type != PathIterator.SEG_MOVETO) {
            // Once we know that the path is not empty, we do not need to check again unless
            // Path#reset is called.
            mCachedIsEmpty = false;
            return false;
        }
    }
    return true;
}
Also used : PathIterator(java.awt.geom.PathIterator)

Example 47 with PathIterator

use of java.awt.geom.PathIterator in project jdk8u_jdk by JetBrains.

the class Path2DCopyConstructor method testEqual.

static void testEqual(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(null);
    final PathIterator itB = pathB.getPathIterator(null);
    float[] coordsA = new float[6];
    float[] coordsB = new float[6];
    int n = 0;
    for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
        int typeA = itA.currentSegment(coordsA);
        int typeB = itB.currentSegment(coordsB);
        if (typeA != typeB) {
            throw new IllegalStateException("Path-segment[" + n + "] " + " type are not equals [" + typeA + "|" + typeB + "] !");
        }
        if (!equalsArray(coordsA, coordsB, getLength(typeA))) {
            throw new IllegalStateException("Path-segment[" + n + "] coords" + " are not equals [" + Arrays.toString(coordsA) + "|" + Arrays.toString(coordsB) + "] !");
        }
    }
    if (!itA.isDone() || !itB.isDone()) {
        throw new IllegalStateException("Paths do not have same lengths !");
    }
    log("testEqual: " + n + " segments.");
}
Also used : PathIterator(java.awt.geom.PathIterator)

Example 48 with PathIterator

use of java.awt.geom.PathIterator in project poi by apache.

the class HSLFFreeformShape method setPath.

@Override
public int setPath(Path2D.Double path) {
    Rectangle2D bounds = path.getBounds2D();
    PathIterator it = path.getPathIterator(new AffineTransform());
    List<byte[]> segInfo = new ArrayList<byte[]>();
    List<Point2D.Double> pntInfo = new ArrayList<Point2D.Double>();
    boolean isClosed = false;
    int numPoints = 0;
    while (!it.isDone()) {
        double[] vals = new double[6];
        int type = it.currentSegment(vals);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                segInfo.add(SEGMENTINFO_MOVETO);
                numPoints++;
                break;
            case PathIterator.SEG_LINETO:
                pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                segInfo.add(SEGMENTINFO_LINETO);
                segInfo.add(SEGMENTINFO_ESCAPE);
                numPoints++;
                break;
            case PathIterator.SEG_CUBICTO:
                pntInfo.add(new Point2D.Double(vals[0], vals[1]));
                pntInfo.add(new Point2D.Double(vals[2], vals[3]));
                pntInfo.add(new Point2D.Double(vals[4], vals[5]));
                segInfo.add(SEGMENTINFO_CUBICTO);
                segInfo.add(SEGMENTINFO_ESCAPE2);
                numPoints++;
                break;
            case PathIterator.SEG_QUADTO:
                //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO
                LOG.log(POILogger.WARN, "SEG_QUADTO is not supported");
                break;
            case PathIterator.SEG_CLOSE:
                pntInfo.add(pntInfo.get(0));
                segInfo.add(SEGMENTINFO_LINETO);
                segInfo.add(SEGMENTINFO_ESCAPE);
                segInfo.add(SEGMENTINFO_LINETO);
                segInfo.add(SEGMENTINFO_CLOSE);
                isClosed = true;
                numPoints++;
                break;
            default:
                LOG.log(POILogger.WARN, "Ignoring invalid segment type " + type);
                break;
        }
        it.next();
    }
    if (!isClosed) {
        segInfo.add(SEGMENTINFO_LINETO);
    }
    segInfo.add(SEGMENTINFO_END);
    AbstractEscherOptRecord opt = getEscherOptRecord();
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
    EscherArrayProperty verticesProp = new EscherArrayProperty((short) (EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
    verticesProp.setNumberOfElementsInArray(pntInfo.size());
    verticesProp.setNumberOfElementsInMemory(pntInfo.size());
    verticesProp.setSizeOfElements(8);
    for (int i = 0; i < pntInfo.size(); i++) {
        Point2D.Double pnt = pntInfo.get(i);
        byte[] data = new byte[8];
        LittleEndian.putInt(data, 0, Units.pointsToMaster(pnt.getX() - bounds.getX()));
        LittleEndian.putInt(data, 4, Units.pointsToMaster(pnt.getY() - bounds.getY()));
        verticesProp.setElement(i, data);
    }
    opt.addEscherProperty(verticesProp);
    EscherArrayProperty segmentsProp = new EscherArrayProperty((short) (EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null);
    segmentsProp.setNumberOfElementsInArray(segInfo.size());
    segmentsProp.setNumberOfElementsInMemory(segInfo.size());
    segmentsProp.setSizeOfElements(0x2);
    for (int i = 0; i < segInfo.size(); i++) {
        byte[] seg = segInfo.get(i);
        segmentsProp.setElement(i, seg);
    }
    opt.addEscherProperty(segmentsProp);
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(bounds.getWidth())));
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bounds.getHeight())));
    opt.sortProperties();
    setAnchor(bounds);
    return numPoints;
}
Also used : PathIterator(java.awt.geom.PathIterator) EscherArrayProperty(org.apache.poi.ddf.EscherArrayProperty) Rectangle2D(java.awt.geom.Rectangle2D) ArrayList(java.util.ArrayList) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) Point2D(java.awt.geom.Point2D) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) AffineTransform(java.awt.geom.AffineTransform)

Example 49 with PathIterator

use of java.awt.geom.PathIterator in project JMRI by JMRI.

the class PositionablePolygon method scale.

private GeneralPath scale(float ratioX, float ratioY) {
    //     log.info("scale("+ratioX+" , "+ratioY+")");
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    PathIterator iter = getPathIterator(null);
    float[] coord = new float[6];
    while (!iter.isDone()) {
        int type = iter.currentSegment(coord);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                path.moveTo(coord[0] * ratioX, coord[1] * ratioY);
                break;
            case PathIterator.SEG_LINETO:
                path.lineTo(coord[0] * ratioX, coord[1] * ratioY);
                break;
            case PathIterator.SEG_QUADTO:
                path.quadTo(coord[0], coord[1], coord[2], coord[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                path.curveTo(coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
                break;
            case PathIterator.SEG_CLOSE:
                path.closePath();
                break;
            default:
                log.warn("Unhandled path iterator type: {}", type);
                break;
        }
        //      log.debug("type= "+type+"  x= "+coord[0]+", y= "+ coord[1]);
        iter.next();
    }
    return path;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) Point(java.awt.Point)

Example 50 with PathIterator

use of java.awt.geom.PathIterator in project JMRI by JMRI.

the class DrawPolygon method makeParamsPanel.

@Override
protected JPanel makeParamsPanel(PositionableShape ps) {
    JPanel panel = super.makeParamsPanel(ps);
    _pShape = (PositionablePolygon) ps;
    _editing = true;
    _pShape.editing(true);
    int x = getX();
    int y = getY();
    PathIterator iter = ps.getPathIterator(null);
    float[] coord = new float[6];
    while (!iter.isDone()) {
        iter.currentSegment(coord);
        _vertices.add(new Point(x + Math.round(coord[0]), y + Math.round(coord[1])));
        iter.next();
    }
    _pShape.drawHandles();
    return panel;
}
Also used : JPanel(javax.swing.JPanel) PathIterator(java.awt.geom.PathIterator) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

PathIterator (java.awt.geom.PathIterator)56 AffineTransform (java.awt.geom.AffineTransform)16 GeneralPath (java.awt.geom.GeneralPath)14 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)10 ArrayList (java.util.ArrayList)9 Point2D (java.awt.geom.Point2D)7 CachedPathIterator (com.android.layoutlib.bridge.util.CachedPathIteratorFactory.CachedPathIterator)5 Point (java.awt.Point)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Path2D (java.awt.geom.Path2D)3 Paint (java.awt.Paint)2 Rectangle (java.awt.Rectangle)2 TDoubleArrayList (gnu.trove.TDoubleArrayList)1 GradientPaint (java.awt.GradientPaint)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Shape (java.awt.Shape)1 TexturePaint (java.awt.TexturePaint)1 FontRenderContext (java.awt.font.FontRenderContext)1 GlyphVector (java.awt.font.GlyphVector)1