Search in sources :

Example 21 with Rectangle

use of com.github.davidmoten.rtree2.geometry.Rectangle 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

Rectangle (com.github.davidmoten.rtree2.geometry.Rectangle)15 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 Point (com.github.davidmoten.rtree2.geometry.Point)6 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)6 Rectangle (me.wobblyyyy.pathfinder2.geometry.Rectangle)6 Zone (me.wobblyyyy.pathfinder2.zones.Zone)6 HasGeometry (com.github.davidmoten.rtree2.geometry.HasGeometry)5 Test (org.junit.jupiter.api.Test)5 Geometries.point (com.github.davidmoten.rtree2.geometry.Geometries.point)3 Geometry (com.github.davidmoten.rtree2.geometry.Geometry)3 HashSet (java.util.HashSet)3 Position (com.github.davidmoten.grumpy.core.Position)2 LeafDefault (com.github.davidmoten.rtree2.internal.LeafDefault)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1