Last active
December 7, 2017 04:48
-
-
Save AudyOdi/54eb36b913066109574f47e2c58ddfb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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