use of me.wobblyyyy.pathfinder2.zones.Zone 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 me.wobblyyyy.pathfinder2.zones.Zone 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 me.wobblyyyy.pathfinder2.zones.Zone 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 me.wobblyyyy.pathfinder2.zones.Zone 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 me.wobblyyyy.pathfinder2.zones.Zone in project Pathfinder2 by Wobblyyyy.
the class TestLocalizedPathGen method testUnobstructedNegativePathfinding.
@Test
public void testUnobstructedNegativePathfinding() {
List<Zone> zones = new ArrayList<>();
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);
Assertions.assertEquals(2, path.size());
}
Aggregations