Module:MOS tunings: Difference between revisions
Simplified step ratio sorting |
m Undo revision 156351 by Ganaram inukshuk (talk) go back to previous implementation to resolve later Tag: Undo |
||
| Line 21: | Line 21: | ||
-- Helper function | -- Helper function | ||
-- | -- Sorts step ratios L:s by their hardnesses | ||
-- | function p.sort_step_ratios(step_ratios) | ||
if #step_ratios < 2 then | |||
return step_ratios | |||
end | |||
return | |||
-- Sort using selection sort, which is ok for smol datasets. | |||
for i = 1, #step_ratios - 1 do | |||
local index_of_smallest = i | |||
local current_val = step_ratios[i][1] / step_ratios[i][2] | |||
-- Find the ratio with the smallest hardness | |||
for j = i + 1, #step_ratios do | |||
if (step_ratios[j][1] / step_ratios[j][2] < current_val) then | |||
index_of_smallest = j | |||
end | |||
end | |||
if index_of_smallest ~= i then | |||
local temp = step_ratios[index_of_smallest] | |||
step_ratios[index_of_smallest] = step_ratios[i] | |||
step_ratios[i] = temp | |||
end | |||
end | |||
return step_ratios | |||
end | end | ||
| Line 32: | Line 51: | ||
-- Finds the step ratio range and sorts step ratios | -- Finds the step ratio range and sorts step ratios | ||
function p.preprocess_step_ratios(step_ratios) | function p.preprocess_step_ratios(step_ratios) | ||
local step_ratios = | local step_ratios = p.sort_step_ratios(step_ratios) | ||
local step_ratio_range = "" | local step_ratio_range = "" | ||