Search in sources :

Example 1 with Direction

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

the class AutoGridTest method testUpdateSize.

@Test
public void testUpdateSize() {
    final double size = 2.5;
    final double padding = 0.5;
    final double shapeSize = 100;
    final Direction direction = Direction.SOUTH;
    final BoundingBox boundingBox = new BoundingBox(0d, 0d, shapeSize, shapeSize);
    tested = new AutoGrid.Builder().forBoundingBox(boundingBox).withIconSize(size).withPadding(padding).towards(direction).build();
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getDirection());
    assertEquals(shapeSize, tested.getMaxSize(), 0);
    assertEquals((size + padding) / 2, tested.getMargin(), 0);
    final List<Point2D> expectedPoints = new ArrayList<>();
    final Iterator<Point2D> points = tested.iterator();
    int count = 5;
    for (int i = 0; i < count; i++) {
        final Point2D point = points.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, 0d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, 3d), expectedPoints.get(1));
    assertEquals(new Point2D(0d, 6d), expectedPoints.get(2));
    assertEquals(new Point2D(0d, 9d), expectedPoints.get(3));
    assertEquals(new Point2D(0d, 12d), expectedPoints.get(4));
    tested.setSize(6, 6);
    assertEquals(6, tested.getMaxSize(), 0);
    expectedPoints.clear();
    final Iterator<Point2D> points2 = tested.iterator();
    for (int i = 0; i < count; i++) {
        final Point2D point = points2.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, 0d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, 3d), expectedPoints.get(1));
    assertEquals(new Point2D(3d, 0d), expectedPoints.get(2));
    assertEquals(new Point2D(3d, 3d), expectedPoints.get(3));
    assertEquals(new Point2D(6d, 0d), expectedPoints.get(4));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 2 with Direction

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

the class AutoGridTest method testGrid1.

@Test
public void testGrid1() {
    final double size = 10;
    final double padding = 5;
    final Direction direction = Direction.EAST;
    final BoundingBox boundingBox = new BoundingBox(0d, 0d, 100d, 100d);
    tested = new AutoGrid.Builder().forBoundingBox(boundingBox).withIconSize(size).withPadding(padding).towards(direction).build();
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getDirection());
    assertEquals(100, tested.getMaxSize(), 0);
    assertEquals((size + padding) / 2, tested.getMargin(), 0);
    final List<Point2D> expectedPoints = new ArrayList<>();
    final Iterator<Point2D> points = tested.iterator();
    int count = 5;
    for (int i = 0; i < count; i++) {
        final Point2D point = points.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, -15d), expectedPoints.get(0));
    assertEquals(new Point2D(15d, -15d), expectedPoints.get(1));
    assertEquals(new Point2D(30d, -15d), expectedPoints.get(2));
    assertEquals(new Point2D(45d, -15d), expectedPoints.get(3));
    assertEquals(new Point2D(60d, -15d), expectedPoints.get(4));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 3 with Direction

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

the class AutoGridTest method testGrid2.

@Test
public void testGrid2() {
    final double size = 2.5;
    final double padding = 0.5;
    final Direction direction = Direction.SOUTH;
    final BoundingBox boundingBox = new BoundingBox(0d, 0d, 100d, 100d);
    tested = new AutoGrid.Builder().forBoundingBox(boundingBox).withIconSize(size).withPadding(padding).towards(direction).build();
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getDirection());
    assertEquals(100, tested.getMaxSize(), 0);
    assertEquals((size + padding) / 2, tested.getMargin(), 0);
    final List<Point2D> expectedPoints = new ArrayList<>();
    final Iterator<Point2D> points = tested.iterator();
    int count = 5;
    for (int i = 0; i < count; i++) {
        final Point2D point = points.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, 0d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, 3d), expectedPoints.get(1));
    assertEquals(new Point2D(0d, 6d), expectedPoints.get(2));
    assertEquals(new Point2D(0d, 9d), expectedPoints.get(3));
    assertEquals(new Point2D(0d, 12d), expectedPoints.get(4));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 4 with Direction

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

the class FixedLayoutGridTest method testGrid1.

@Test
public void testGrid1() {
    final double size = 10;
    final double padding = 5;
    final Direction direction = Direction.EAST;
    final int rows = 2;
    final int cols = 2;
    tested = new FixedLayoutGrid(padding, size, direction, rows, cols);
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getTowards());
    assertEquals(rows, tested.getRows());
    assertEquals(cols, tested.getCols());
    final List<Point2D> expectedPoints = new ArrayList<>();
    tested.iterator().forEachRemaining(expectedPoints::add);
    assertEquals(4, expectedPoints.size());
    assertEquals(new Point2D(0d, -15d), expectedPoints.get(0));
    assertEquals(new Point2D(15d, -15d), expectedPoints.get(1));
    assertEquals(new Point2D(0d, -30d), expectedPoints.get(2));
    assertEquals(new Point2D(15d, -30d), expectedPoints.get(3));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 5 with Direction

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

Aggregations

Point2D (com.ait.lienzo.client.core.types.Point2D)12 Direction (com.ait.lienzo.shared.core.types.Direction)12 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)5 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)4 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)1 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)1 PathPartList (com.ait.lienzo.client.core.types.PathPartList)1 HashSet (java.util.HashSet)1