tillarnold / fixed-2d-array

A fixed size 2D array in javascript
MIT License
5 stars 2 forks source link

distance() #11

Closed Benny- closed 7 years ago

Benny- commented 7 years ago

This is a feature request to add a distance function.

It calculates the distance between two points on the grid.

In my specific use case diagonal tiles are not bordering and should not be counted.

possibly commented 7 years ago

So I'm imagining the distance function taking two valid locations and returning a path that traverses the Fixed2dArray. The path's length is the Distance. Is this what your imagining?

Benny- commented 7 years ago

My use case only requires the distance between those points as an integer. Regardless, what you propose would be a excellent solution for my problem. The function name might need to be called something else, like findRoute(), findPath() or something else.

possibly commented 7 years ago

While you may only need the integer, the integer needs to reflect that diagnol movements were not considered in calculating that integer.

If pathfinding is necessary to derive the integer you need, perhaps you should look into the npm module Pathfinding and feed it the data stored in your Fixed2DArray. The module implements many common algorithms and operates over 2d arrays.

Benny- commented 7 years ago

That would be a excellent solution and would invalidate this feature request. Thanks for pointing me in the right direction.