From ad0713547c45930254473d8dc2b198b0587183d2 Mon Sep 17 00:00:00 2001 From: ywang Date: Sat, 7 Dec 2019 16:48:19 +0100 Subject: Improved quadratic function solver; added wrapper for math.sqrt() --- advtrains/lzb.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'advtrains/lzb.lua') 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 -- cgit v1.2.3