I agree that tracks should be as straight as possible, but my point is all about consistency. Why should a sequence of two 45 degree bends have very different radius just because once it is self correcting, and other times they form a 90 degree turn. Look at this screenshot:

.

Why should a train running from south to north be significantly faster than train going from south to east ? (think of assumed_45_radius set to 1 for now). The train making 90 degree turn has in fact one tile longer distance between the two 45 degree bends than the train taking the pair of self correcting turns?

If your (blue line) approach to the 90 degree turns is taken absolutely, then the sharpest 90 degree turn should have a radius of 1/2 tile - the same as 180 degree turn. Also if you look at the 90.png diagram you will see that the green line is entirely on the same tiles as the black line of track, while the blue line crosses two extra tiles. Overall the green line is much closer to the track than blue line.

If the tile between -8 and -10 would be a part of another bend, then of course the speed of the train would be limited by that shorter bend which would be a pair of 45 bends with one straight tile in between. Wouldn't it?

I have played a lot and checked the speeds to see if they are as expected. Here is a test save game (pak128.britain-ex) which I will comment further.

http://server.exp.simutrans.com/debug-saves/cornering-test.sveI have put a HST train to run non stop from Trnava to Selpice. When you load it it should approaching station Selpice. HST is fast enough to be limited by the curves on the track. However I found a few discrepancies.

**bug #1** - steps_to_X should be reduced by one before any further calculations (for diagonal tracks), or the algorithm to count steps should be revised (according to bug#2)

If you watch the train from selpice it accelerates to full speed given by track (160 km/h). It starts to slow down at nemcanka (signalbox), as there is a 90 degree bend, just exactly the same as on the above diagram. It has 5 diagonal tiles, so the expected radius would be 5*125/2 = 312.5 m. And the speed = sqrt (312*87/10) = 52 km/h. Yet the train slows down to 57 km/h, (at 74,83) which gives steps_to_90 = 6. The same then applies to similar bends at (59,52) - 31 tiles, speed 131km/h is for 32 steps, and (25,49) - 11 tiles, speed 80 km/h should be for 12 steps. So the calculation of steps_to_90 returns the result greater by one than it should.

Also short pairs of self correcting 45 degree bends are off by one. This can be seen on the milk train approaching nemcanka - it will move to the third track at (92,87), slowing down to 73, as if the diagonal section had 5 tiles, but it has only 4. And again when approaching the dairy it takes the tightest pair of 45 degree bends - 2 tiles, at speed 57 km/h which should be for steps_to_45=3.

**bug#2** radius should not be calculated from manhattan distance, but real (euclidean) distance.

Very interesting is the stretch of track of 6 E-W tiles at (30,44). The train slows down to 61 km/h (7 steps_to_90). Lets assume that the off by one bug from above applies, so it would be calculated with 6 steps_to_90. Then the radius is 3 tiles, which is completely wrong. See the screenshot - blue line. I think that for this kind of 90 degree turns, and using you original approach, the radius should not be steps/2 but steps*sqrt(2)/2 (red curve):

To be consistent for curves with middle part either diagonal or orthogonal to tiles, one has to use euclidean distance in the calculation, not manhattan. For your approach to 90 degree curves it should be radius=dist*sqrt(2)/2, or for my (more gentle) approach it would be radius=dist*(sqrt(2)/2+1/2). Euclidean dist for diagonal tracks is steps*sqrt(2)/2 so we get back yours radius=steps*sqrt(2)/2*sqrt(2)/2=steps/2, or mine radius=steps*sqrt(2)/2*(sqrt(2)/2+1/2)=steps/2*(1+sqrt(2)/2)=steps/2*(1+sin(45)). The same applies to pairs of 45 degree bends.

**bug #3**The behavior on the way back is somewhat inconsistent. There are two stretches of 15 tiles (those with crossings - one at new cemetery, other at trnava predmestie stop), that form a pair of self-correcting 45 degree turns. On the way to trnava, the HST slows down to 131 km/h at the end of both. But on the way back, it drives at 133 km/h (at 58,52)

**bug#4**the HST when leaving Nemcanka station has to pass a tight pair of self correcting 45 degree bends (at 93,86). I have set the assumed radius to 100 to avoid its effects. While it worked well on the milk train passing this turn at 57 km/h, the HST train passes it at 93 km/h. As if it applied a speed limit of 16 tiles long 90 degree bend - and indeed there is such - the station is 16 tiles long. But the following short bend is ignored.

So If I may suggest to change the handling of corners to the following:

a) if there is a 90 degree hairpin turn (i.e. 180 or 135, e.g. at 22,127) - set the radius to 1/2 tile, without any more calculations.

b) if there is a pair of 45 degree turns (whether forming a 90 degree turn or self correcting S-turn), calculate the radius as radius=dist*(sqrt(2)/2+1/2)=dist*1.207, where dist is euclidean distance

Now I realized that the current algorithm is producing the red curve from 90.png, which may be intentional, but is still one step longer for 45.png