vleue / polyanya

Pathfinding using Polyanya
Apache License 2.0
260 stars 18 forks source link

Infinite loop with some meshes and paths #45

Closed MJohnson459 closed 9 months ago

MJohnson459 commented 9 months ago

In some circumstances I'm hitting an infinite loop when trying to generate a path. It seems to be related to the delta.

For example, with this mesh and a delta of 0.01:

mesh
2
10 8
3.775000 2.675000 2 -1 5
3.775000 1.175000 4 -1 4 5 7
2.125000 1.175000 6 -1 0 1 3 4 6
2.125000 1.275000 2 -1 0
1.775000 1.275000 3 -1 0 1
1.775000 1.175000 4 -1 1 2 3
0.375000 1.175000 2 -1 2
0.375000 0.375000 4 -1 2 3 6
4.075000 0.375000 4 -1 4 6 7
4.075000 2.675000 3 -1 5 7
3 4 2 3
3 5 2 4
3 7 5 6
3 5 7 2
3 1 2 8
3 0 1 9
3 7 8 2
3 8 9 1

These path fails to generate:

Creating path from Vec2(2.0705771, 1.2326102) to Vec2(2.074013, 1.0023998)
Creating path from Vec2(2.0911932, 1.2326102) to Vec2(2.7302842, 1.0573754)
Creating path from Vec2(1.8231869, 1.2119944) to Vec2(1.9846778, 0.93711627)

With a delta of 0.1, I can't get the infinite loop to happen on this mesh but these paths are wrong:

# should be direct but goes via a vertex
Creating path from Vec2(1.9406888, 1.1835598) to Vec2(2.0856483, 0.85704863)

# goes outside grid
Creating path from Vec2(2.1137958, 1.2623727) to Vec2(3.8983479, 1.3031867)

With all that said, I'm assuming there is something wrong with the mesh but as far as I can tell, it is valid based on the documentation. For reference it looks like this with the failures generally happening with polygons 0 and 1:

simple_mesh

mockersf commented 9 months ago

as you noticed on #46, this is mostly a question of precision. If you multiply all your coordinates by 10, it should work

MJohnson459 commented 9 months ago

I'm just going to close this. I can still cause the pathing to fail with a bad mesh but I can't find a good, small, sample that fails. In any case the real bug is in the bad mesh and it shouldn't really be up to this library to validate it. And it won't infinite loop now at least so I would say this is solved.