https://medium.com/@avolitty/optimizing-calculation-of-8-directional-grid-navigation-in-c-be03047f8fb1