@@ -122,44 +122,73 @@ public static ushort ToKmphPrecise(float speed) {
122122 return ( ushort ) Mathf . Round ( speed * SPEED_TO_KMPH ) ;
123123 }
124124
125- /// <summary>
126- /// Based on the MPH/KMPH settings round the current speed to the nearest STEP and
127- /// then decrease by STEP.
128- /// </summary>
129- /// <param name="speed">Ingame speed</param>
130- /// <returns>Ingame speed decreased by the increment for MPH or KMPH</returns>
131- public static float GetPrevious ( float speed ) {
132- if ( speed < 0f ) {
133- return - 1f ;
134- }
135- if ( GlobalConfig . Instance . Main . DisplaySpeedLimitsMph ) {
136- var rounded = ToMphRounded ( speed ) ;
137- return ( rounded > LOWER_MPH ? rounded - MPH_STEP : LOWER_MPH ) / SPEED_TO_MPH ;
138- } else {
139- var rounded = ToKmphRounded ( speed ) ;
140- return ( rounded > LOWER_KMPH ? rounded - KMPH_STEP : LOWER_KMPH ) / SPEED_TO_KMPH ;
141- }
142- }
143-
144- /// <summary>
145- /// Based on the MPH/KMPH settings round the current speed to the nearest STEP and
146- /// then increase by STEP.
147- /// </summary>
148- /// <param name="speed">Ingame speed</param>
149- /// <returns>Ingame speed increased by the increment for MPH or KMPH</returns>
150- public static float GetNext ( float speed ) {
151- if ( speed < 0f ) {
152- return - 1f ;
153- }
154- if ( GlobalConfig . Instance . Main . DisplaySpeedLimitsMph ) {
155- var rounded = ToMphRounded ( speed ) ;
156- return ( rounded < UPPER_MPH ? rounded + MPH_STEP : UPPER_MPH ) / SPEED_TO_MPH ;
157- }
158- else {
159- var rounded = ToKmphRounded ( speed ) ;
160- return ( rounded < UPPER_KMPH ? rounded + KMPH_STEP : UPPER_KMPH ) / SPEED_TO_KMPH ;
161- }
162- }
125+ /// <summary>
126+ /// Based on the MPH/KMPH settings round the current speed to the nearest STEP and
127+ /// then decrease by STEP.
128+ /// </summary>
129+ /// <param name="speed">Ingame speed</param>
130+ /// <returns>Ingame speed decreased by the increment for MPH or KMPH</returns>
131+ public static float GetPrevious ( float speed ) {
132+ if ( speed < 0f ) {
133+ return - 1f ;
134+ }
135+
136+ if ( GlobalConfig . Instance . Main . DisplaySpeedLimitsMph ) {
137+ ushort rounded = ToMphRounded ( speed ) ;
138+ if ( rounded == LOWER_MPH ) {
139+ return 0 ;
140+ }
141+
142+ if ( rounded == 0 ) {
143+ return UPPER_MPH / SPEED_TO_MPH ;
144+ }
145+
146+ return ( rounded > LOWER_MPH ? rounded - MPH_STEP : LOWER_MPH ) / SPEED_TO_MPH ;
147+ } else {
148+ ushort rounded = ToKmphRounded ( speed ) ;
149+ if ( rounded == LOWER_KMPH ) {
150+ return 0 ;
151+ }
152+
153+ if ( rounded == 0 ) {
154+ return UPPER_KMPH / SPEED_TO_KMPH ;
155+ }
156+
157+ return ( rounded > LOWER_KMPH ? rounded - KMPH_STEP : LOWER_KMPH ) / SPEED_TO_KMPH ;
158+ }
159+ }
160+
161+ /// <summary>
162+ /// Based on the MPH/KMPH settings round the current speed to the nearest STEP and
163+ /// then increase by STEP.
164+ /// </summary>
165+ /// <param name="speed">Ingame speed</param>
166+ /// <returns>Ingame speed increased by the increment for MPH or KMPH</returns>
167+ public static float GetNext ( float speed ) {
168+ if ( speed < 0f ) {
169+ return - 1f ;
170+ }
171+
172+ if ( GlobalConfig . Instance . Main . DisplaySpeedLimitsMph ) {
173+ ushort rounded = ToMphRounded ( speed ) ;
174+ rounded += MPH_STEP ;
175+
176+ if ( rounded > UPPER_MPH ) {
177+ rounded = 0 ;
178+ }
179+
180+ return rounded / SPEED_TO_MPH ;
181+ } else {
182+ ushort rounded = ToKmphRounded ( speed ) ;
183+ rounded += KMPH_STEP ;
184+
185+ if ( rounded > UPPER_KMPH ) {
186+ rounded = 0 ;
187+ }
188+
189+ return rounded / SPEED_TO_KMPH ;
190+ }
191+ }
163192
164193 /// <summary>
165194 /// For US signs and MPH enabled, scale textures vertically by 1.25f.
0 commit comments