Module:JI ratios: Difference between revisions
No edit summary |
cleanup before rewriting |
||
| Line 8: | Line 8: | ||
-- TODO | -- TODO | ||
-- - Move filtering functions to separate module? | |||
-- - Transfer control over to new "main" function: p.ji_ratios() | -- - Transfer control over to new "main" function: p.ji_ratios() | ||
| Line 56: | Line 57: | ||
end | end | ||
return found | return found | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
--------------------------- FILTER/SORTING FUNCTIONS --------------------------- | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 104: | Line 91: | ||
end | end | ||
return filtered_ratios | return filtered_ratios | ||
end | |||
-- Sorts ratios by closeness to cent values. | |||
function p.sort_by_closeness_to_cent_values(ratios, cent_values, tolerance) | |||
local tolerance = tolerance or 30 | |||
local sorted_ratios = {} | |||
local curr_index = 1 -- Index of current_ratio | |||
for i = 1, #cent_values do | |||
local lower_bound = cent_values[i] - tolerance | |||
local upper_bound = cent_values[i] + tolerance | |||
local cents_within_range = true | |||
local curr_ratios = {} | |||
for j = curr_index, #ratios do | |||
local curr_ratio = ratios[j] | |||
local curr_cents = rat.cents(curr_ratio) | |||
if lower_bound < curr_cents and curr_cents < upper_bound then | |||
table.insert(curr_ratios, curr_ratio) | |||
--elseif curr_cents > upper_bound then | |||
-- curr_index = j | |||
-- break | |||
end | |||
end | |||
table.insert(sorted_ratios, curr_ratios) | |||
end | |||
return sorted_ratios | |||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
----------------------- INT-LIMIT | -------------------------- INT-LIMIT SEARCH FUNCTION --------------------------- | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 140: | Line 157: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
------------------------ | ------------------------- PRIME-LIMIT SEARCH FUNCTION -------------------------- | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 168: | Line 185: | ||
end | end | ||
-- | -------------------------------------------------------------------------------- | ||
---------------------------- SUBGROUP SEARCH FUNCTION -------------------------- | |||
-------------------------------------------------------------------------------- | |||
function p.search_by_subgroup(subgroup, equave, fine_search_args) | function p.search_by_subgroup(subgroup, equave, fine_search_args) | ||
local subgroup = subgroup or {rat.new(2), rat.new(3), rat.new(7)} | local subgroup = subgroup or {rat.new(2), rat.new(3), rat.new(7)} | ||
| Line 239: | Line 259: | ||
--------------------------- REVERSE-SEARCH FUNCTIONS --------------------------- | --------------------------- REVERSE-SEARCH FUNCTIONS --------------------------- | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
--[[ | |||
function p.int_limit_of_ratios(ratios) | function p.int_limit_of_ratios(ratios) | ||
| Line 254: | Line 274: | ||
end | end | ||
]]-- | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-------------------------- ARG-BASED SEARCH FUNCTIONS -------------------------- | -------------------------- ARG-BASED SEARCH FUNCTIONS -------------------------- | ||
| Line 309: | Line 329: | ||
return parsed | return parsed | ||
end | end | ||
| Line 414: | Line 375: | ||
end | end | ||
return texts | return texts | ||
end | end | ||