Search in sources :

Example 21 with PointXY

use of me.wobblyyyy.pathfinder2.geometry.PointXY 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)

Example 22 with PointXY

use of me.wobblyyyy.pathfinder2.geometry.PointXY in project Pathfinder2 by Wobblyyyy.

the class TestLocalizedPathGen method testUnobstructedPath.

@Test
public void testUnobstructedPath() {
    List<Zone> zones = new ArrayList<>();
    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);
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 23 with PointXY

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

Example 24 with PointXY

use of me.wobblyyyy.pathfinder2.geometry.PointXY in project Pathfinder2 by Wobblyyyy.

the class TestPathOptimizer method testLinearOptimization.

@Test
public void testLinearOptimization() {
    List<Zone> zones = new ArrayList<>();
    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);
    path = PathOptimizer.optimize(path);
    Assertions.assertNotNull(path);
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 25 with PointXY

use of me.wobblyyyy.pathfinder2.geometry.PointXY in project Pathfinder2 by Wobblyyyy.

the class TestPathOptimizer method testNonlinearOptimization.

@Test
public void testNonlinearOptimization() {
    Rectangle blockerShape = new Rectangle(5, 1, 6, 10);
    Zone blockerZone = new Zone(blockerShape);
    List<Zone> zones = new ArrayList<Zone>() {

        {
            add(blockerZone);
        }
    };
    LocalizedPathGen gen = new LocalizedPathGen(zones, 0.5, 0.5);
    PointXY start = new PointXY(0, 0);
    PointXY end = new PointXY(10, 10);
    List<PointXY> unoptimized = gen.getPath(start, end);
    List<PointXY> optimized = PathOptimizer.optimize(unoptimized);
    List<PointXY> overOptimized = PathOptimizer.optimize(optimized);
    Assertions.assertNotNull(unoptimized);
    Assertions.assertNotNull(optimized);
    Assertions.assertNotNull(overOptimized);
    int unoptimizedSize = unoptimized.size();
    int optimizedSize = optimized.size();
    int overOptimizedSize = overOptimized.size();
    double unoptimizedLength = PathOptimizer.determineLength(unoptimized);
    double optimizedLength = PathOptimizer.determineLength(optimized);
    double overOptimizedLength = PathOptimizer.determineLength(overOptimized);
// Assertions.assertEquals(30, unoptimizedSize);
// Assertions.assertEquals(16, optimizedSize);
// Assertions.assertEquals(16, overOptimizedSize);
// Assertions.assertTrue(Equals.soft(16.778, unoptimizedLength, 0.01));
// Assertions.assertEquals(optimizedLength, overOptimizedLength);
}
Also used : Zone(me.wobblyyyy.pathfinder2.zones.Zone) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) Rectangle(me.wobblyyyy.pathfinder2.geometry.Rectangle) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)24 ArrayList (java.util.ArrayList)12 Test (org.junit.jupiter.api.Test)10 Zone (me.wobblyyyy.pathfinder2.zones.Zone)9 Rectangle (me.wobblyyyy.pathfinder2.geometry.Rectangle)6 Angle (me.wobblyyyy.pathfinder2.geometry.Angle)5 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)5 Pathfinder (me.wobblyyyy.pathfinder2.Pathfinder)3 NullPointException (me.wobblyyyy.pathfinder2.exceptions.NullPointException)2 SimpleMatrix (org.ejml.simple.SimpleMatrix)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InvalidToleranceException (me.wobblyyyy.pathfinder2.exceptions.InvalidToleranceException)1 Line (me.wobblyyyy.pathfinder2.geometry.Line)1 Translation (me.wobblyyyy.pathfinder2.geometry.Translation)1 Listener (me.wobblyyyy.pathfinder2.listening.Listener)1 SimulatedOdometry (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry)1 SimulatedRobot (me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot)1 ElapsedTimer (me.wobblyyyy.pathfinder2.time.ElapsedTimer)1 LinearTrajectory (me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)1 Gamepad (me.wobblyyyy.pathfinder2.utils.Gamepad)1