How many crossings are there? Is there a formula? Let's say I had a square that was divided by $m\times n$ rectangles. Call the rectangles length $m$ and the height $n$. The square is $m$ rectangles tall and $n$ rectangles wide. 
When you draw the diagonal, how many times does the diagonal cross a rectangle side?
 A: You can think of the square being divided by $m-1$ horizontal lines and $n-1$ vertical lines. The diagonal has to cross each of these lines once to get to the opposite corner, so that should be $m+n-2$ crossings. However, sometimes you might cross a horizontal line and a vertical line simultaneously (i.e. the diagonal passes through the corner of one of the rectangles). How often this happens depends on the highest common factor of $m$ and $n$: if the diagonal passes through the corner which is $p$ lines up and $q$ across, we must have $p/q=n/m$. So the number of times we pass through a corner (not counting the corners of the square) is $\mathrm{hcf}(m,n)-1$. We've already counted the corner crossings twice each (because they cross two lines), so we need to subtract them to get $m+n-\mathrm{hcf}(m,n)-1$.
A: Not including the point where the diagonal enters the grid and the point where it exits, it must cross the $m-1$ lines that divide the columns of $m$ rectangles in one dimension and the $n-1$ lines that divide the rows of $n$ rectangles in the other dimension.
That would be $m + n - 2$ crossings altogether, but depending on the dimensions of the grid, the diagonal may cross through the corner of one rectangle into another, thereby crossing one of the $m-1$ lines and one of the $n-1$ lines at one time. Usually we consider this just one "time" the rectangle crosses a rectangle side--but perhaps you don't consider it crossing a side at all, but rather crossing a corner.
The number of corner crossings is $\gcd(m,n) - 1$, where $\gcd(m,n)$ is the greatest common divisor of $m$ and $n.$
