aboutsummaryrefslogtreecommitdiff
path: root/advtrains/lzb.lua
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2019-12-07 16:48:19 +0100
committerywang <yw05@forksworld.de>2020-04-12 16:07:16 +0200
commitad0713547c45930254473d8dc2b198b0587183d2 (patch)
treebfa91c2b303542a814e92ff32bd28cc65b0b217f /advtrains/lzb.lua
parenta86677b42fc37c59c9297baa567a7e1d68660d4f (diff)
downloadadvtrains-ad0713547c45930254473d8dc2b198b0587183d2.tar.gz
advtrains-ad0713547c45930254473d8dc2b198b0587183d2.tar.bz2
advtrains-ad0713547c45930254473d8dc2b198b0587183d2.zip
Improved quadratic function solver; added wrapper for math.sqrt()
Diffstat (limited to 'advtrains/lzb.lua')
-rw-r--r--advtrains/lzb.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua
index 3961438..30d7972 100644
--- a/advtrains/lzb.lua
+++ b/advtrains/lzb.lua
@@ -94,7 +94,7 @@ LZB point itself, and not related to the emergency brake.
]]
function advtrains.lzb_map_entry(train, lzb)
local ret = {[0]={},[1]={},[2]={},[3]={}}
- if (not train) or (not lzb) then return ret end
+ if not (train and lzb) then return ret end
local ti = train.index
local v0 = train.velocity
local v1 = lzb.spd
@@ -168,7 +168,7 @@ function advtrains.lzb_get_limit_by_entry(train, lzb)
local s = train.index - lzbmap[ret.lever].i
local a = advtrains.get_acceleration(train, ret.lever)
local v0 = lzbmap[ret.lever].v
- ret.velocity = math.sqrt(2*a*s - v0*v0)
+ ret.velocity = math.abs(advtrains.safesqrt(2*a*s - v0*v0))
end
if ret.velocity < train.velocity -1 then ret.lever = ret.lever - 1 end
return ret