Search in sources :

Example 66 with ElkRectangle

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

the class RectlinearConvexHullTest method visualize.

private static void visualize(final List<Point> points, final RectilinearConvexHull rch) {
    KVector offset = new KVector(10, 10);
    double scale = 10;
    @SuppressWarnings("serial") JPanel p = new JPanel() {

        public void paint(java.awt.Graphics g) {
            super.paint(g);
            g.setColor(Color.DARK_GRAY);
            g.fillPolygon(toPolygon(rch, offset, scale));
            g.setColor(Color.GRAY);
            for (Point p : points) {
                g.fillRect((int) (p.x * scale + offset.x) - 1, (int) (p.y * scale + offset.y) - 1, 3, 3);
            }
            g.setColor(Color.PINK);
            for (ElkRectangle r : rch.splitIntoRectangles()) {
                g.drawRect((int) (r.x * scale + offset.x), (int) ((r.y) * scale + offset.y), (int) (r.width * scale), (int) (r.height * scale));
            }
            g.setColor(Color.GRAY);
        }
    };
    JFrame f = new JFrame();
    f.setSize(1500, 1500);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    f.getContentPane().add(p);
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : JPanel(javax.swing.JPanel) JFrame(javax.swing.JFrame) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 67 with ElkRectangle

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

the class RectlinearConvexHullTest method main.

/* ----------------
     * Simple JFrame that draws the hull and rects.
     */
public static void main(String[] args) {
    List<Point> points = Lists.newArrayList();
    points.addAll(Arrays.asList(new Point(1d, 6d), new Point(3d, 5d), new Point(5d, 2d), new Point(7d, 2d), new Point(9d, 4d), new Point(11d, 4d), new Point(11d, 8d), new Point(8d, 8d), new Point(8d, 12d), new Point(6d, 12d), new Point(6d, 10d), new Point(4d, 6d)));
    Random r = new Random();
    for (int i = 0; i < 100; ++i) {
        points.add(new Point((int) (r.nextDouble() * 100), (int) (r.nextDouble() * 100)));
    }
    RectilinearConvexHull rch = RectilinearConvexHull.of(points);
    System.out.println("HULL: " + rch.getHull());
    List<ElkRectangle> rects = rch.splitIntoRectangles();
    System.out.println("Rectangles: " + rects);
    visualize(points, rch);
}
Also used : Random(java.util.Random) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 68 with ElkRectangle

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

the class CompactionTest method testLeftCompaction.

@Test
public void testLeftCompaction() {
    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.LEFT).compact().finish();
    assertEquals(0, left.hitbox.x, EPSILON);
    assertEquals(25, 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)

Example 69 with ElkRectangle

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

the class CompactionTest method testUpGroupCompaction.

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

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

the class Block method placeRectsIn.

/**
 * Checks whether rectangles can fit in a given width.
 * Optionally the rectangles can be directly placed.
 * @param width The width
 * @param placeRects Whether the rectangles should be directly placed.
 * @return The bounds of this block if you would place all rectangles in the given width.
 */
private ElkRectangle placeRectsIn(final double width, final boolean placeRects) {
    // Next x coordinate at which a rect shall be placed in a blockrow
    double currentX = 0;
    // Next y coordinate at which a rect shall be placed in a blockrow
    double currentY = this.y;
    double currentWidth = 0;
    double currentHeight = 0;
    double maxHeightInRow = 0;
    double widthInRow = 0;
    int row = 0;
    if (placeRects) {
        rows.clear();
        rows.add(new BlockRow(this.x, this.y, nodeNodeSpacing));
    }
    // Current index in row.
    int index = 0;
    for (ElkNode rect : children) {
        if (currentX + rect.getWidth() + (index > 0 ? nodeNodeSpacing : 0) > width && maxHeightInRow > 0) {
            // Case new row
            currentX = 0;
            currentY += maxHeightInRow + nodeNodeSpacing;
            currentWidth = Math.max(currentWidth, widthInRow);
            currentHeight += maxHeightInRow + nodeNodeSpacing;
            maxHeightInRow = 0;
            widthInRow = 0;
            if (placeRects) {
                row++;
                rows.add(new BlockRow(this.x, currentY, nodeNodeSpacing));
            }
            // Reset current index in row
            index = 0;
        }
        widthInRow += rect.getWidth() + (index > 0 ? nodeNodeSpacing : 0);
        maxHeightInRow = Math.max(maxHeightInRow, rect.getHeight());
        if (placeRects) {
            rows.get(row).addRectangle(rect);
        }
        currentX += rect.getWidth() + (index > 0 ? nodeNodeSpacing : 0);
        index++;
    }
    currentWidth = Math.max(currentWidth, widthInRow);
    currentHeight += maxHeightInRow;
    if (placeRects) {
        this.width = currentWidth;
        this.height = currentHeight;
        this.parentRow.notifyAboutNodeChange();
    }
    return new ElkRectangle(x, y, currentWidth, currentHeight);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

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