- const deltaX = x2 - x1;
- const deltaY = y2 - y1;
- const step = [ deltaX / Math.abs(deltaX), deltaY / Math.abs(deltaY) ];
- if (allowedSteps.every(st => st[0] != step[0] || st[1] != step[1]))
+ const deltaX = x2 - x1,
+ absDeltaX = Math.abs(deltaX);
+ const deltaY = y2 - y1,
+ absDeltaY = Math.abs(deltaY);
+ const step = [ deltaX / absDeltaX, deltaY / absDeltaY ];
+ if (
+ // Check that the step is a priori valid:
+ (absDeltaX != absDeltaY && deltaX != 0 && deltaY != 0) ||
+ allowedSteps.every(st => st[0] != step[0] || st[1] != step[1])
+ ) {