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, start, tail) | ||
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 28: | Line 30: | ||
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, start, false) | ||
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) | return r_layout .. p.auto_layout(n - r_n, m - r_m, convergents, false, tail) | ||
end | end | ||
| Line 51: | Line 53: | ||
end | end | ||
) | ) | ||
layout = p.auto_layout(fifth, et.size, convergents) | layout = p.auto_layout(fifth, et.size, convergents, true, true) | ||
end | end | ||