luasrc/usr/lib/lua/hoodselector/util.lua: check_site.lua simplify checksite script and fix if logic

Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
This commit is contained in:
Jan-Tarek Butt 2019-05-26 19:47:04 +02:00
parent fd65fa20ce
commit d68ca9e900

View File

@ -1,15 +1,26 @@
--Need to check if not default domain and does the default not contain shapes
if this_domain() ~= need_string(in_site({'default_domain'})) then
for _,shape in ipairs(need_table(in_domain({'hoodselector', 'shapes'}))) do
need({'hoodselector', 'shapes'}, function(err)
if #shape >= 2 then
for _, pos in ipairs(shape) do
need({'hoodselector', 'shapes'}, function(err) return pos.lat == nil or not ( pos.lat < 90.0 and pos.lat > -90.0 ) end, false, "lat must match a range +/-90.0")
need({'hoodselector', 'shapes'}, function(err) return pos.lon == nil or not ( pos.lon < 180.0 and pos.lon > -180.0 ) end, false, "lon must match a range +/-180.0")
end
return true
end
function check_lat_lon_range(pos,range,label)
need({'hoodselector', 'shapes'}, function(err)
if (type(pos) ~= "number") then
return false
end
if pos > range or pos < -range then
return false
end
return true
end, true, label.." must match a range +/-"..range)
end
if this_domain() ~= need_string(in_site({'default_domain'})) then
for _,shape in pairs(need_table(in_domain({'hoodselector', 'shapes'}))) do
need({'hoodselector', 'shapes'}, function(err)
if #shape < 2 then
return false
end
for k,v in ipairs(shape) do
check_lat_lon_range(v.lat,90.0,"lat")
check_lat_lon_range(v.lon,180.0,"lon")
end
return true
end, true, "needs to have at least 2 coordinates for rectangular shapes.")
end
end