Module:Keyboard: Difference between revisions
mNo edit summary |
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 | function p.auto_layout(n, m, convergents) | ||
if m == 0 then | if m == 0 then | ||
return '' | return '' | ||
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 | 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 | 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 | layout = p.auto_layout(fifth, et.size, convergents) | ||
end | end | ||