prettymuchbryce/easystarjs

thoughts on numeric grids

kkoch986 opened this issue · 5 comments

hey I'm working on a project where i have a numeric gird of weighted tiles. It would be cool to add some utilities for numeric grids.

I'm thinking functions like setWeightedGrid() which would take something like

[ [ 0, 1, 2 ], [ 0, 3, 4 ] ]

and assign weight 0 to 0, 1 to 1 etc...

The other useful function i think would be to set a threshold for passable tiles, something like setAcceptableThreshold() so i could say setAcceptableThreshold(10) and that means any tile > 10 would be deemed impassable.

I plan to implement these features on top of easystar anyway so just wanted to get your two cents and see if you would be interested in these features.

Hey kkoch. Thanks for the issue.

Do you think your problem could be solved with only one new method setAcceptableThreshold ?

Why might an explicit setWeightedGrid function be necessary ?

The purpose of setWeightedGrid would be to assign costs to each tile based on its value. If i ran something like this:

var easystar = new EasyStar.js();
easystar.setGrid(this.map);
easystar.setAcceptableTiles([true]);
easystar.enableDiagonals();

Even if the values in map are numeric it wouldnt call easystar.setTileCost(tileType, multiplicativeCost); for each number in there would it? My thought is having a setWeightedGrid function that assigns the cost to each tile according to its number and maybe flag it as a weighted cell so it could react to changes in the values.

I havent really looked into the source too much yet so I'm not sure exactly what would have to be done to accomplish this.

Thinking about it more, it wouldnt have to actually set the tile cost but maybe flag it as numerically weighted and when we look at the tile to get the cost we could just return the value

I understand now. You want to use setWeightedGrid as a way to batch-set tile costs, or even possibly create a second data structure to store these weighted values separately from the associated values from setGrid.

After thinking about it some more, I think this use case is pretty specific to your own needs. Something like this makes more sense to me as functionality that sits compositionally outside of EasyStar itself. You could keep track of these impassable tiles separately in your own code, and make them impassable with EasyStar by using the API calls setAcceptableTiles() or avoidAdditionalPoint().

no problem, thanks!