Search in sources :

Example 16 with Rectangle

use of com.github.davidmoten.rtree2.geometry.Rectangle in project rtree2 by davidmoten.

the class Comparators method overlapArea.

private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
    Rectangle gPlusR = g.geometry().mbr().add(r);
    float m = 0;
    for (HasGeometry other : list) {
        if (other != g) {
            m += gPlusR.intersectionArea(other.geometry().mbr());
        }
    }
    return m;
}
Also used : Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle) HasGeometry(com.github.davidmoten.rtree2.geometry.HasGeometry)

Example 17 with Rectangle

use of com.github.davidmoten.rtree2.geometry.Rectangle in project rtree2 by davidmoten.

the class Utilities method entries1000.

static List<Entry<Object, Rectangle>> entries1000(Precision precision) {
    List<Entry<Object, Rectangle>> list = new ArrayList<Entry<Object, Rectangle>>();
    BufferedReader br = new BufferedReader(new InputStreamReader(BenchmarksRTree.class.getResourceAsStream("/1000.txt")));
    String line;
    try {
        while ((line = br.readLine()) != null) {
            String[] items = line.split(" ");
            double x = Double.parseDouble(items[0]);
            double y = Double.parseDouble(items[1]);
            Entry<Object, Rectangle> entry;
            if (precision == Precision.DOUBLE)
                entry = Entries.entry(new Object(), Geometries.rectangle(x, y, x + 1, y + 1));
            else
                entry = Entries.entry(new Object(), Geometries.rectangle((float) x, (float) y, (float) x + 1, (float) y + 1));
            list.add(entry);
        }
        br.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return list;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Example 18 with Rectangle

use of com.github.davidmoten.rtree2.geometry.Rectangle in project Pathfinder2 by Wobblyyyy.

the class TestLocalizedPathGen method testPartiallyObstructedPath.

@Test
public void testPartiallyObstructedPath() {
    List<Zone> zones = new ArrayList<Zone>() {

        {
            add(new Zone(new Rectangle(1, 3, 10, 4)));
        }
    };
    LocalizedPathGen gen = new LocalizedPathGen(zones, 0.5, 0.5);
    PointXY start = new PointXY(0, 0);
    PointXY end = new PointXY(10, 10);
    List<PointXY> path = gen.getPath(start, end);
    for (PointXY point : path) {
        Assertions.assertFalse(zones.get(0).isPointInShape(point));
    }
    Assertions.assertNotNull(path);
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) ArrayList(java.util.ArrayList) Rectangle(me.wobblyyyy.pathfinder2.geometry.Rectangle) Test(org.junit.jupiter.api.Test)

Example 19 with Rectangle

use of com.github.davidmoten.rtree2.geometry.Rectangle in project Pathfinder2 by Wobblyyyy.

the class TestLocalizedPathGen method testFullyObstructedPath.

@Test
public void testFullyObstructedPath() {
    List<Zone> zones = new ArrayList<Zone>() {

        {
            add(new Zone(new Rectangle(0, 3, 10, 4)));
        }
    };
    LocalizedPathGen gen = new LocalizedPathGen(zones, 0.5, 0.5);
    PointXY start = new PointXY(0, 0);
    PointXY end = new PointXY(10, 10);
    List<PointXY> path = gen.getPath(start, end);
    Assertions.assertNull(path);
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) ArrayList(java.util.ArrayList) Rectangle(me.wobblyyyy.pathfinder2.geometry.Rectangle) Test(org.junit.jupiter.api.Test)

Example 20 with Rectangle

use of com.github.davidmoten.rtree2.geometry.Rectangle in project Pathfinder2 by Wobblyyyy.

the class TestNodeValidator method testNodeValidation.

@Test
public void testNodeValidation() {
    LocalizedGrid grid = new LocalizedGrid(Grid.generateGrid(10, 10), 0, 0, 10, 10);
    Rectangle blocker = new Rectangle(5, 0, 10, 10);
    Zone blockerZone = new Zone(blocker);
    List<Zone> zones = new ArrayList<Zone>(1) {

        {
            add(blockerZone);
        }
    };
    NodeValidator.validateNodes(grid, zones);
    Assertions.assertTrue(grid.getNode(new PointXY(0, 0)).isValid());
    Assertions.assertFalse(grid.getNode(new PointXY(6, 6)).isValid());
    Assertions.assertFalse(grid.getNode(new PointXY(5, 0)).isValid());
    Assertions.assertTrue(grid.getNode(new PointXY(3, 5)).isValid());
    Assertions.assertFalse(grid.getNode(new PointXY(7, 7)).isValid());
    Assertions.assertFalse(grid.getNode(new PointXY(8, 8)).isValid());
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) Rectangle(me.wobblyyyy.pathfinder2.geometry.Rectangle) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

Rectangle (com.github.davidmoten.rtree2.geometry.Rectangle)15 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 Point (com.github.davidmoten.rtree2.geometry.Point)6 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)6 Rectangle (me.wobblyyyy.pathfinder2.geometry.Rectangle)6 Zone (me.wobblyyyy.pathfinder2.zones.Zone)6 HasGeometry (com.github.davidmoten.rtree2.geometry.HasGeometry)5 Test (org.junit.jupiter.api.Test)5 Geometries.point (com.github.davidmoten.rtree2.geometry.Geometries.point)3 Geometry (com.github.davidmoten.rtree2.geometry.Geometry)3 HashSet (java.util.HashSet)3 Position (com.github.davidmoten.grumpy.core.Position)2 LeafDefault (com.github.davidmoten.rtree2.internal.LeafDefault)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1