This commit is contained in:
Andrej730
2025-02-24 11:47:19 +05:00
parent 3854afb34d
commit 0783f8082e
8 changed files with 153 additions and 119 deletions
@@ -18,7 +18,8 @@
import math
def station_as_string(station:float,plus_seperator=3,accuracy=3):
def station_as_string(station: float, plus_seperator=3, accuracy=3):
"""
Returns a stringized version of a station. Example 100.0 is 1+00.00 as a stationing string
@param station: the station to be stringized
@@ -27,25 +28,23 @@ def station_as_string(station:float,plus_seperator=3,accuracy=3):
"""
value = math.fabs(station)
shifter = math.pow(10.0,plus_seperator)
v1 = math.floor(value/shifter)
v2 = value - v1*shifter
shifter = math.pow(10.0, plus_seperator)
v1 = math.floor(value / shifter)
v2 = value - v1 * shifter
# Check to make sure that v2 is not basically the same as shifter
# If station = 69500.00000, we sometimes get 694+100.00 instead of 695+00.00
if math.isclose(v2-shifter,5.0*math.pow(10.0,-(accuracy+1))):
if math.isclose(v2 - shifter, 5.0 * math.pow(10.0, -(accuracy + 1))):
v2 = 0.0
v1 += 1
v1 = -1*v1 if station < 0 else v1
v1 = -1 * v1 if station < 0 else v1
station_string = "{:d}+{:0{}.{}f}".format(v1,v2,plus_seperator+accuracy+1,accuracy)
station_string = "{:d}+{:0{}.{}f}".format(v1, v2, plus_seperator + accuracy + 1, accuracy)
# special case when v1 is 0 and station is negative, the string above doesn't get the leading
# special case when v1 is 0 and station is negative, the string above doesn't get the leading
# negative sign. this snippet fixes that
if v1 == 0 and station < 0:
station_string = "-" + station_string
return station_string