Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a21ddfb20883efe9

Jump to content

Module:IAU star location map

From Wikipedia, the free encyclopedia

--[[
* IAU Star Positioning Map Pattern Implementation Module.
*
* Imported from https://it.wikipedia.org/w/index.php?title=Modulo:Mappa_di_localizzazione_IAU&oldid=84979493
]]--

require('strict')

local getArgs = require('Module:Arguments').getArgs
local mRaDec = require('Module:RADec')
local cfg = mw.loadData('Module:IAU star location map/Configuration')
local errorCategory = '[[Category:Pages with errors in module IAU star location map]]'
local p = {}

local function errhandler(msg)
	local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
	return string.format('<span class="error">%s</span>%s', msg, cat)
end

local function _latinise_letters(tmparg)
            --2>--remove case
            tmparg=mw.ustring.lower(tmparg);
            --2>--remove acccent
            tmparg=mw.ustring.gsub(tmparg, "[áàâäãå]", "a");
            tmparg=mw.ustring.gsub(tmparg, "[æ]", "ae");
            tmparg=mw.ustring.gsub(tmparg, "[ç]", "c");
            tmparg=mw.ustring.gsub(tmparg, "[éèêë]", "e");
            tmparg=mw.ustring.gsub(tmparg, "[íìîï]", "i");
            tmparg=mw.ustring.gsub(tmparg, "[ñ]", "n");
            tmparg=mw.ustring.gsub(tmparg, "[óòôöõ]", "o");
            tmparg=mw.ustring.gsub(tmparg, "[œ]", "oe");
            tmparg=mw.ustring.gsub(tmparg, "[úùûü]", "u");
            tmparg=mw.ustring.gsub(tmparg, "[ýÿ]", "y");

            return tmparg;
end

-- http://lua-users.org/wiki/SimpleRound
local function round(num, idp)
	local mult = 10 ^ (idp or 0)
	return math.floor(num * mult + 0.5) / mult
end

-- Converts declination from degrees/minutes/seconds to decimal degrees
local function dec2deg(dec)
	local sign = dec.d >= 0 and not(dec.signe == '-') and 1 or -1
	return dec.d + sign * dec.m / 60 + sign * dec.s / 3600
end

-- Converts right ascension from hours/minutes/seconds to decimal degrees
local function ar2deg(ar)
	return ar.h * 15 + ar.m / 4 + ar.s / 240
end

-- Parse the right ascension parameter with the format "hours/minutes/seconds"
local function parseArSlash(args)
	local h, m, s = string.match(args.ra, '^([%d]+)/(%d+)/([%d,%.]+)$')
	h, m, s = tonumber(h), tonumber(m), tonumber(s)
	return (h and m and s) and ar2deg({ h = h, m = m, s = s }) or nil
end

-- Parse the declination parameter with the format "degrees/minutes/seconds"
local function parseDecSlash(args)
	local d, signe, m, s = string.match(args.dec, '^+?((-?)%d+)/(%d+)/([%d,%.]+)$')
	d, m, s = tonumber(d), tonumber(m), tonumber(s)
	return (d and m and s) and dec2deg({ d = d, m = m, s = s, signe = signe }) or nil
end

-- The functions getX and getY were obtained from Ysogo's formulas in
-- Project Discussions: Astronomy#Constellation Map Position:
-- X = Ax+(Aw/2)+(Ah/(DECsup-DECinf))*(DECogg-DECaxe)*sin((ARmed-ARogg)/disang)
-- Y = Ay+Ah-(Ah/(DECsup-DECinf))*((DECogg-DECaxe)*cos((ARmed-ARogg)/disang)-(DECinf-DECaxe))
local function getX(map, ar, dec, width, marksize)
	local x = map.ax + map.aw / 2 +
			  (map.ah / (map.dec_sup - map.dec_inf)) *
			  (dec - map.dec_axe) *
			  math.sin(((map.ar_med - ar) / map.dis_ang) * (math.pi / 180))
	-- scale the result based on width and center the marker
	return round(x * width / map.iw - marksize / 2)
end

