Search in sources :

Example 56 with Point2DArray

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

the class PolygonView method create.

// TODO: If cornerRadius > 0 -> bug.
private static MultiPath create(final MultiPath result, final int sides, final double radius, final double cornerRadius) {
    final double ix = radius;
    final double iy = radius;
    if ((sides > 2) && (radius > 0)) {
        result.M(ix, iy - radius);
        if (cornerRadius <= 0) {
            for (int n = 1; n < sides; n++) {
                final double theta = (n * 2 * Math.PI / sides);
                result.L(ix + (radius * Math.sin(theta)), iy + (-1 * radius * Math.cos(theta)));
            }
            result.Z();
        } else {
            final Point2DArray list = new Point2DArray(ix, iy - radius);
            for (int n = 1; n < sides; n++) {
                final double theta = (n * 2 * Math.PI / sides);
                list.push(ix + (radius * Math.sin(theta)), iy + (-1 * radius * Math.cos(theta)));
            }
            Geometry.drawArcJoinedLines(result.getPathPartList(), list.push(ix, iy - radius), cornerRadius);
        }
    }
    return result;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray)

Example 57 with Point2DArray

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

the class WiresConnectorViewTest method testGetControlPoints.

@Test
@SuppressWarnings("unchecked")
public void testGetControlPoints() {
    Point2DArray linePoints = new Point2DArray(new Point2D(0, 0), new Point2D(0.1, 0.2), new Point2D(0.3, 0.4), new Point2D(0.5, 0.6), new Point2D(1, 2));
    when(line.getPoint2DArray()).thenReturn(linePoints);
    ControlPoint[] controlPoints = tested.getManageableControlPoints();
    assertNotNull(controlPoints);
    assertEquals(3, controlPoints.length);
    ControlPoint controlPoint0 = controlPoints[0];
    assertNotNull(controlPoint0);
    assertNotNull(controlPoint0.getLocation());
    assertEquals(0.1d, controlPoint0.getLocation().getX(), 0d);
    assertEquals(0.2d, controlPoint0.getLocation().getY(), 0d);
    ControlPoint controlPoint1 = controlPoints[1];
    assertNotNull(controlPoint1);
    assertNotNull(controlPoint1.getLocation());
    assertEquals(0.3d, controlPoint1.getLocation().getX(), 0d);
    assertEquals(0.4d, controlPoint1.getLocation().getY(), 0d);
    ControlPoint controlPoint2 = controlPoints[2];
    assertNotNull(controlPoint2);
    assertNotNull(controlPoint2.getLocation());
    assertEquals(0.5d, controlPoint2.getLocation().getX(), 0d);
    assertEquals(0.6d, controlPoint2.getLocation().getY(), 0d);
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Test(org.junit.Test)

Example 58 with Point2DArray

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

the class WiresConnectorViewTest method testUpdateControlPoint.

@Test
@SuppressWarnings("unchecked")
public void testUpdateControlPoint() {
    Point2D p = new Point2D(0.1, 0.2);
    Point2DArray cps = new Point2DArray(new Point2D(0, 0), p, new Point2D(1, 2));
    when(line.getPoint2DArray()).thenReturn(cps);
    IControlHandleList pointHandles = mock(IControlHandleList.class);
    when(pointHandles.isEmpty()).thenReturn(false);
    when(pointHandles.size()).thenReturn(1);
    tested.setPointHandles(pointHandles);
    tested.updateControlPoints(new ControlPoint[] { ControlPoint.build(0.5, 0.5) });
    assertEquals(0.5, p.getX(), 0d);
    assertEquals(0.5, p.getY(), 0d);
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList) Test(org.junit.Test)

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