Skip to content

Instantly share code, notes, and snippets.

@AudyOdi
Last active December 7, 2017 04:48
Show Gist options
  • Select an option

  • Save AudyOdi/54eb36b913066109574f47e2c58ddfb9 to your computer and use it in GitHub Desktop.

Select an option

Save AudyOdi/54eb36b913066109574f47e2c58ddfb9 to your computer and use it in GitHub Desktop.
// check diagonal
let dx = focusCoordinate.x - anchorCoordinate.x;
let dy = focusCoordinate.y - anchorCoordinate.y;
if (Math.abs(dx) === Math.abs(dy)) {
let loopCount = 1;
let getCalculatedCol = (iterator: number) => {
if (dx === dy) {
// diagonal from top left to bottom right or vice versa
let col = Math.min(focusCoordinate.x, anchorCoordinate.x);
return col + iterator;
} else {
// diagonal from top right to bottom left or vice versa
let col = Math.max(focusCoordinate.x, anchorCoordinate.x);
return col - iterator;
}
};
for (
let row = Math.min(focusCoordinate.y, anchorCoordinate.y) + 1;
row < Math.max(focusCoordinate.y, anchorCoordinate.y);
row++
) {
let index = row * dimension + getCalculatedCol(loopCount);
intermediateDotIndexes.push(index);
loopCount++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment