Search in sources :

Example 1 with Zone

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);
        }
    }
}
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 2 with Zone

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);
}
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 3 with Zone

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);
}
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 4 with Zone

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);
}
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 5 with Zone

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());
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)9 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)9 Zone (me.wobblyyyy.pathfinder2.zones.Zone)9 Test (org.junit.jupiter.api.Test)8 Rectangle (me.wobblyyyy.pathfinder2.geometry.Rectangle)6 PathfinderPluginManager (me.wobblyyyy.pathfinder2.plugin.PathfinderPluginManager)1