@@ -25,6 +25,7 @@ require('AnalyticHelper') -- for the test cases
2525require (' PathfinderUtil' )
2626require (' HybridAStar' )
2727require (' GraphPathfinder' )
28+ lu .EPS = 0.01
2829
2930local GraphEdge = GraphPathfinder .GraphEdge
3031local TestConstraints = CpObject (PathfinderConstraintInterface )
@@ -416,37 +417,70 @@ function TestWithTransitions:testTransition()
416417 start = State3D (- 5 , 0 , 0 , 0 )
417418 goal = State3D (210 , 205 , 0 , 0 )
418419 done , path , _ = runPathfinder ()
419- printPath ()
420420 lu .assertIsTrue (done )
421421 lu .assertEquals (# path , 14 )
422422 -- path contains all points of the edge it goes through
423423 path [1 ]:assertAlmostEquals (Vector (0 , 0 ))
424- path [3 ]:assertAlmostEquals (Vector (200 , 0 ))
424+ path [3 ]:assertAlmostEquals (Vector (203.8 , 0 ))
425425 -- here's the arch
426- path [13 ]:assertAlmostEquals (Vector (210 , 10 ))
426+ path [13 ]:assertAlmostEquals (Vector (210 , 100 ))
427427 path [# path ]:assertAlmostEquals (Vector (210 , 200 ))
428428end
429429
430- TestExtension = {}
431- function TestExtension :testExtension ()
430+ -- z to make it run last
431+ TestzExtension = {}
432+ function TestzExtension :testExtension ()
432433 local edge = GraphEdge (GraphEdge .UNIDIRECTIONAL , {})
433- for i = 0 , 100 , 5 do
434+ for i = 0 , 30 , 5 do
434435 edge :append (Vertex (i , i / 5 ))
435436 end
437+ local len = edge :getLength ()
436438 local graph = { edge }
437- pathfinder = GraphPathfinder (math.huge , 500 , 20 , graph )
439+ edge = GraphEdge (GraphEdge .UNIDIRECTIONAL , {})
440+ for i = 35 , 100 , 5 do
441+ edge :append (Vertex (i , i / 5 ))
442+ end
443+ len = len + edge :getLength () + 5 / math.cos (math.atan (1 / 5 ))
444+ table.insert (graph , edge )
445+ lu .assertAlmostEquals (len , 101.98 )
446+ pathfinder = GraphPathfinder (math.huge , 500 , 20 , graph , 5 )
438447 start = State3D (- 5 , 0 , 0 , 0 )
439- goal = State3D (50 , 10 , 0 , 0 )
448+ goal = State3D (50 , 0 , 0 , 0 )
440449 done , path , _ = runPathfinder ()
441- printPath ()
442450 lu .assertIsTrue (done )
443- lu .assertEquals (# path , 90 )
451+ lu .assertAlmostEquals (path :getLength (), len / 2 + 5 )
452+ lu .assertEquals (# path , 11 )
444453 -- path contains all points of the edge it goes through
445454 path [1 ]:assertAlmostEquals (Vector (0 , 0 ))
446- path [41 ]:assertAlmostEquals (Vector (200 , 0 ))
447- -- here's the arch
448- path [52 ]:assertAlmostEquals (Vector (210 , 10 ))
449- path [# path ]:assertAlmostEquals (Vector (210 , 200 ))
455+ path [6 ]:assertAlmostEquals (Vector (25 , 5 ))
456+ path [10 ]:assertAlmostEquals (Vector (50 , 10 ))
457+ path [11 ]:assertAlmostEquals (Vector (54.9 , 10.98 ))
458+
459+ pathfinder = GraphPathfinder (math.huge , 500 , 20 , graph , 15 )
460+ done , path , _ = runPathfinder ()
461+ lu .assertAlmostEquals (path :getLength (), len / 2 + 15 )
462+ lu .assertEquals (# path , 12 )
463+ path [11 ]:assertAlmostEquals (Vector (55 , 11 ))
464+ path [12 ]:assertAlmostEquals (Vector (64.71 , 12.94 ))
465+
466+ -- cut edge not long enough
467+ pathfinder = GraphPathfinder (math.huge , 500 , 20 , graph , 55 )
468+ done , path , _ = runPathfinder ()
469+ lu .assertAlmostEquals (path :getLength (), len / 2 + 55 )
470+ lu .assertEquals (# path , 20 )
471+ path [18 ]:assertAlmostEquals (Vector (90 , 18 ))
472+ path [19 ]:assertAlmostEquals (Vector (95 , 19 ))
473+ path [20 ]:assertAlmostEquals (Vector (103.93 , 20.79 ))
474+
475+ -- no cut edge
476+ pathfinder = GraphPathfinder (math.huge , 500 , 20 , graph , 5 )
477+ goal = State3D (100 , 10 , 0 , 0 )
478+ done , path , _ = runPathfinder ()
479+ lu .assertAlmostEquals (path :getLength (), len + 5 )
480+ lu .assertEquals (# path , 20 )
481+ path [18 ]:assertAlmostEquals (Vector (90 , 18 ))
482+ path [19 ]:assertAlmostEquals (Vector (95 , 19 ))
483+ path [20 ]:assertAlmostEquals (Vector (104.90 , 20.98 ))
450484
451485end
452486
0 commit comments