Last active
December 15, 2022 07:07
-
-
Save deleteman/67fdcf8119a100fe72fc5742644fd190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pathIntersectsObstacle(start, end, obstacles) { | |
// Convert the starting and ending coordinates to grid coordinates | |
let {x:startX, y:startY} = start; | |
let {x:endX, y:endY} = end; | |
// Get the coordinates of all points on the path | |
let path = getPath(startX, startY, endX, endY); | |
//get the points in the array that are within the list of obstacles | |
let instersections = path.filter( point => !!obstacles.find( o => o.x == point[0] && o.y == point[1]) ).length | |
return instersections | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment