-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometry.js
More file actions
29 lines (27 loc) · 734 Bytes
/
geometry.js
File metadata and controls
29 lines (27 loc) · 734 Bytes
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
29
Game.Geometry = {
getLine: function(startX, startY, endX, endY) {
let points = [];
let dx = Math.abs(endX - startX);
let dy = Math.abs(endY - startY);
let sx = (startX < endX) ? 1 : -1;
let sy = (startY < endY) ? 1 : -1;
let err = dx - dy;
let e2;
while (true) {
points.push({x: startX, y: startY});
if (startX == endX && startY == endY) {
break;
}
e2 = err * 2;
if (e2 > -dx) {
err -= dy;
startX += sx;
}
if (e2 < dx){
err += dx;
startY += sy;
}
}
return points;
}
};