Skip to content

Commit 06a5735

Browse files
committed
Add input checking for angles.
1 parent f0c670c commit 06a5735

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Source/Orts.Parsers.Msts/STFReader.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,12 @@ public enum UNITS
809809
/// </summary>
810810
Temperature = 1 << 27, // "Temperature", note above TemperatureDifference, is different
811811

812+
/// <summary>
813+
/// Valid Units: deg, rad
814+
/// <para>Scaled to Radians</para>
815+
/// </summary>
816+
Angle = 1 << 28, // "Temperature", note above TemperatureDifference, is different
817+
812818
// "Any" is used where units cannot easily be specified, such as generic routines for interpolating continuous data from point values.
813819
// or interpreting locomotive cab attributes from the ORTSExtendedCVF experimental mechanism.
814820
// "Any" should not be used where the dimensions of a unit are predictable.
@@ -1128,6 +1134,13 @@ internal double ParseUnitSuffix(ref string constant, UNITS validUnits)
11281134
return 1;
11291135
}
11301136
}
1137+
if ((validUnits & UNITS.Angle) > 0)
1138+
switch (suffix)
1139+
{
1140+
case "": return 1.0;
1141+
case "rad": return 1;
1142+
case "deg": return 0.0174533; // 1 deg = 0.0174533 radians
1143+
}
11311144
STFException.TraceWarning(this, "Found a suffix '" + suffix + "' which could not be parsed as a " + validUnits.ToString() + " unit");
11321145
return 1;
11331146
}

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
10381038
case "wagon(ortshorizontallengthairhose": CarAirHoseHorizontalLengthM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
10391039
case "wagon(ortslengthcouplerface": CarCouplerFaceLengthM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
10401040
case "wagon(ortswheelflangelength": WheelFlangeLengthM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
1041-
case "wagon(ortsmaximumwheelflangeangle": MaximumWheelFlangeAngleRad = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
1041+
case "wagon(ortsmaximumwheelflangeangle": MaximumWheelFlangeAngleRad = stf.ReadFloatBlock(STFReader.UNITS.Angle, null); break;
10421042
case "wagon(ortstrackgauge":
10431043
stf.MustMatch("(");
10441044
TrackGaugeM = stf.ReadFloat(STFReader.UNITS.Distance, null);

0 commit comments

Comments
 (0)