For reference, here's the latest from a dev on spacing: https://forums.factorio.com/viewtopic.php?p=592880#p592880
- elevated-straight-rail has a length of 2 (equals to 2.00 required support distance)
- elevated-half-diagonal-rail has a length of 4.472135955 (equals to 4.48 required support distance)
- elevated-curved-a-rail has a length of 5.132284556 (equals to 5.14 required support distance)
- elevated-curved-b-rail has a length of 5.077891568 (equals to 5.08 required support distance)
- rail-ramp provides support distance of 9. Since rail-ramp is a rail itself, this value is measured from the upper rail connection point. Visually you may see the rail support baked into rail ramp graphics, its center is 2 tiles away from the elevated connection point, so that means when counting support distance from visible baked in support center, it would be 11 tiles support distance (2 is immediately consumed by the rail ramp, only 9 distance is remaining)
- rail-support provides support distance of 11 measuring from the rail support center.
Now that all the numbers are given, the mechanic as i implemented it for elevated rails is following:
A rail is considered supported when traveling from either of its ends (without reversing at junction points) a support is found within a distance so that "my required support distance"(aka "my length") + "support distance of rails between the support position" is lower that the support provided. That can be more easily read as: "there exists a support for which my entire length is within support distance".