Search in sources :

Example 1 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project kie-wb-common by kiegroup.

the class DirectionalLineTest method testStkipParse.

@Test
public void testStkipParse() throws Exception {
    final Attributes attr = mock(Attributes.class);
    final Point2DArray points = new Point2DArray();
    when(attr.getControlPoints()).thenReturn(points);
    final boolean parsed = tested.parse(attr);
    assertFalse(parsed);
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Attributes(com.ait.lienzo.client.core.shape.Attributes) Test(org.junit.Test)

Example 2 with Point2DArray

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

the class Geometry method findIntersection.

/**
 * Finds intersecting point from the center of a path
 * @param x
 * @param y
 * @param path
 * @return the path's intersection point, or null if there's no intersection point
 */
public static Point2D findIntersection(final int x, final int y, final MultiPath path) {
    final Point2D pointerPosition = new Point2D(x, y);
    final BoundingBox box = path.getBoundingBox();
    final Point2D center = findCenter(box);
    // length just needs to ensure the c to xy is outside of the path
    final double length = box.getWidth() + box.getHeight();
    final Point2D projectionPoint = getProjection(center, pointerPosition, length);
    final Point2DArray points = new Point2DArray();
    points.push(center);
    points.push(projectionPoint);
    final Set<Point2D>[] intersects = Geometry.getCardinalIntersects(path, points);
    Point2D nearest = null;
    for (final Set<Point2D> set : intersects) {
        double nearesstDistance = length;
        if ((set != null) && !set.isEmpty()) {
            for (final Point2D p : set) {
                final double currentDistance = p.distance(pointerPosition);
                if (currentDistance < nearesstDistance) {
                    nearesstDistance = currentDistance;
                    nearest = p;
                }
            }
        }
    }
    return nearest;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Set(java.util.Set) HashSet(java.util.HashSet) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 3 with Point2DArray

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

the class Geometry method getCardinals.

/**
 * Returns cardinal points for a given bounding box
 *
 * @param box the bounding box
 * @return [C, N, NE, E, SE, S, SW, W, NW]
 */
public static final Point2DArray getCardinals(final BoundingBox box, final Direction[] requestedCardinals) {
    final Set<Direction> set = new HashSet<>(Arrays.asList(requestedCardinals));
    final Point2DArray points = new Point2DArray();
    final Point2D c = findCenter(box);
    final Point2D n = new Point2D(c.getX(), box.getY());
    final Point2D e = new Point2D(box.getX() + box.getWidth(), c.getY());
    final Point2D s = new Point2D(c.getX(), box.getY() + box.getHeight());
    final Point2D w = new Point2D(box.getX(), c.getY());
    final Point2D sw = new Point2D(w.getX(), s.getY());
    final Point2D se = new Point2D(e.getX(), s.getY());
    final Point2D ne = new Point2D(e.getX(), n.getY());
    final Point2D nw = new Point2D(w.getX(), n.getY());
    points.push(c);
    if (set.contains(Direction.NORTH)) {
        points.push(n);
    }
    if (set.contains(Direction.NORTH_EAST)) {
        points.push(ne);
    }
    if (set.contains(Direction.EAST)) {
        points.push(e);
    }
    if (set.contains(Direction.SOUTH_EAST)) {
        points.push(se);
    }
    if (set.contains(Direction.SOUTH)) {
        points.push(s);
    }
    if (set.contains(Direction.SOUTH_WEST)) {
        points.push(sw);
    }
    if (set.contains(Direction.WEST)) {
        points.push(w);
    }
    if (set.contains(Direction.NORTH_WEST)) {
        points.push(nw);
    }
    return points;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) Direction(com.ait.lienzo.shared.core.types.Direction) HashSet(java.util.HashSet)

Example 4 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 Point2DArray getCardinalIntersects(final PathPartList path, final Direction[] requestedCardinals) {
    final Point2DArray cardinals = getCardinals(path.getBoundingBox(), requestedCardinals);
    @SuppressWarnings("unchecked") final Set<Point2D>[] // c is removed, so -1
    intersections = new Set[cardinals.size()];
    getCardinalIntersects(path, cardinals, intersections, true);
    return removeInnerPoints(cardinals.get(0), intersections);
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Set(java.util.Set) HashSet(java.util.HashSet)

Example 5 with Point2DArray

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

the class Geometry method getPathIntersect.

/**
 * Finds the intersection of the connector's end segment on a path.
 * @param connection
 * @param path
 * @param c
 * @param pointIndex
 * @return
 */
public static Point2D getPathIntersect(final WiresConnection connection, final MultiPath path, final Point2D c, final int pointIndex) {
    final Point2DArray plist = connection.getConnector().getLine().getPoint2DArray();
    Point2D p = plist.get(pointIndex).copy();
    final Point2D offsetP = path.getComputedLocation();
    p.offset(-offsetP.getX(), -offsetP.getY());
    // p may be within the path boundary, so work of a vector that guarantees a point outside
    final double width = path.getBoundingBox().getWidth();
    if (c.equals(p)) {
        // this happens with the magnet is over the center of the opposite shape
        // so either the shapes are horizontall or vertically aligned.
        // this means we can just take the original centre point for the project
        // without this the project throw an error as you cannot unit() something of length 0,0
        p.offset(offsetP.getX(), offsetP.getY());
    }
    try {
        p = getProjection(c, p, width);
        final Set<Point2D>[] set = Geometry.getCardinalIntersects(path, new Point2DArray(c, p));
        final Point2DArray points = Geometry.removeInnerPoints(c, set);
        return (points.size() > 1) ? points.get(1) : null;
    } catch (final Exception e) {
        return null;
    }
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Set(java.util.Set) HashSet(java.util.HashSet) Point2D(com.ait.lienzo.client.core.types.Point2D)

Aggregations

Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)58 Point2D (com.ait.lienzo.client.core.types.Point2D)44 Test (org.junit.Test)11 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)7 HashSet (java.util.HashSet)6 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)6 Set (java.util.Set)5 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)4 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)4 Direction (com.ait.lienzo.shared.core.types.Direction)4 Attributes (com.ait.lienzo.client.core.shape.Attributes)3 IControlHandle (com.ait.lienzo.client.core.shape.wires.IControlHandle)3 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)3 PathPartList (com.ait.lienzo.client.core.types.PathPartList)3 Group (com.ait.lienzo.client.core.shape.Group)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)2 WiresConnector (com.ait.lienzo.client.core.shape.wires.WiresConnector)2 DashArray (com.ait.lienzo.client.core.types.DashArray)2 Transform (com.ait.lienzo.client.core.types.Transform)2 NFastArrayList (com.ait.tooling.nativetools.client.collection.NFastArrayList)2