Search in sources :

Example 81 with ElkRectangle

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

the class UtilsTest method distanceTest.

/**
 * Distance test using different directions.
 */
@Test
public void distanceTest() {
    List<Pair<KVector, Boolean>> vectors = Lists.newArrayList();
    // true if the nodes should collide
    vectors.add(Pair.of(new KVector(-20, 20), true));
    vectors.add(Pair.of(new KVector(-80, 0), false));
    vectors.add(Pair.of(new KVector(-20, 9), false));
    vectors.add(Pair.of(new KVector(0, 50), false));
    vectors.add(Pair.of(new KVector(-9.99, 50), false));
    vectors.add(Pair.of(new KVector(60, 60), false));
    vectors.add(Pair.of(new KVector(-30, 50), true));
    vectors.add(Pair.of(new KVector(-20, 130), true));
    vectors.add(Pair.of(new KVector(-20, -21), false));
    // Arrays.stream(new File(ElkUtil.debugFolderPath("test")).listFiles()).forEach(File::delete);
    Node n1 = new Node(r1.getCenter(), r1);
    for (Pair<KVector, Boolean> v : vectors) {
        Node n2 = new Node(rectangles.get(12).getCenter(), new ElkRectangle(rectangles.get(12)));
        double distance = n1.distance(n2, v.getFirst());
        // if they should collide, move them, otherwise check whether the returned distance is infinite
        if (v.getSecond()) {
            // move + check shortest distance
            n2.translate(v.getFirst().scaleToLength(distance));
            assertTrue(CompareFuzzy.eq(ElkMath.shortestDistance(n1.rect, n2.rect), 0.0));
        } else {
            assertTrue(Double.isInfinite(distance));
        }
    }
}
Also used : Node(org.eclipse.elk.alg.common.spore.Node) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Pair(org.eclipse.elk.core.util.Pair) Test(org.junit.Test)

Example 82 with ElkRectangle

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

the class Issue502Test method testLargeEnoughNode.

private void testLargeEnoughNode(final ElkNode node) {
    ElkRectangle requiredSize = new ElkRectangle();
    for (ElkNode child : node.getChildren()) {
        ElkRectangle childRect = new ElkRectangle(child.getX(), child.getY(), child.getWidth(), child.getHeight());
        requiredSize.union(childRect);
    }
    for (ElkEdge edge : node.getContainedEdges()) {
        for (ElkEdgeSection section : edge.getSections()) {
            for (ElkBendPoint bendPoint : section.getBendPoints()) {
                requiredSize.width = Math.max(requiredSize.width, bendPoint.getX());
                requiredSize.height = Math.max(requiredSize.height, bendPoint.getY());
            }
        }
    }
    assertTrue("Node not large enough for content. Size required: (" + requiredSize.width + ", " + requiredSize.height + "). " + "Actual size: (" + node.getWidth() + ", " + node.getHeight() + ")", node.getWidth() >= requiredSize.width && node.getHeight() >= requiredSize.height);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

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