Search in sources :

Example 26 with ElkRectangle

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

the class CompactionTest method testLeftCompactionEqualCoordinate.

@Test
public void testLeftCompactionEqualCoordinate() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode top = new CTestNodeSpacing(new ElkRectangle(0, 0, 20, 20), 0d, 0d);
    graph.cNodes.add(top);
    CTestNode bot = new CTestNodeSpacing(new ElkRectangle(30, 20, 20, 20), 0d, 0d);
    graph.cNodes.add(bot);
    compacter(graph).setConstraintAlgorithm(OneDimensionalCompactor.SCANLINE_CONSTRAINTS).changeDirection(Direction.LEFT).compact().finish();
    assertEquals(0, top.hitbox.x, EPSILON);
    assertEquals(0, bot.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) Test(org.junit.Test)

Example 27 with ElkRectangle

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

the class CompactionTest method testSubsequentDirectionsCompaction.

/* --------------------------------------------------
     * Testing subsequent calls with different directions
     * -------------------------------------------------- */
@Test
public void testSubsequentDirectionsCompaction() {
    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(25, 0, 20, 20));
    graph.cNodes.add(two);
    CTestNode three = new CTestNode(new ElkRectangle(0, 25, 20, 20));
    graph.cNodes.add(three);
    CTestNode four = new CTestNode(new ElkRectangle(25, 25, 20, 20));
    graph.cNodes.add(four);
    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).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 : 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 28 with ElkRectangle

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

the class CompactionTest method testDownCompaction.

@Test
public void testDownCompaction() {
    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.DOWN).compact().finish();
    assertEquals(5, upper.hitbox.y, EPSILON);
    assertEquals(30, 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 29 with ElkRectangle

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

the class CompactionTest method testHorizontalSpacings.

/* --------------------------------------------------
     *        Testing different kinds of spacings.
     * --------------------------------------------------*/
/*
     * We support different spacing values between nodes and edges in vertical and horizontal
     * direction. Thereby "vertical" and "horizontal" depends on the compaction direction.
     * Furthermore, we support individual spacings between any pair of nodes.
     */
/**
 * Horizontal spacing should be preserved when compaction leftwards or rightwards.
 */
@Test
public void testHorizontalSpacings() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    // test horizontal direction
    CTestNodeSpacing one = new CTestNodeSpacing(new ElkRectangle(0, 0, 20, 20), 5d, 0d);
    graph.cNodes.add(one);
    CTestNodeSpacing two = new CTestNodeSpacing(new ElkRectangle(50, 0, 20, 20), 7d, 0d);
    graph.cNodes.add(two);
    CTestNodeSpacing three = new CTestNodeSpacing(new ElkRectangle(150, 0, 20, 20), 10d, 0d);
    graph.cNodes.add(three);
    compacter(graph).changeDirection(Direction.LEFT).compact().finish();
    assertEquals(0, one.hitbox.x, EPSILON);
    assertEquals(27, two.hitbox.x, EPSILON);
    assertEquals(57, three.hitbox.x, EPSILON);
    compacter(graph).changeDirection(Direction.RIGHT).compact().finish();
    assertEquals(0, one.hitbox.x, EPSILON);
    assertEquals(27, two.hitbox.x, EPSILON);
    assertEquals(57, three.hitbox.x, EPSILON);
    compacter(graph).changeDirection(Direction.LEFT).compact().finish();
    assertEquals(0, one.hitbox.x, EPSILON);
    assertEquals(27, two.hitbox.x, EPSILON);
    assertEquals(57, three.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) Test(org.junit.Test)

Example 30 with ElkRectangle

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

the class CompactionTest method testRightCompaction.

@Test
public void testRightCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode left = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(left);
    CTestNode right = new CTestNode(new ElkRectangle(30, 0, 20, 20));
    graph.cNodes.add(right);
    compacter(graph).changeDirection(Direction.RIGHT).compact().finish();
    assertEquals(5, left.hitbox.x, EPSILON);
    assertEquals(30, right.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) 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