Search in sources :

Example 6 with PathIterator

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

the class Path_Delegate method offset.

/**
     * Offset the path by (dx,dy), returning true on success
     *
     * @param dx  The amount in the X direction to offset the entire path
     * @param dy  The amount in the Y direction to offset the entire path
     */
public void offset(float dx, float dy) {
    GeneralPath newPath = new GeneralPath();
    PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
    newPath.append(iterator, false);
    mPath = newPath;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) AffineTransform(java.awt.geom.AffineTransform)

Example 7 with PathIterator

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

the class DefaultProcessDiagramCanvas method getShapeIntersection.

/**
   * 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:
        }
        it.next();
    }
    return null;
}
Also used : PathIterator(java.awt.geom.PathIterator) Line2D(java.awt.geom.Line2D) Point(java.awt.Point) Paint(java.awt.Paint)

Example 8 with PathIterator

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

the class PathMeasure_Delegate method native_isClosed.

@LayoutlibDelegate
static /*package*/
boolean native_isClosed(long native_instance) {
    PathMeasure_Delegate pathMeasure = sManager.getDelegate(native_instance);
    assert pathMeasure != null;
    Path_Delegate path = Path_Delegate.getDelegate(pathMeasure.mNativePath);
    if (path == null) {
        return false;
    }
    int type = 0;
    float[] segment = new float[6];
    for (PathIterator pi = path.getJavaShape().getPathIterator(null); !pi.isDone(); pi.next()) {
        type = pi.currentSegment(segment);
    }
    // A path is a closed path if the last element is SEG_CLOSE
    return type == PathIterator.SEG_CLOSE;
}
Also used : CachedPathIterator(com.android.layoutlib.bridge.util.CachedPathIteratorFactory.CachedPathIterator) PathIterator(java.awt.geom.PathIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 9 with PathIterator

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

the class Path_Delegate method native_approximate.

@LayoutlibDelegate
static float[] native_approximate(long nPath, float error) {
    Path_Delegate pathDelegate = sManager.getDelegate(nPath);
    if (pathDelegate == null) {
        return null;
    }
    // Get a FlatteningIterator
    PathIterator iterator = pathDelegate.getJavaShape().getPathIterator(null, error);
    float[] segment = new float[6];
    float totalLength = 0;
    ArrayList<Point2D.Float> points = new ArrayList<Point2D.Float>();
    Point2D.Float previousPoint = null;
    while (!iterator.isDone()) {
        int type = iterator.currentSegment(segment);
        Point2D.Float currentPoint = new Point2D.Float(segment[0], segment[1]);
        // MoveTo shouldn't affect the length
        if (previousPoint != null && type != PathIterator.SEG_MOVETO) {
            totalLength += currentPoint.distance(previousPoint);
        }
        previousPoint = currentPoint;
        points.add(currentPoint);
        iterator.next();
    }
    int nPoints = points.size();
    float[] result = new float[nPoints * 3];
    previousPoint = null;
    for (int i = 0; i < nPoints; i++) {
        Point2D.Float point = points.get(i);
        float distance = previousPoint != null ? (float) previousPoint.distance(point) : .0f;
        result[i * 3] = distance / totalLength;
        result[i * 3 + 1] = point.x;
        result[i * 3 + 2] = point.y;
        totalLength += distance;
        previousPoint = point;
    }
    return result;
}
Also used : PathIterator(java.awt.geom.PathIterator) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 10 with PathIterator

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

the class Path2DCopyConstructor method testFlattening.

static void testFlattening(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(at, FLATNESS);
    final PathIterator itB = pathB.getPathIterator(at, FLATNESS);
    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 + "] !");
        }
        // Take care of floating-point precision:
        if (!equalsArrayEps(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("testFlattening: " + n + " segments.");
}
Also used : PathIterator(java.awt.geom.PathIterator)

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