In a printed circuit board (pcb) layout, the lines can only direct horizontally, vertically and diagonally. Such that every line is a combination of a horizontal/vertical part combined with a diagonal part.
I am looking for a way to implement this knowledge in Tikz. This means that when one for instance draws a line:
\draw (0,0) -- ++(5,2);
This should be drawn as:
\draw (0,0) -- ++(3,0) -- ++(2,2);
Where the horizontal and vertical direction always get priority over the diagonal one. Of course this can easily be implemented when the coordinates are given explicitly. But when for instance the coordinates have names, I don't see a way to do this.
Algorithmically the following should be done: say the two points are
- calculate the difference
abs(dx) >= abs(dy)do the following
abs(dx) < abs(dy) simply swap the x-axis with the y-axis.
If the original line is a perfect diagonal, the result is a diagonal as well (since the horizontal part has a length of zero). In case the line is perfectly horizontal/vertical, the resulting line is horizontal/vertical as well (since the diagonal part has a length equal to zero).