Search in sources :

Example 21 with ElkRectangle

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

the class CompactionTest method testVerticalSpacingDuringHorizontalCompaction.

/**
 * "Two" is "center node". Node "one" is supposed to be blocked by "two", while "three" can move freely.
 */
@Test
public void testVerticalSpacingDuringHorizontalCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNodeSpacing one = new CTestNodeSpacing(new ElkRectangle(150, 11, 20, 20), 0d, 10d);
    graph.cNodes.add(one);
    CTestNodeSpacing two = new CTestNodeSpacing(new ElkRectangle(0, 40, 20, 20), 0d, 5d);
    graph.cNodes.add(two);
    CTestNodeSpacing three = new CTestNodeSpacing(new ElkRectangle(150, 76, 20, 20), 0d, 15d);
    graph.cNodes.add(three);
    compacter(graph).changeDirection(Direction.LEFT).compact().finish();
    assertEquals(20, one.hitbox.x, EPSILON);
    assertEquals(0, two.hitbox.x, EPSILON);
    assertEquals(0, 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 22 with ElkRectangle

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

the class CompactionTest method testVeticalSpacings.

/**
 * Vertical spacing should be preserved when compaction upwards or downwards.
 */
@Test
public void testVeticalSpacings() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    // test horizontal direction
    CTestNodeSpacing one = new CTestNodeSpacing(new ElkRectangle(0, 0, 20, 20), 0d, 5d);
    graph.cNodes.add(one);
    CTestNodeSpacing two = new CTestNodeSpacing(new ElkRectangle(0, 50, 20, 20), 0d, 7d);
    graph.cNodes.add(two);
    CTestNodeSpacing three = new CTestNodeSpacing(new ElkRectangle(0, 150, 20, 20), 0d, 10d);
    graph.cNodes.add(three);
    compacter(graph).changeDirection(Direction.UP).compact().finish();
    assertEquals(0, one.hitbox.y, EPSILON);
    assertEquals(27, two.hitbox.y, EPSILON);
    assertEquals(57, three.hitbox.y, EPSILON);
    compacter(graph).changeDirection(Direction.DOWN).compact().finish();
    assertEquals(0, one.hitbox.y, EPSILON);
    assertEquals(27, two.hitbox.y, EPSILON);
    assertEquals(57, three.hitbox.y, EPSILON);
    compacter(graph).changeDirection(Direction.UP).compact().finish();
    assertEquals(0, one.hitbox.y, EPSILON);
    assertEquals(27, two.hitbox.y, EPSILON);
    assertEquals(57, three.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 23 with ElkRectangle

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

the class CompactionTest method testDownGroupCompaction.

/**
 * The connection indicates a grouping, not an edge.
 *
 *   +--+         
 *   |  |     
 *   +--+-----+--+
 *            |  |
 *     +--+   +--+ 
 *     |  |  
 *     +--+ 
 */
@Test
public void testDownGroupCompaction() {
    CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
    CTestNode upperLeft = new CTestNode(new ElkRectangle(0, 0, 20, 20));
    graph.cNodes.add(upperLeft);
    CTestNode lowerLeft = new CTestNode(new ElkRectangle(5, 40, 10, 20));
    graph.cNodes.add(lowerLeft);
    CTestNode right = new CTestNode(new ElkRectangle(25, 10, 20, 20));
    graph.cNodes.add(right);
    CGroup group = new CGroup(upperLeft, right);
    graph.cGroups.add(group);
    compacter(graph).changeDirection(Direction.DOWN).compact().finish();
    assertEquals(15, upperLeft.hitbox.y, EPSILON);
    assertEquals(40, lowerLeft.hitbox.y, EPSILON);
    assertEquals(25, right.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 24 with ElkRectangle

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

the class RectlinearConvexHullTest 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));
    assertTrue(containsInAnyOrder(expectedRects, actualRects));
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Test(org.junit.Test)

Example 25 with ElkRectangle

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

the class RectlinearConvexHullTest method testCross.

/**
 * Test the following point set. For each corner of the cross a point to the point set added.
 * The hull is expected to consist of exactly 3 points per staircase, thus 12 points over all.
 *
 * <pre>
 *      __
 *   __|  |__
 *  |__    __|
 *     |__|
 * </pre>
 */
@Test
public void testCross() {
    List<Point> points = Lists.newArrayList();
    points.addAll(Arrays.asList(new Point(0d, 1d), new Point(1d, 1d), new Point(1d, 0d), new Point(2d, 0d), new Point(2d, 1d), new Point(3d, 1d), new Point(3d, 2d), new Point(2d, 2d), new Point(2d, 3d), new Point(1d, 3d), new Point(1, 2d), new Point(0d, 2d)));
    RectilinearConvexHull rch = RectilinearConvexHull.of(points);
    // test that the hull consists of the specified points in the exact order
    Assert.assertEquals(points, rch.getHull());
    List<ElkRectangle> expectedRects = Arrays.asList(new ElkRectangle(0, 1, 1, 1), new ElkRectangle(1, 0, 1, 3), new ElkRectangle(2, 1, 1, 1));
    List<ElkRectangle> actualRects = rch.splitIntoRectangles();
    // we don't care about order here
    assertTrue(containsInAnyOrder(expectedRects, actualRects));
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) 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