# Picking cells which form a completed line between to 2d grid cells

I'm using Bresenham's line algorithm to calculate a "line" of cells between a start and end point on a 2D tile grid.

However, I'm using this during terrain generation to create a visible pathway, which means I need every cell to have at least one shared border with a neighbor.

This shows how the line algorithm is picking cells:

Yet if you imagine this as a road, there's no way to drive from one "segment" to the next.

How can I calculate a line that doesn't "jump" like this?

I've thought about using pathfinding or raycasting but they both feel like overkill because they worry about things I don't need here. I won't have obstacles to route around and I don't care about calculating ray intersections.

• If you can only make orthogonal (n,s,e,w) steps you can think about the problem as two separate loops, over evenly spaced vertical and horizontal steps. If you merge those two loops together it will interleave the vertical and horizontal steps and give you what you want (I think). I have an explanation and sample code here Commented Oct 1, 2016 at 16:53