Let's say we have a line going through the centers of two cells on a 2D grid, and we define a "pixel-perfect rasterized line" as the minimal set of 8-connected cells that best approximate the original line.
Finding such a set of cells is usually done via the Bresenham's algorithm, but in some cases [1, 2, 3] it can be useful to have some closed-form formula e.g. $$\text{distance(point, line)} \,<\, \text{thickness}/2,$$that tells whether a given cell's center belongs to such "rasterized line" or not.
For this purpose, $\text{thickness} = 1$ doesn't always give correct results, but empirically I found that $$\text{thickness} = \max(|N_x|, |N_y|)$$ (where $N$ is the normalized direction of the line) seems to always work.
Illustration of the correct (green) and incorrect (red) results:

Unfortunately, I don't have enough mathematical background to understand why this ends up being the correct answer. How would one actually derive it?