-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
DistanceSnake.js
28 lines (26 loc) · 953 Bytes
/
DistanceSnake.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @author samme
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Calculate the snake distance between two sets of coordinates (points).
*
* Snake distance (rectilinear distance, Manhattan distance) is the sum of the horizontal and vertical distances.
* It's the effective distance when movement is allowed only horizontally or vertically (but not both).
*
* @function Phaser.Math.Distance.Snake
* @since 3.22.0
*
* @param {number} x1 - The x coordinate of the first point.
* @param {number} y1 - The y coordinate of the first point.
* @param {number} x2 - The x coordinate of the second point.
* @param {number} y2 - The y coordinate of the second point.
*
* @return {number} The distance between each point.
*/
var SnakeDistance = function (x1, y1, x2, y2)
{
return Math.abs(x1 - x2) + Math.abs(y1 - y2);
};
module.exports = SnakeDistance;