Search in sources :

Example 11 with BoundingBox

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

the class DelegateWiresCompositeControlTest method testBoundConstraints.

@Test
public void testBoundConstraints() {
    BoundingBox boundingBox = mock(BoundingBox.class);
    tested.setBoundsConstraint(boundingBox);
    verify(delegate, times(1)).setBoundsConstraint(eq(boundingBox));
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Test(org.junit.Test)

Example 12 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox 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 13 with BoundingBox

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

the class Geometry method setScaleToFit.

public static final IPrimitive<?> setScaleToFit(final IPrimitive<?> prim, final double wide, final double high) {
    final Point2D scale = prim.getScale();
    final BoundingBox bbox = prim.getBoundingBox();
    if (null != scale) {
        final double sx = scale.getX();
        final double sy = scale.getY();
        if ((sx != 1) || (sy != 1)) {
            return setScaleToFit(prim, wide, high, new BoundingPoints(bbox).transform(new Transform().scale(sx, sy)).getBoundingBox());
        }
    }
    return setScaleToFit(prim, wide, high, bbox);
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Transform(com.ait.lienzo.client.core.types.Transform) BoundingPoints(com.ait.lienzo.client.core.types.BoundingPoints)

Example 14 with BoundingBox

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

the class Geometry method getBoundingBoxOfArc.

public static BoundingBox getBoundingBoxOfArc(final Point2D ps, final Point2D pc, final Point2D pe, final double r) {
    final double xs = ps.getX();
    final double ys = ps.getY();
    final double xe = pe.getX();
    final double ye = pe.getY();
    // the length doesn't matter, just take largest x
    final Point2D p0 = new Point2D(xs > xe ? xs : xe, pc.getY());
    double as = Geometry.getAngleBetweenTwoLines(ps, pc, p0);
    if (ps.getY() < pc.getY()) {
        // deduct from 360, if angle is above
        as = Geometry.RADIANS_360 - as;
    }
    double ae = Geometry.getAngleBetweenTwoLines(pe, pc, p0);
    if (pe.getY() < pc.getY()) {
        // deduct from 360, if angle is above
        ae = Geometry.RADIANS_360 - ae;
    }
    if (!clockwise(as, ae)) {
        // reverse to make clockwise
        final double t = ae;
        ae = as;
        as = t;
    }
    if (ae < as) {
        // this only happens when as is before RADIANS_270 and and ae is after RADIANS_270
        ae += Geometry.RADIANS_360;
    }
    double xmin = 0, xmax = 0;
    double ymin = 0, ymax = 0;
    if (xs < xe) {
        xmin = xs;
        xmax = xe;
    } else {
        xmin = xe;
        xmax = xs;
    }
    if (ys < ye) {
        ymin = ys;
        ymax = ye;
    } else {
        ymin = ye;
        ymax = ys;
    }
    if (ae > RADIANS_90) {
        if (as < RADIANS_90) {
            ymax = pc.getY() + r;
        }
        if (ae > RADIANS_180) {
            if (as < RADIANS_180) {
                xmin = pc.getX() - r;
            }
            if (ae > RADIANS_270) {
                if (as < RADIANS_270) {
                    ymin = pc.getY() - r;
                }
                if (ae > RADIANS_360) {
                    xmax = pc.getX() + r;
                    if (ae > RADIANS_450) {
                        ymax = pc.getY() + r;
                        if (ae > RADIANS_540) {
                            xmin = pc.getX() - r;
                            if (ae > RADIANS_630) {
                                ymin = pc.getY() - r;
                            }
                        }
                    }
                }
            }
        }
    }
    return new BoundingBox(xmin, ymin, xmax, ymax);
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 15 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox 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)

Aggregations

BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)79 Point2D (com.ait.lienzo.client.core.types.Point2D)24 Test (org.junit.Test)16 ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)8 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)7 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)7 Context2D (com.ait.lienzo.client.core.Context2D)6 ArrayList (java.util.ArrayList)6 Direction (com.ait.lienzo.shared.core.types.Direction)5 Group (com.ait.lienzo.client.core.shape.Group)4 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)4 Text (com.ait.lienzo.client.core.shape.Text)3 Transform (com.ait.lienzo.client.core.types.Transform)3 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)3 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 MultiPathDecorator (com.ait.lienzo.client.core.shape.MultiPathDecorator)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)2 WiresConnector (com.ait.lienzo.client.core.shape.wires.WiresConnector)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 BoundingPoints (com.ait.lienzo.client.core.types.BoundingPoints)2