A hexagonal grid is a tiling of the plane consisting solely of regular hexagons. You will be given two pairs of coordinates, identifying two hexagons in the grid. Consider a line segment connecting the centers of these two hexagons, and return the number of hexagons that this line segment intersects.
Only count hexagons if the line passes through their interior. Do not count a hexagon if the line only intersects one of its corners or is coincident with one of its edges.
Hexagons will be identified by a pair of coordinates, as shown in the following diagram.
The first coordinate is proportional to the horizontal distance from the vertical axis.
The second coordinate is proportional to the vertical distance from the diagonal axis.
|