local function getY(map, ar, dec, width, marksize)
	local y = map.ay + map.ah -
			  (map.ah / (map.dec_sup - map.dec_inf)) *
			  ((dec - map.dec_axe) * math.cos(((map.ar_med - ar) / map.dis_ang) * (math.pi / 180)) - (map.dec_inf - map.dec_axe) )
	-- scale the result based on width and center the marker
	return round(y * width / map.iw - marksize / 2)
end

local function getThumbnail(text, image, args, width)
	local divNode = mw.html.create('div')
	divNode
		:addClass('thumb')
		:addClass(args.float == 'right' and 'floatright' or 'floatleft')
		:tag('div')
			:addClass('thumbinner')
			:css('width', width .. 'px')
			:wikitext(text)
			:tag('div')
				:addClass('thumbcaption')
				:wikitext(args.caption or '')
				:tag('div')
					:addClass('magnify')
					:wikitext(string.format('[[:File:%s]]', image))
	return tostring(divNode)
end

-- Returns the list of configured map codes
function p.maps()
	local sortedMaps = {}
	for key, _ in pairs(cfg.mappe) do
		table.insert(sortedMaps, key)
	end
	table.sort(sortedMaps)
	return mw.text.listToText(sortedMaps)
end

-- Returns 1 if the specified map is available, otherwise nil.
function p.hasmap(frame)
	local map = frame.args[1] and mw.ustring.lower(frame.args[1])
	return (cfg.alias[map] or cfg.mappe[map]) and 1
end

-- For use from another module
function p._main(args)
	local map, ar, dec, text
	local width = tonumber(args.width) or 260
	local marksize = tonumber(args.marksize) or 15
	
	-- gets the maps
	if args.map then
		args.map = _latinise_letters(args.map)
	else
		error('Map not specified', 2)
	end
	-- possibly others
	args.map = cfg.alias[args.map] or args.map
	if not cfg.mappe[args.map] then
		error('Invalid map' .. args.map, 2)
	end
	map = cfg.mappe[args.map]
	
	-- gets right ascension and declination
	if args.ra and args.dec then
		ar = mRaDec.parseRA(args.ra)
		dec = mRaDec.parseDEC(args.dec)
		if ar and dec then
			ar = ar2deg(ar)
			dec = dec2deg(dec)
		end
	end
	if not ar or not dec then
		error('Invalid celestial coordinates', 2)
	end

	-- double maps
	if args.map == 'ser' then
		map = ar > 255 and map.cauda or map.caput
	end
	-- for constellations that cross the prime meridian
	if map.ar_med > ar + 180 then
		ar = ar + 360
	end

	-- use the Superimpose2 template
	text = mw.getCurrentFrame():expandTemplate {
		title = 'Superimpose2',
		args = {
			base = map.image,
			base_width = width .. 'px',
			base_caption = '',
			float = args.mark or 'Cercle rouge 100%.svg',
			float_width = marksize .. 'px',
			float_caption = args.name or '',
			x = getX(map, ar, dec, width, marksize),
			y = getY(map, ar, dec, width, marksize)
		}
	}

	return args.inclusion and text or getThumbnail(text, map.image, args, width + 2)
end

-- Entry-point for the template {{IAU star location map}}
function p.main(frame)
	return select(2, xpcall(function()
		return p._main(getArgs(frame, { parentOnly = true }))
	end, errhandler))
end

-- Per l'utilizzo da altro modulo
function p._main2(map)
	local map, ar, dec, text
	
	-- ottiene la map
	if map then
		map = _latinise_letters(map)
	else
		error('map non spécifiée', 2)
	end
	-- eventuale alias
	map = cfg.alias[map] or map
	if not cfg.mappe[map] then
		error('map non disponibile: ' .. map, 2)
	end
	map = cfg.mappe[map]
	

	-- map doppia
	if map == 'ser' then
		map = map.caput
	end
	
	-- utilizza il template Superpose
	text = '[['.. map.page .. '|'.. string.gsub(map.page, ' %(constellation%)', '') ..']]'
	return text
end

-- Entry-point for the template {{IAU star location map}}
function p.page(frame)
	local map = frame.args[1]
	return p._main2(map)
end

return p