Skip to content

Instantly share code, notes, and snippets.

@deleteman
Last active December 15, 2022 07:07
Show Gist options
  • Save deleteman/67fdcf8119a100fe72fc5742644fd190 to your computer and use it in GitHub Desktop.
Save deleteman/67fdcf8119a100fe72fc5742644fd190 to your computer and use it in GitHub Desktop.
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