Search in sources :

Example 61 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class RectilinearConvexHullTest method testLittleRobot.

/**
 * Test the following point set.
 *
 * <pre>
 *     __|__
 *  __|     |__
 *    |_____|
 *       |
 * </pre>
 */
@Test
public void testLittleRobot() {
    List<Point> points = Lists.newArrayList();
    points.addAll(Arrays.asList(new Point(0d, 2d), new Point(1d, 2d), new Point(1d, 1d), new Point(2d, 1d), new Point(2d, 0d), new Point(2d, 0d), new Point(2d, 1d), new Point(3d, 1d), new Point(3d, 2d), new Point(4d, 2d), new Point(4d, 2d), new Point(3d, 2d), new Point(3d, 3d), new Point(2d, 3d), new Point(2d, 4d), new Point(2d, 4d), new Point(2d, 3d), new Point(1d, 3d), new Point(1d, 2d), new Point(0d, 2d)));
    // test hull
    RectilinearConvexHull rch = RectilinearConvexHull.of(points);
    Assert.assertEquals(points, rch.getHull());
    // and rects
    List<ElkRectangle> actualRects = rch.splitIntoRectangles();
    List<ElkRectangle> expectedRects = Arrays.asList(new ElkRectangle(0, 2, 1, 0), new ElkRectangle(1, 1, 1, 2), new ElkRectangle(2, 0, 0, 4), new ElkRectangle(2, 1, 1, 2), new ElkRectangle(3, 2, 1, 0));
    Assert.assertTrue(Iterables.elementsEqual(actualRects, expectedRects));
}
Also used : RectilinearConvexHull(org.eclipse.elk.alg.common.RectilinearConvexHull) Point(org.eclipse.elk.alg.common.Point) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Test(org.junit.Test)

Example 62 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class OneDimensionalCompactorTest method testSubsequentDirectionsCompaction.

/* --------------------------------------------------
     * Testing subsequent calls with different directions
     * -------------------------------------------------- */
@Test
public void testSubsequentDirectionsCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CNode one = CNode.of().hitbox(new ElkRectangle(0, 0, 20, 20)).create(graph);
    CNode two = CNode.of().hitbox(new ElkRectangle(25, 0, 20, 20)).create(graph);
    CNode three = CNode.of().hitbox(new ElkRectangle(0, 25, 20, 20)).create(graph);
    CNode four = CNode.of().hitbox(new ElkRectangle(25, 25, 20, 20)).create(graph);
    Set<Direction> directions = EnumSet.of(Direction.LEFT, Direction.RIGHT, Direction.UP, Direction.DOWN);
    // subsequently apply all combinations of four subsequent compaction steps
    for (Direction d1 : directions) {
        for (Direction d2 : directions) {
            for (Direction d3 : directions) {
                for (Direction d4 : directions) {
                    compacter(graph).setSpacingsHandler(TEST_SPACING_HANDLER).changeDirection(d1).compact().changeDirection(d2).compact().changeDirection(d3).compact().changeDirection(d4).compact().finish();
                    // the way we modeled the graph, every node should stay where it is
                    String currentDirections = d1 + " " + d2 + " " + d3 + " " + d4;
                    assertEquals(currentDirections, 0, one.hitbox.x, EPSILON);
                    assertEquals(currentDirections, 0, one.hitbox.y, EPSILON);
                    assertEquals(currentDirections, 25, two.hitbox.x, EPSILON);
                    assertEquals(currentDirections, 0, two.hitbox.y, EPSILON);
                    assertEquals(currentDirections, 0, three.hitbox.x, EPSILON);
                    assertEquals(currentDirections, 25, three.hitbox.y, EPSILON);
                    assertEquals(currentDirections, 25, four.hitbox.x, EPSILON);
                    assertEquals(currentDirections, 25, four.hitbox.y, EPSILON);
                }
            }
        }
    }
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) Test(org.junit.Test)

Example 63 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class CompactionTest method testUpCompaction.

@Test
public void testUpCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode upper = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(upper);
    CTestNode lower = new CTestNode(new ElkRectangle(0, 30, 20, 20));
    graph.cNodes.add(lower);
    compacter(graph).changeDirection(Direction.UP).compact().finish();
    assertEquals(0, upper.hitbox.y, EPSILON);
    assertEquals(25, lower.hitbox.y, EPSILON);
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) Test(org.junit.Test)

Example 64 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class CompactionTest method testNoSpacingAppliedWithinGroups.

/**
 * Two separate groups, three nodes each.
 *
 * Care has to be taken when calculating the initial position of a {@link CGroup} not to include
 * any spacing between the group nodes. (Group nodes are rigidly fixed relative to each other
 * and thus no other spacing should be applied in between them). This test asserts that the
 * initial position of the groups is as expected.
 */
@Test
public void testNoSpacingAppliedWithinGroups() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode one = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(one);
    CTestNode two = new CTestNode(new ElkRectangle(20, 10, 20, 20));
    graph.cNodes.add(two);
    CTestNode three = new CTestNode(new ElkRectangle(40, 20, 20, 20));
    graph.cNodes.add(three);
    CGroup g1 = new CGroup(one, two, three);
    graph.cGroups.add(g1);
    CTestNode four = new CTestNode(new ElkRectangle(22, 80, 20, 20));
    graph.cNodes.add(four);
    CTestNode five = new CTestNode(new ElkRectangle(42, 90, 20, 20));
    graph.cNodes.add(five);
    CTestNode six = new CTestNode(new ElkRectangle(62, 100, 20, 20));
    graph.cNodes.add(six);
    CGroup g2 = new CGroup(four, five, six);
    graph.cGroups.add(g2);
    compacter(graph).changeDirection(Direction.LEFT).compact().changeDirection(Direction.RIGHT).compact().changeDirection(Direction.UP).compact().changeDirection(Direction.DOWN).compact().finish();
    assertEquals(0, one.hitbox.x, EPSILON);
    assertEquals(20, two.hitbox.x, EPSILON);
    assertEquals(40, three.hitbox.x, EPSILON);
    assertEquals(0, four.hitbox.x, EPSILON);
    assertEquals(20, five.hitbox.x, EPSILON);
    assertEquals(40, six.hitbox.x, EPSILON);
    assertEquals(0, one.hitbox.y, EPSILON);
    assertEquals(10, two.hitbox.y, EPSILON);
    assertEquals(20, three.hitbox.y, EPSILON);
    assertEquals(35, four.hitbox.y, EPSILON);
    assertEquals(45, five.hitbox.y, EPSILON);
    assertEquals(55, six.hitbox.y, EPSILON);
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup) Test(org.junit.Test)

Example 65 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class CompactionTest method testLeftGroupCompaction.

/**
 * The connection indicates a grouping, not an edge.
 *
 *   +--+         
 *   |  |     +--+
 *   +--+     |  |
 *            +--+
 *             |  
 *          +--+  
 *          |  |  
 *          +--+ 
 */
@Test
public void testLeftGroupCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode left = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(left);
    CTestNode upperRight = new CTestNode(new ElkRectangle(40, 5, 20, 20));
    graph.cNodes.add(upperRight);
    CTestNode lowerRight = new CTestNode(new ElkRectangle(30, 25, 20, 20));
    graph.cNodes.add(lowerRight);
    CGroup group = new CGroup(upperRight, lowerRight);
    graph.cGroups.add(group);
    compacter(graph).changeDirection(Direction.LEFT).compact().finish();
    assertEquals(0, left.hitbox.x, EPSILON);
    assertEquals(25, upperRight.hitbox.x, EPSILON);
    assertEquals(15, lowerRight.hitbox.x, EPSILON);
}
Also used : CGraph(org.eclipse.elk.alg.layered.compaction.oned.CGraph) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Direction(org.eclipse.elk.core.options.Direction) CGroup(org.eclipse.elk.alg.layered.compaction.oned.CGroup) Test(org.junit.Test)

Aggregations

ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)82 KVector (org.eclipse.elk.core.math.KVector)33 Test (org.junit.Test)27 Direction (org.eclipse.elk.core.options.Direction)18 CGraph (org.eclipse.elk.alg.layered.compaction.oned.CGraph)17 ElkPadding (org.eclipse.elk.core.math.ElkPadding)9 PortContext (org.eclipse.elk.alg.common.nodespacing.internal.PortContext)8 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)7 CGroup (org.eclipse.elk.alg.layered.compaction.oned.CGroup)6 Point (org.eclipse.elk.alg.common.Point)4 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)4 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 ElkNode (org.eclipse.elk.graph.ElkNode)4 RectilinearConvexHull (org.eclipse.elk.alg.common.RectilinearConvexHull)3 AtomicCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.AtomicCell)3 RectangleStripOverlapRemover (org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover)3 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)3 LNode (org.eclipse.elk.alg.layered.graph.LNode)3 Random (java.util.Random)2