Search in sources :

Example 11 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method getCardinalIntersects.

public static void getCardinalIntersects(final PathPartList path, final Point2DArray cardinals, final Set<Point2D>[] intersections, final boolean addCenter) {
    final Point2D center = cardinals.get(0);
    Point2D pathStart = new Point2D(0, 0);
    Point2D segmentStart = pathStart;
    int i = PathPartList.skipRedundantLeadingMoveTo(path);
    // A set is used as vertex's may intersect, so the start/end of two liens will intersect
    for (; i < path.size(); i++) {
        final PathPartEntryJSO entry = path.get(i);
        NFastDoubleArrayJSO points = entry.getPoints();
        switch(entry.getCommand()) {
            case PathPartEntryJSO.MOVETO_ABSOLUTE:
                {
                    points = entry.getPoints();
                    final Point2D m = new Point2D(points.get(0), points.get(1));
                    if (i == 0) {
                        // This position is needed, if we close the path.
                        pathStart = m;
                    }
                    segmentStart = m;
                    break;
                }
            case PathPartEntryJSO.LINETO_ABSOLUTE:
                {
                    points = entry.getPoints();
                    final double x0 = points.get(0);
                    final double y0 = points.get(1);
                    final Point2D end = new Point2D(x0, y0);
                    for (int j = 1; j < cardinals.size(); j++) {
                        final Point2D cardinal = cardinals.get(j);
                        final Point2D intersectPoint = Geometry.intersectLineLine(center, cardinal, segmentStart, end);
                        if (intersectPoint != null) {
                            addIntersect(intersections, j, intersectPoint);
                        }
                    }
                    segmentStart = end;
                    break;
                }
            case PathPartEntryJSO.CLOSE_PATH_PART:
                {
                    final double x0 = pathStart.getX();
                    final double y0 = pathStart.getY();
                    final Point2D end = new Point2D(x0, y0);
                    for (int j = 1; j < cardinals.size(); j++) {
                        final Point2D cardinal = cardinals.get(j);
                        final Point2D intersectPoint = Geometry.intersectLineLine(center, cardinal, segmentStart, end);
                        if (intersectPoint != null) {
                            addIntersect(intersections, j, intersectPoint);
                        }
                    }
                    segmentStart = end;
                    break;
                }
            case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
                {
                    points = entry.getPoints();
                    final double x0 = points.get(0);
                    final double y0 = points.get(1);
                    final Point2D p0 = new Point2D(x0, y0);
                    final double x1 = points.get(2);
                    final double y1 = points.get(3);
                    final Point2D p1 = new Point2D(x1, y1);
                    final Point2D end = p1;
                    final double r = points.get(4);
                    for (int j = 1; j < cardinals.size(); j++) {
                        final Point2D cardinal = cardinals.get(j);
                        final Point2DArray intersectPoints = Geometry.intersectLineArcTo(center, cardinal, segmentStart, p0, p1, r);
                        if (intersectPoints.size() > 0) {
                            for (final Point2D p : intersectPoints) {
                                addIntersect(intersections, j, p);
                            }
                        }
                    }
                    segmentStart = end;
                }
                break;
        }
    }
    if (addCenter) {
        addIntersect(intersections, 0, center);
    }
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) Point2D(com.ait.lienzo.client.core.types.Point2D) PathPartEntryJSO(com.ait.lienzo.client.core.types.PathPartEntryJSO)

Example 12 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method getIntersectPolyLinePath.

public static Point2DArray getIntersectPolyLinePath(final Point2DArray points, final PathPartList path, final boolean closed) {
    Point2DArray intersectPoints = null;
    if (null != path) {
        final int size = closed ? points.size() : points.size() - 1;
        for (int i = 0; i < size; i++) {
            final Point2D p1 = points.get(i);
            Point2D p2;
            if (closed) {
                p2 = (i < (size - 1)) ? points.get(i + 1) : points.get(0);
            } else {
                p2 = points.get(i + 1);
            }
            final Point2DArray segmentIntersectPoints = getIntersectLineSegmentPath(p1, p2, path);
            if (segmentIntersectPoints != null) {
                if (intersectPoints == null) {
                    intersectPoints = new Point2DArray();
                }
                for (final Point2D p : segmentIntersectPoints) {
                    intersectPoints.push(p);
                }
            }
        }
    }
    return intersectPoints;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 13 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method getBoundingBoxOfArcTo.

public static BoundingBox getBoundingBoxOfArcTo(final Point2D p0, final Point2D p1, final Point2D p2, final double r) {
    final Point2DArray arcPoints = getCanvasArcToPoints(p0, p1, p2, r);
    final BoundingBox box = getBoundingBoxOfArc(arcPoints.get(0), arcPoints.get(1), arcPoints.get(2), r);
    if (!arcPoints.get(0).equals(p0)) {
        // p0 is always the start point of the path, but not necessary of the arc - depending on the radius
        box.add(p0);
    }
    return box;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 14 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method removeInnerPoints.

public static final Point2DArray removeInnerPoints(final Point2D c, final Set<Point2D>[] pointSet) {
    final Point2DArray points = new Point2DArray();
    int i = 0;
    for (final Set<Point2D> set : pointSet) {
        double furthestDistance = -1;
        if ((set != null) && !set.isEmpty()) {
            for (final Point2D p : set) {
                final double currentDistance = p.distance(c);
                if (currentDistance > furthestDistance) {
                    furthestDistance = currentDistance;
                    points.set(i, p);
                }
            }
            i++;
        }
    }
    return points;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 15 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method getCardinalIntersects.

public static final Point2DArray getCardinalIntersects(final AbstractMultiPathPartShape<?> shape, final Direction[] requestedCardinals) {
    final Point2DArray cardinals = getCardinals(shape.getBoundingBox(), requestedCardinals);
    final Set<Point2D>[] intersections = getCardinalIntersects(shape, cardinals);
    final Point2DArray points = removeInnerPoints(cardinals.get(0), intersections);
    return points;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Set(java.util.Set) HashSet(java.util.HashSet)

Aggregations

Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)47 Point2D (com.ait.lienzo.client.core.types.Point2D)37 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)6 HashSet (java.util.HashSet)6 Set (java.util.Set)5 Direction (com.ait.lienzo.shared.core.types.Direction)4 IControlHandle (com.ait.lienzo.client.core.shape.wires.IControlHandle)3 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)3 PathPartList (com.ait.lienzo.client.core.types.PathPartList)3 Attributes (com.ait.lienzo.client.core.shape.Attributes)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 DashArray (com.ait.lienzo.client.core.types.DashArray)2 Transform (com.ait.lienzo.client.core.types.Transform)2 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)2 Test (org.junit.Test)2 Group (com.ait.lienzo.client.core.shape.Group)1 Line (com.ait.lienzo.client.core.shape.Line)1 Node (com.ait.lienzo.client.core.shape.Node)1 OrthogonalPolyLine (com.ait.lienzo.client.core.shape.OrthogonalPolyLine)1