Module:Mediants: Difference between revisions
m todo |
Changed filter functions to be two-param, where the first param is a table that has both the mediant and depth; may momentarily break dependent modules |
||
| Line 4: | Line 4: | ||
-- Module for finding mediants, either by search depth or by search function. | -- Module for finding mediants, either by search depth or by search function. | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 24: | Line 18: | ||
-- Int limit filter determines whether a ratio is within an int limit. Does not | -- Int limit filter determines whether a ratio is within an int limit. Does not | ||
-- use depth. | -- use depth. | ||
function p.int_limit_filter( | function p.int_limit_filter(mediant_data, int_limit) | ||
local mediant = mediant_data["mediant"] | |||
return math.max(mediant[1], mediant[2]) <= int_limit | return math.max(mediant[1], mediant[2]) <= int_limit | ||
end | end | ||
| Line 30: | Line 25: | ||
-- Depth filter determines whether a ratio is within a target depth. Does not | -- Depth filter determines whether a ratio is within a target depth. Does not | ||
-- use the mediant itself. | -- use the mediant itself. | ||
function p.search_depth_filter( | function p.search_depth_filter(mediant_data, search_depth) | ||
local depth = mediant_data["depth"] | |||
return depth <= search_depth | return depth <= search_depth | ||
end | end | ||
| Line 36: | Line 32: | ||
-- Tenney height filter determines whether a ratio is within a target Tenney | -- Tenney height filter determines whether a ratio is within a target Tenney | ||
-- height. Does not use depth. | -- height. Does not use depth. | ||
function p.tenney_height_filter( | function p.tenney_height_filter(mediant_data, tenney_height) | ||
local mediant = mediant_data["mediant"] | |||
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height | return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height | ||
end | end | ||
| Line 78: | Line 75: | ||
table.insert(new_depths, depth_1) | table.insert(new_depths, depth_1) | ||
if filter_func( | local mediant_data = { ["mediant"] = mediant, ["depth"] = new_depth } | ||
if filter_func(mediant_data, filter_args) then | |||
table.insert(new_ratios, mediant) | table.insert(new_ratios, mediant) | ||
table.insert(new_depths, new_depth) | table.insert(new_depths, new_depth) | ||