Search in sources :

Example 1 with RectilinearConvexHull

use of org.eclipse.elk.alg.common.RectilinearConvexHull in project elk by eclipse.

the class RectilinearConvexHullTest 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
    Assert.assertTrue(Iterables.elementsEqual(actualRects, expectedRects));
}
Also used : RectilinearConvexHull(org.eclipse.elk.alg.common.RectilinearConvexHull) Point(org.eclipse.elk.alg.common.Point) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Test(org.junit.Test)

Example 2 with RectilinearConvexHull

use of org.eclipse.elk.alg.common.RectilinearConvexHull in project elk by eclipse.

the class RectilinearConvexHullTest 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 : RectilinearConvexHull(org.eclipse.elk.alg.common.RectilinearConvexHull) Random(java.util.Random) Point(org.eclipse.elk.alg.common.Point) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Point(org.eclipse.elk.alg.common.Point)

Example 3 with RectilinearConvexHull

use of org.eclipse.elk.alg.common.RectilinearConvexHull in project elk by eclipse.

the class RectilinearConvexHullTest 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));
    Assert.assertTrue(Iterables.elementsEqual(actualRects, expectedRects));
}
Also used : RectilinearConvexHull(org.eclipse.elk.alg.common.RectilinearConvexHull) Point(org.eclipse.elk.alg.common.Point) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Test(org.junit.Test)

Aggregations

Point (org.eclipse.elk.alg.common.Point)3 RectilinearConvexHull (org.eclipse.elk.alg.common.RectilinearConvexHull)3 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)3 Test (org.junit.Test)2 Random (java.util.Random)1