Search in sources :

Example 76 with ElkRectangle

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

the class GreedyRectangleStripOverlapRemover method removeOverlaps.

@Override
public double removeOverlaps(final RectangleStripOverlapRemover overlapRemover) {
    final double gap = overlapRemover.getGap();
    Set<RectangleNode> alreadyPlacedNodes = Sets.newHashSet();
    double stripSize = 0;
    for (RectangleNode currNode : overlapRemover.getRectangleNodes()) {
        // We start with an initial y coordinate of zero
        double yPos = 0;
        // Sort the node's list of overlapping nodes by y coordinate
        currNode.getOverlappingNodes().sort(GreedyRectangleStripOverlapRemover::compareByYCoordinate);
        // coordinate would cause an overlap
        for (RectangleNode overlapNode : currNode.getOverlappingNodes()) {
            if (alreadyPlacedNodes.contains(overlapNode)) {
                ElkRectangle currRect = currNode.getRectangle();
                ElkRectangle overlapRect = overlapNode.getRectangle();
                // Check if the current y coordinate would cause an overlap with the overlap node
                if (yPos < overlapRect.y + overlapRect.height + gap && yPos + currRect.height + gap > overlapRect.y) {
                    yPos = overlapRect.y + overlapRect.height + gap;
                }
            }
        }
        // Apply the y coordinate and remember that this node is now placed
        currNode.getRectangle().y = yPos;
        alreadyPlacedNodes.add(currNode);
        // Update the strip size
        stripSize = Math.max(stripSize, currNode.getRectangle().y + currNode.getRectangle().height);
    }
    return stripSize;
}
Also used : RectangleNode(org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover.RectangleNode) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 77 with ElkRectangle

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

the class HorizontalPortPlacementSizeCalculator method computeHorizontalPortMargins.

/**
 * Sets the horizontal margins of all ports such that they include the space necessary to place their labels.
 */
private static void computeHorizontalPortMargins(final NodeContext nodeContext, final PortSide portSide, final boolean portLabelsOutside) {
    for (PortContext portContext : nodeContext.portContexts.get(portSide)) {
        double labelWidth = portContext.portLabelCell != null ? portContext.portLabelCell.getMinimumWidth() : 0;
        if (labelWidth > 0) {
            if (portContext.labelsNextToPort) {
                // The label is placed next to the port
                double portWidth = portContext.port.getSize().x;
                if (labelWidth > portWidth) {
                    double overhang = (labelWidth - portWidth) / 2;
                    portContext.portMargin.left = overhang;
                    portContext.portMargin.right = overhang;
                }
            } else {
                // The label is either placed outside (right to the port) or possibly inside, but for a compound
                // node, which means that it is placed right of the port as well to keep it from overlapping with
                // inside edges
                portContext.portMargin.right = nodeContext.portLabelSpacing + labelWidth;
            }
        } else if (PortLabelPlacement.isFixed(nodeContext.portLabelsPlacement)) {
            // The fixed port label is not considered with portContext.portLabelCell. Nevertheless, a port margin
            // must be added if necessary.
            ElkRectangle labelsBounds = ElkUtil.getLabelsBounds(portContext.port);
            if (labelsBounds.x < 0) {
                // Add the part of the label that is on the left of the port to the left margin
                portContext.portMargin.left = -labelsBounds.x;
            }
            if (labelsBounds.x + labelsBounds.width > portContext.port.getSize().x) {
                // Add the part of the label that is on the right of the port to the right margin
                portContext.portMargin.right = labelsBounds.x + labelsBounds.width - portContext.port.getSize().x;
            }
        }
    }
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) PortContext(org.eclipse.elk.alg.common.nodespacing.internal.PortContext)

Example 78 with ElkRectangle

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

the class ElkMathTest method testPathContains.

@Test
public void testPathContains() {
    ElkRectangle rect = new ElkRectangle(23, 14, 20, 20);
    KVectorChain path = new KVectorChain();
    path.add(24, 15);
    path.add(27, 20);
    path.add(39, 30);
    path.add(29, 19);
    assertTrue(ElkMath.contains(rect, path));
    // on border
    KVectorChain path2 = new KVectorChain(path);
    path2.add(23, 14);
    assertTrue(!ElkMath.contains(rect, path2));
    // outside
    path.add(10, 10);
    assertTrue(!ElkMath.contains(rect, path));
}
Also used : KVectorChain(org.eclipse.elk.core.math.KVectorChain) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Test(org.junit.Test)

Example 79 with ElkRectangle

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

the class UtilsTest method init.

@Before
public void init() {
    r1 = new ElkRectangle(0, 0, 20, 60);
    ElkRectangle r2 = new ElkRectangle(40, 20, 20, 20);
    ElkRectangle r3 = new ElkRectangle(40, 40, 20, 20);
    ElkRectangle r4 = new ElkRectangle(30, 70, 20, 20);
    ElkRectangle r5 = new ElkRectangle(20, 80, 20, 20);
    ElkRectangle r6 = new ElkRectangle(10, 80, 20, 20);
    ElkRectangle r7 = new ElkRectangle(0, 80, 20, 20);
    ElkRectangle r8 = new ElkRectangle(-30, 70, 20, 20);
    ElkRectangle r9 = new ElkRectangle(-40, 40, 20, 20);
    ElkRectangle r10 = new ElkRectangle(-40, 20, 20, 20);
    ElkRectangle r11 = new ElkRectangle(-30, -20, 20, 20);
    ElkRectangle r12 = new ElkRectangle(-20, -40, 20, 20);
    ElkRectangle r13 = new ElkRectangle(0, -30, 20, 20);
    ElkRectangle r14 = new ElkRectangle(30, -30, 20, 20);
    ElkRectangle r15 = new ElkRectangle(20, 0, 20, 20);
    ElkRectangle r16 = new ElkRectangle(0, 60, 20, 20);
    rectangles = Lists.newArrayList(r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16);
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Before(org.junit.Before)

Example 80 with ElkRectangle

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

the class UtilsTest method overlapTest.

/**
 * Testing the computed overlap of two rectangles by moving one accordingly and checking
 * whether the distance becomes >= 0.
 */
@Test
public void overlapTest() {
    ElkRectangle r1 = new ElkRectangle(0, 0, 40, 80);
    ElkRectangle r2 = new ElkRectangle(0, 0, 70, 20);
    ElkRectangle r3 = new ElkRectangle(10, 50, 70, 20);
    ElkRectangle r4 = new ElkRectangle(-40, 30, 70, 20);
    ElkRectangle r5 = new ElkRectangle(-60, 70, 70, 20);
    ElkRectangle r6 = new ElkRectangle(-10, 70, 70, 20);
    ElkRectangle r7 = new ElkRectangle(-20, -10, 70, 20);
    ElkRectangle r8 = new ElkRectangle(10, 20, 20, 20);
    ElkRectangle r9 = new ElkRectangle(-20, -20, 100, 120);
    ElkRectangle r10 = new ElkRectangle(0, -0.001, 40, 80);
    List<ElkRectangle> rs = Lists.newArrayList(r2, r3, r4, r5, r6, r7, r8, r9, r10);
    rs.forEach(r -> assertTrue(testOverlapComputation(r1, r)));
}
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