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