Motivated by this challenge
Background
Let we have a square sheet of flexible material. Roughly speaking, we may close it on itself four ways:
Here the color marks the edges that connect and the vectors indicate the direction. The sphere and torus are obtained without flipping the sides, Klein bottle — with one flipping edge, and projective plane with both.
Surprisingly torus, not a sphere, in many senses is the simplest construct. For example, you can't comb a hairy ball flat without creating a cowlick (but torus can).
This is why torus is often used in games, puzzles and research.
Specific info
This is a separate picture for fundamental polygon (or closing rule) of projective plane (for 1..N notation):

Neighborhood of [1, 1] cell for N x N lattice:

Example how to find distance for points (2, 4) and (5, 3) in 5 x 5 projective plane:

Green paths are shortest, so it is the distance.
Task
For given two points and size of lattice,
find euclidean distance between points on the projective plane.
I/O
Flexible, in any suitable formats
Test cases
For 1..N notation
N, p1, p2 → distance For a better understanding, also indicated distance on torus (for same points and size):
5, [1, 1], [1, 1] → 0.0 (0.0) 5, [2, 4], [5, 3] → 2.24 (2.24) 5, [2, 4], [4, 1] → 2.0 (1.41) 10, [2, 2], [8, 8] → 4.12 (5.66) 10, [1, 1], [10, 10] → 1.0 (1.41) 10, [4, 4], [6, 6] → 2.83 (2.83) 