javascript-astar icon indicating copy to clipboard operation
javascript-astar copied to clipboard

Any way to make diagonal paths less free?

Open ghost opened this issue 9 years ago • 6 comments

As far as I can tell, diagonal paths are free right now, meaning moving between walls whose corners touch is possible, like this: http://imgur.com/l8T5Dur

Is there any way to add in the option to disallow this behavior, preferably something as fancy as multiple options like this: http://pathfindingjs.readthedocs.org/en/latest/user-guide/diagonal-movement/

I really like how lightweight and fast your project is!

ghost avatar Mar 23 '15 07:03 ghost

Oh, good idea. That shouldn't be too hard to implement, since the diagonal option is already on the Graph, we would just need to modify the neighbors call to check isWall() on the relevant nodes before adding them to the neighbors list.

The options available in pathfindingjs seem reasonable. We would want to treat true being passed into the diagonal option in a reasonable way to prevent breaking people who are already using it.

Here is one proposal:

diagonal: 0 (default value - never) | 1 (always) | 2 (if at most one) | 3 (if no obstacles)

And then convert true into 1 to keep backwards compat.

What do you think about that idea?

bgrins avatar Mar 23 '15 15:03 bgrins

Yeah, that seems great! I actually made that issue before looking at your code, and I found it eminently readable! I was able to make the change in my local copy, but I added more options instead of extending the "diagonal" option (e.g., {diagonalFree: true}, {diagonalAtMostOne: true}, etc.). Your idea is better.

ghost avatar Mar 23 '15 18:03 ghost

Sounds great, could you file a PR with your updated changes?

bgrins avatar Mar 23 '15 18:03 bgrins

Sure, I'm at work now, but I'll submit one later today.

ghost avatar Mar 23 '15 18:03 ghost

Okay pull request submitted.

ghost avatar Mar 24 '15 02:03 ghost

was this ever fixed?

LukeWood avatar May 10 '20 01:05 LukeWood