'How to set linerender to be drawn only in 3 directions in Unity

I really don't know how the title of this question should look like, bcs the question is more complex.Here i uploaded 2 images.

Here i created board using positions from 0 to row lenght,and then i added linerenderer to draw a line from first touch position to last touach position and everything works fine

So my question is how to draw a line from starting point to last point,but if the line from starting point is not in the angle of 45,set it to be angle 45,between x and y and from starting point. F.e if i have a situation like on the picture above,i want to transform it like in the picture below.

It should look like this,and line only should be able to go horizontal,vertical and diagonal(180,90 and 45 degrees)

So if the line is not drawn on any of this directions,move it to closest one.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source