Revision: 56606
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 4, 2012 19:25 by hellowouter
Initial Code
// returns true if (x1,y1) is adjacent to (x2,y2) function isAjdacent(x1, y1, x2, y2) { var dx = Math.abs(x1 - x2), dy = Math.abs(y1 - y2); return (dx + dy === 1); }
Initial URL
http://books.google.be/books?ei=4RJ8T-ybE8ahOrTR7LwM&id=43qowOBC1CEC&q=manhattan#v=snippet&q=manhattan
Initial Description
This function returns true if the two sets of coordinates are neighbors and false if they ar not. The function easily determines whether they are neighbors by looking at the distance between the positions along both axes, also callled the Manhattan distance. The sum of the two distances must be exactly 1 if the positions are adjacent. Note: the coordinates should be integers
Initial Title
Check if coordinates are adjacent
Initial Tags
Initial Language
JavaScript