@@ -90,7 +90,7 @@ public SuperElevation(Simulator simulator)
9090 }
9191 else if ( curveDir != Math . Sign ( sec . SectionCurve . Angle ) ) // we are in curve, but bending different dir
9292 {
93- MarkSections ( simulator , sectionList , curveLen , sectionLengths ) ; // treat the sections encountered so far, then restart with other dir
93+ MarkSections ( simulator , sectionList , curveLen , sectionLengths , curveDir ) ; // treat the sections encountered so far, then restart with other dir
9494 curveDir = Math . Sign ( sec . SectionCurve . Angle ) ;
9595 sectionList . Clear ( ) ;
9696 sectionLengths . Clear ( ) ;
@@ -104,7 +104,7 @@ public SuperElevation(Simulator simulator)
104104 {
105105 if ( startCurve == true ) // we are in a curve, need to finish
106106 {
107- MarkSections ( simulator , sectionList , curveLen , sectionLengths ) ;
107+ MarkSections ( simulator , sectionList , curveLen , sectionLengths , curveDir ) ;
108108 curveLen = 0f ;
109109 sectionList . Clear ( ) ;
110110 sectionLengths . Clear ( ) ;
@@ -126,16 +126,23 @@ public SuperElevation(Simulator simulator)
126126 }
127127 if ( startCurve == true ) // we are in a curve after looking at every section
128128 {
129- MarkSections ( simulator , sectionList , curveLen , sectionLengths ) ;
129+ MarkSections ( simulator , sectionList , curveLen , sectionLengths , curveDir ) ;
130130 }
131131 sectionList . Clear ( ) ;
132132 }
133133 }
134134
135- void MarkSections ( Simulator simulator , List < TrVectorSection > SectionList , float totLen , List < float > lengths )
135+ void MarkSections ( Simulator simulator , List < TrVectorSection > SectionList , float totLen , List < float > lengths , int direction )
136136 {
137- if ( totLen < simulator . SuperElevationMinLen || SectionList . Count == 0 )
138- return ; // Ignore curves too short or invalid data
137+ if ( SectionList . Count <= 0 )
138+ return ; // Avoid errors with invalid section lists
139+ else if ( totLen < simulator . SuperElevationMinLen )
140+ {
141+ // Zero out any curves that are too short
142+ foreach ( TrVectorSection s in SectionList )
143+ s . NomElevM = 0 ;
144+ return ;
145+ }
139146
140147 // The superelevation standard we will use. null means no superelevation
141148 SuperElevationStandard standard = null ;
@@ -218,9 +225,8 @@ void MarkSections(Simulator simulator, List<TrVectorSection> SectionList, float
218225 }
219226 else // No superelevation needed (shouldn't reach this point, this is a failsafe)
220227 superElevation = 0.0f ;
221-
222- SectionList [ i ] . NomElevM = superElevation ;
223228 }
229+ SectionList [ i ] . NomElevM = superElevation ;
224230 }
225231 }
226232 }
@@ -325,6 +331,9 @@ void MarkSections(Simulator simulator, List<TrVectorSection> SectionList, float
325331 // Visual superelevation is stored in terms of angle in radians rather than meters
326332 float [ ] angles = elevations . Select ( e => ( float ) Math . Asin ( e / simulator . SuperElevationGauge ) ) . ToArray ( ) ;
327333 SectionList [ count ] . VisElevTable = new Interpolator ( SectionList [ count ] . PhysElevTable . X , angles ) ;
334+ // Invert visual elevation values based on curve direction
335+ // direction is negated for consistency of direction sense in other places
336+ SectionList [ count ] . VisElevTable . ScaleY ( - direction ) ;
328337
329338 accumulatedLength += lengths [ count ] ;
330339 count ++ ;
0 commit comments