Module:Limits: Difference between revisions
Module created |
Distinct consistency limit implemented |
||
Line 32: | Line 32: | ||
end | end | ||
function p.additively_consistent(equave, size, ratios) | function p.additively_consistent(equave, size, ratios, distinct) | ||
distinct = distinct or false | |||
local function approximate(a) | local function approximate(a) | ||
return math.floor(size * math.log(rat.as_float(a)) / math.log(equave) + 0.5) | return math.floor(size * math.log(rat.as_float(a)) / math.log(equave) + 0.5) | ||
end | |||
if distinct then | |||
local approx_set = {} | |||
for a_key, a in pairs(ratios) do | |||
local a_approx = approximate(a) | |||
if approx_set[a_approx] then | |||
return false | |||
end | |||
approx_set[a_approx] = true | |||
end | |||
end | end | ||
for a_key, a in pairs(ratios) do | for a_key, a in pairs(ratios) do | ||
Line 56: | Line 67: | ||
end | end | ||
function p.consistency_limit(size, equave) | function p.consistency_limit(size, equave, distinct) | ||
equave = equave or 2 | equave = equave or 2 | ||
distinct = distinct or false | |||
local n = 1 | local n = 1 | ||
local last_n = 1 | local last_n = 1 | ||
Line 65: | Line 77: | ||
else | else | ||
local ratios = p.limits_modulo_equave(n, equave) | local ratios = p.limits_modulo_equave(n, equave) | ||
local consistent = p.additively_consistent(equave, size, ratios) | local consistent = p.additively_consistent(equave, size, ratios, distinct) | ||
if not consistent then | if not consistent then | ||
return last_n | return last_n |