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;
}
}
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);
}
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);
}
}
}
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);
}
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");
}
}
Aggregations