Module:Keyboard: Difference between revisions

Plumtree (talk | contribs)
mNo edit summary
Plumtree (talk | contribs)
mNo edit summary
Line 9: Line 9:
-- `n`: white keys needed
-- `n`: white keys needed
-- `m`: total keys needed
-- `m`: total keys needed
function p.auto_layout(n, m, convergents, start, tail)
function p.auto_layout(n, m, convergents)
if m == 0 then
if m == 0 then
return ''
return ''
elseif n == 1 and m == 2 and tail and not start then
return 'bw' -- instead of 'wb'
elseif layout_cache[n .. '/' .. m] then
elseif layout_cache[n .. '/' .. m] then
return layout_cache[n .. '/' .. m]
return layout_cache[n .. '/' .. m]
Line 30: Line 28:
end
end
local r_n, r_m = rat.as_pair(convergents[max_i])
local r_n, r_m = rat.as_pair(convergents[max_i])
local r_layout = p.auto_layout(r_n, r_m, convergents, start, false)
local r_layout = p.auto_layout(r_n, r_m, convergents)
if not layout_cache[r_n .. '/' .. r_m] then
if not layout_cache[r_n .. '/' .. r_m] then
layout_cache[r_n .. '/' .. r_m] = r_layout
layout_cache[r_n .. '/' .. r_m] = r_layout
end
end
return r_layout .. p.auto_layout(n - r_n, m - r_m, convergents, false, tail)
if n - r_n ~= 1 or m - r_m ~= 2 then
return r_layout .. p.auto_layout(n - r_n, m - r_m, convergents)
else
return r_layout .. 'bw'
end
end
end


Line 53: Line 55:
end
end
)
)
layout = p.auto_layout(fifth, et.size, convergents, true, true)
layout = p.auto_layout(fifth, et.size, convergents)
end
end