Search in sources :

Example 6 with Rectangle

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

the class RTree method calculateMaxView.

private Rectangle calculateMaxView(RTree<T, S> tree) {
    Iterator<Entry<T, S>> it = tree.entries().iterator();
    Rectangle r = null;
    while (it.hasNext()) {
        Entry<T, S> entry = it.next();
        if (r != null)
            r = r.add(entry.geometry().mbr());
        else
            r = entry.geometry().mbr();
    }
    if (r == null) {
        return rectangle(0, 0, 0, 0);
    } else {
        return r;
    }
}
Also used : Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle)

Example 7 with Rectangle

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

the class UtilTest method testMbrWithNegativeValues.

@Test
public void testMbrWithNegativeValues() {
    Rectangle r = Geometries.rectangle(-2D, -2, -1, -1);
    Rectangle mbr = Util.mbr(Collections.singleton(r));
    assertEquals(r, mbr);
    System.out.println(r);
}
Also used : Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle) Test(org.junit.Test)

Example 8 with Rectangle

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

the class NodeValidator method validateNodes.

/**
 * Validate a set of nodes. This will iterate through a grid's nodes and
 * update the validity of each of the nodes by determining if the node
 * is inside a solid zone (not valid) or not (valid).
 *
 * @param grid  the grid to validate the nodes of.
 * @param zones the list of zones to use for validation.
 */
public static void validateNodes(LocalizedGrid grid, List<Zone> zones) {
    List<Node> nodes = grid.getGrid().getNodes();
    Rectangle bounds = grid.getRectangle();
    List<Zone> filteredZones = new ArrayList<>(zones.size());
    for (Zone zone : zones) {
        if (zone.isSolid() && zone.getShape().doesCollideWith(bounds)) {
            filteredZones.add(zone);
        }
    }
    if (filteredZones.size() == 0)
        return;
    for (Node node : nodes) {
        PointXY point = grid.toPoint(new Coord(node));
        for (Zone zone : filteredZones) {
            if (point.isInside(zone.getShape()))
                node.setValid(false);
        }
    }
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) Rectangle(me.wobblyyyy.pathfinder2.geometry.Rectangle) ArrayList(java.util.ArrayList)

Example 9 with Rectangle

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

the class TestLocalizedPathGen method testObstructedNegativePathfinding.

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

        {
            add(new Zone(new Rectangle(-3, -2, 8, 3)));
        }
    };
    LocalizedPathGen gen = new LocalizedPathGen(zones, 0.5, 0.5);
    PointXY start = new PointXY(-5, -5);
    PointXY end = new PointXY(5, 5);
    List<PointXY> path = gen.getPath(start, end);
    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 10 with Rectangle

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

the class BenchmarksRTree method main.

public static void main(String[] args) {
    RTree<Object, Point> tree = RTree.maxChildren(28).star().<Object, Point>create(entries);
    Rectangle r = searchRectangle();
    if (longRun) {
        while (true) {
            if (Iterables.size(tree.search(r)) == 0) {
                System.out.println("unexpected");
            }
        }
    } else {
        long t = System.currentTimeMillis();
        long warmupTimeSeconds = 10;
        long benchmarkTimeSeconds = 10;
        long t2 = -1;
        long count = 0;
        while (true) {
            if (Iterables.size(tree.search(r)) == 0) {
                System.out.println("zero!!");
            }
            ;
            count++;
            if (count % 10000 == 0) {
                if (t2 == -1) {
                    if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(warmupTimeSeconds)) {
                        t2 = System.currentTimeMillis();
                    }
                } else if (System.currentTimeMillis() - t2 > TimeUnit.SECONDS.toMillis(benchmarkTimeSeconds)) {
                    break;
                }
            }
        }
        double ratePerSecond = count * 1000.0 / (System.currentTimeMillis() - t2);
        DecimalFormat df = new DecimalFormat("0.000");
        System.out.println("ratePerSecond=" + df.format(ratePerSecond / 1000000.0) + "m");
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle) Point(com.github.davidmoten.rtree2.geometry.Point)

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