In the surface of a real donut you have a lot of problems due to the curvature and the different sizes, so the calculation is very complicated. For example, in a real donut the circle at the top and at the bottom of the donut have different length that the two circles at the equator. In the torus in this page all the horizontal circles have the same length.
This is a magical torus, where all the horizontal and vertical circles have the same length. It also has no Gaussian curvature. You can't construct one of this magical torus as a surface in the 3D space, but you can construct one as a surface in the 4D space.
The post says that for a torus, which is a product space of two (or more?) circles, we can analyze the the distance "along each circle" from a shared origin for a chosen basis. One circle is our "x" and the other is our "y". (Contrast with a plane and two lines.)
This seems reasonable if the objects we're looking to measure our distance to are expressed in terms of those circles as well, since this allows us to simply put a measure on each circle and get a distance formula for any two points that behaves the way we would like.
in your interpretation, the red circle moving to the boundary would look like this https://cdn.pixabay.com/photo/2013/03/08/05/53/frame-91452_9...
Instead, look at how the arrow types match here: https://upload.wikimedia.org/wikipedia/commons/3/37/Projecti...
the side you choose to glue first matters (compare before/after) https://upload.wikimedia.org/wikipedia/commons/b/ba/Inside-o...
and the orientation of the arrows https://upload.wikimedia.org/wikipedia/commons/6/64/Klein_Bo... also matters https://upload.wikimedia.org/wikipedia/commons/5/5c/Klein_bo...
Mathematically, you'd say that a sphere is simply connected and hence is its own universal cover and hence is not the quotient of a plane. Meanwhile, the universal cover of a torus is a plane and the fundamental domain of that covering can always be taken to be a parallelogram. The study of all possible such parallelograms is the standard example of a Teichmuller space [1] which is well-known recently due to both the use of the idea in "inter-universal Teichmuller theory" developed for the famous ABC conjecture work in 2012 as well as for being the subject of study of a winner of the most recent Fields medal [2] who is especially notable for being the first female recipient and was in the news again recently sadly for having died of cancer at a young age.
[1] https://en.wikipedia.org/wiki/Teichm%C3%BCller_space [2] https://en.wikipedia.org/wiki/Maryam_Mirzakhani
In the 2d example in the post, you would rescale the coordinates so the unit cell is from (-pi,pi) in both dimensions, and then the distance formula would be
sqrt(((cos(x1) - cos(x2))**2 + ((sin(x1) - sin(x1))**2 + ((cos(y1) - cos(y2))**2 + ((sin(y1) - sin(y1))**2)
This works well for doing things like determining the "nearest" point to another point, and similar operations, and has some other nice properties.(I forget the name of this system, but it is commonly used for calculations involving dihedral angles in MD simulations)
Folks who use this kind of distance measure might note that it also works well as a metric between angles (i.e. rotations) or between points on the projective line. For instance, see https://www.youtube.com/watch?v=oJAn--vsAzc (unfortunately not too self-contained a source)
1.0 % 5.0 = 1.0
6.0 % 5.0 = 1.0
7.0 % 5.0 = 2.0
7.4 % 5.0 = 2.4
7.4 % 1.0 = 0.4
With that in place, the torodial distance becomes a one-liner without any case distinctions (i.e. without ifs).They are a part of modern (and not-so-modern) programming languages (% in Python, Rust, etc.). Even C from quarter of a century ago supports them (fmod). There are also at least two CPU instructions on x86, fprem and fprem1.