Modulo:Coord: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nuova sandbox
aggiornata DecCoord:toDms come da discussione
Riga 230:
 
-- Ritorna un nuovo oggetto DmsCoord, convertendo in gradi/minuti/secondi
function DecCoord:toDms(dmsFormat)
local dec, deg, min, sec
 
if dmsFormatdec == "d" thenself.deg
deg = roundmath.floor(self.deg, 0dec)
dec = (dec sec =- deg) %* 60
elseif dmsFormat == "dm" then
degmin = roundmath.floor(self.deg * 60, 0dec)
dec = (dec - min) = deg %* 60
degsec = math.floorround((deg - min) /dec, 602)
elseif dmsFormat == "dms" then
deg = round(self.deg * 3600, 0)
sec = deg % 60
deg = math.floor((deg - sec) / 60)
min = deg % 60
deg = math.floor((deg - min) / 60) % 360
end
 
return DmsCoord:new(deg, min, sec, self.card)
Riga 291 ⟶ 284:
-- Coord
-------------------------------------------------------------------------------
 
-- Usato nelle conversioni da gradi decimali a gradi/minuti/secondi,
-- dato il numero di decimali maggiore tra latdec e longdec ritorna il formato adatto:
-- "d" per 0 decimali
-- "dm" per 1-2 decimali
-- "dms" per >= 3 decimali
local function getDmsFormat(latdec, longdec)
local d1, d2, max
d1 = getDecimalPlaces(latdec)
d2 = getDecimalPlaces(longdec)
max = d1 > d2 and d1 or d2
 
return max == 0 and "d" or
((max == 1 or max == 2) and "dm" or "dms")
end
 
-- Crea l'HTML ritornato da Coord
Riga 380 ⟶ 357:
local function coord()
local decLat, degLong, dmsLat, dmsLong
local reqFormat, dmsFormat, defaultFormat, geohackParams, ret
 
-- parsifica i parametri
Riga 408 ⟶ 385:
-- conversioni dec <=> dms
if reqFormat == "dec" or reqFormat == "d" then
dmsFormatdmsLat = getDmsFormatdecLat:toDms(decLat.deg, decLong.deg)
dmsLatdmsLong = decLatdecLong:toDms(dmsFormat)
dmsLong = decLong:toDms(dmsFormat)
elseif reqFormat == "dm" or reqFormat == "dms" then
decLat = dmsLat:toDec()
decLong = dmsLong:toDec()
end
 
Riga 420 ⟶ 396:
elseif reqFormat == "dec" then
defaultFormat = "dec"
elseif reqFormat == "d" then
defaultFormat = (dmsFormat == "d" and "dms" or "dec")
else
defaultFormat = "dms"