Module:Coordinates: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary |
(move validation functions) |
||
Line 56: | Line 56: | ||
coordinateSpec.default = "dec" |
coordinateSpec.default = "dec" |
||
end |
end |
||
errors = validate( lat, nil, nil, long, nil, nil, 'parseDec' ); |
|||
-- TODO refactor the validations into separate functions |
|||
if (tonumber(lat) or 0) > 90 then |
|||
table.insert(errors, {"parseDec","latd>90"}) |
|||
end |
|||
if (tonumber(lat) or 0) < -90 then |
|||
table.insert(errors, {"parseDec", "latd<-90"}) |
|||
end |
|||
if (tonumber(long) or 0) >= 360 then |
|||
table.insert(errors, {"parseDec", "longd>=360"}) |
|||
end |
|||
if (tonumber(long) or 0) <= -360 then |
|||
table.insert(errors, {"parseDec", "longd<=-360"}) |
|||
end |
|||
return coordinateSpec, errors |
return coordinateSpec, errors |
||
end |
end |
||
Line 102: | Line 89: | ||
coordinateSpec.default = "dms" |
coordinateSpec.default = "dms" |
||
end |
end |
||
--[[ |
|||
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS' ); |
|||
-- Error reporting |
|||
if isEmpty( |
if isEmpty(long_d) then |
||
table.insert(errors, {" |
table.insert(errors, {"parseDMS", "Missing longitude" }) |
||
end |
end |
||
if not isEmpty(args[10]) then |
|||
table.insert(errors, {"parseDM", "Unexpected extra parameters"}) |
|||
end |
|||
if (tonumber(args[1]) or 0) > 90 then |
|||
table.insert(errors, {"parseDMS", "latd>90"}) |
|||
end |
|||
if (tonumber(args[1]) or 0) < -90 then |
|||
table.insert(errors, {"parseDMS", "latd<-90"}) |
|||
end |
|||
if (tonumber(args[2]) or 0) >= 60 then |
|||
table.insert(errors, {"parseDMS", "latm>=60"}) |
|||
end |
|||
if (tonumber(args[2]) or 0) < 0 then |
|||
table.insert(errors, {"parseDMS", "latm<0"}) |
|||
end |
|||
if (tonumber(args[3]) or 0) >= 60 then |
|||
table.insert(errors, {"parseDMS", "lats>=60"}) |
|||
end |
|||
if (tonumber(args[3]) or 0) < 0 then |
|||
table.insert(errors, {"parseDMS", "lats<0"}) |
|||
end |
|||
if (tonumber(args[5]) or 0) >= 360 then |
|||
table.insert(errors, {"parseDMS", "longd>=360"}) |
|||
end |
|||
if (tonumber(args[5]) or 0) <= -360 then |
|||
table.insert(errors, {"parseDMS", "longd<=-360"}) |
|||
end |
|||
if (tonumber(args[6]) or 0) >= 60 then |
|||
table.insert(errors, {"parseDMS", "longm>=60"}) |
|||
end |
|||
if (tonumber(args[6]) or 0) < 0 then |
|||
table.insert(errors, {"parseDMS", "longm<0"}) |
|||
end |
|||
if (tonumber(args[7]) or 0) >= 60 then |
|||
table.insert(errors, {"parseDMS", "longs>=60"}) |
|||
end |
|||
if (tonumber(args[7]) or 0) < 0 then |
|||
table.insert(errors, {"parseDMS", "longs<0"}) |
|||
end |
|||
]] |
|||
return coordinateSpec, errors |
return coordinateSpec, errors |
||
end |
end |
||
Line 352: | Line 298: | ||
end |
end |
||
function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source ) |
|||
--- TODO not yet in use |
|||
local errors = {}; |
|||
function validateDegreesLatitude(degrees) |
|||
if 0+tonumber(degrees) > 90 then |
|||
if (tonumber(lat_d) or 0) > 90 then |
|||
table.insert(errors, {source, "latd>90"}) |
|||
end |
end |
||
if |
if (tonumber(lat_d) or 0) < -90 then |
||
table.insert(errors, {source, "latd<-90"}) |
|||
end |
end |
||
if (tonumber(lat_m) or 0) >= 60 then |
|||
return true |
|||
table.insert(errors, {source, "latm>=60"}) |
|||
end |
|||
--- TODO not yet in use |
|||
function validateDegreesLongtitude(degrees) |
|||
if 0+tonumber(degrees) >= 360 then |
|||
return "longd>=360" |
|||
end |
end |
||
if |
if (tonumber(lat_m) or 0) < 0 then |
||
table.insert(errors, {source, "latm<0"}) |
|||
end |
end |
||
if (tonumber(lat_s) or 0) >= 60 then |
|||
return true |
|||
table.insert(errors, {source, "lats>=60"}) |
|||
end |
|||
--- TODO not yet in use |
|||
function validateMinutes(minutes) |
|||
if 0+tonumber(minutes) >= 60 then |
|||
return "m>=60" |
|||
end |
end |
||
if |
if (tonumber(lat_s) or 0) < 0 then |
||
table.insert(errors, {source, "lats<0"}) |
|||
end |
end |
||
if (tonumber(long_d) or 0) >= 360 then |
|||
return true |
|||
table.insert(errors, {source, "longd>=360"}) |
|||
end |
|||
--- TODO not yet in use |
|||
function validateSeconds(seconds) |
|||
if 0+tonumber(seconds) >= 60 then |
|||
return "s>=60" |
|||
end |
end |
||
if |
if (tonumber(long_d) or 0) <= -360 then |
||
table.insert(errors, {source, "longd<=-360"}) |
|||
end |
end |
||
if (tonumber(long_m) or 0) >= 60 then |
|||
return true |
|||
table.insert(errors, {source, "longm>=60"}) |
|||
end |
|||
if (tonumber(long_m) or 0) < 0 then |
|||
table.insert(errors, {source, "longm<0"}) |
|||
end |
|||
if (tonumber(long_s) or 0) >= 60 then |
|||
table.insert(errors, {source, "longs>=60"}) |
|||
end |
|||
if (tonumber(long_s) or 0) < 0 then |
|||
table.insert(errors, {source, "longs<0"}) |
|||
end |
|||
return errors; |
|||
end |
end |
||
--- The display function we exposed to Module:Coordinates |
--- The display function we exposed to Module:Coordinates |