easystarjs icon indicating copy to clipboard operation
easystarjs copied to clipboard

Fix incorrect calculation in get distance for diagonals

Open mikeparker opened this issue 5 years ago • 0 comments

I am implementing the ability to return incomplete paths and noticed this calculation was off.

For example if a node is 1x,1y away from the target this function incorrectly returns a distance of 2.4 instead of 1.4.

Another example, if a node is 4x,2y away, this should move diagonally for 2y which will also result in 2x movement, then the remaining 2x, so it should be 2*DIAGONAL_COST + 2*STRAIGHT_COST rather than 2*DIAGONAL_COST + 4*STRAIGHT_COST

mikeparker avatar Jan 07 '20 18:01 mikeparker