Modulo:Coord: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
fix classe span
semplifico controlli sul segno e fix buildHtml
Riga 158:
 
-- Costruttore di DecCoord
-- Se deg è negativo viene cambiato di segno e la direzione cardinale invertita
function DecCoord:new(deg, card)
local self = {}
Riga 163 ⟶ 164:
 
self.deg = tonumber(deg)
if self.carddeg < =0 cardthen
self.displaycard = (self.degcard >== 0"N" and self.deg"S" or -self.deg)(card ..== "°E" ..and "W" or self.card)
if self.deg <= 0 then-self.deg
endelse
card = self.card = card
end
self.degdisplay = self.deg >=.. 0"°" and self.deg. or -self.degcard
 
return self
end
 
-- Ritorna un nuovo oggetto DmsCoord, convertendo in gradi/minuti/secondi.
function DecCoord:toDms(dmsFormat)
local deg, min, sec, card
 
card = self.card
if self.deg < 0 then
card = card == "N" and "S" or (card == "E" and "W" or card)
end
self.deg = self.deg >= 0 and self.deg or -self.deg
 
if dmsFormat == "d" then
Riga 193:
end
 
return DmsCoord:new(deg, min, sec, self.card)
end
 
-- Ritorna i gradi con segno
function DecCoord:getDeg()
return self.deg * card = ((self.card == "N" and "S" or (self.card == "E") and "W"1 or card-1)
end
 
Riga 217 ⟶ 222:
local sign, roundval, deg
sign = (self.card == "N" or self.card == "E") and 1 or -1
roundval = (self.sec and 5 or (self.min and 3 or 0)) + getDecimalPlaces(self.sec or self.min or self.deg)
deg = sign * round((self.deg + ((self.min or 0) + (self.sec or 0) / 60) / 60), roundval)
return DecCoord:new(deg, self.card)
Riga 291 ⟶ 295:
.tag("span")
.addClass("geo")
.wikitext(decLat.deg:getDeg() .. "; " .. decLong.deg:getDeg())
.done()
.done()
Riga 322 ⟶ 326:
if reqFormat == "dec" then
-- {{coord|43.6500|-79.3800}}
decLat = DecCoord:new(args[1], tonumber(args[1]) >= 0 and "N" or "S")
decLong = DecCoord:new(args[2], tonumber(args[2]) >= 0 and "E" or "W")
elseif reqFormat == "d" then
-- {{coord|43.651234|N|79.383333|W}}
Riga 376 ⟶ 380:
 
-- {{dms2dec|N|10|20|35}}
return DmsCoord:new(tonumber(args[2]), tonumber(args[3]), tonumber(args[4]), args[1]):toDec().deg:getDeg()
end