From dfba3c44df2553461be3baaa8c8c3f7524b29c45 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 2 Jun 2020 23:05:42 +0200 Subject: [PATCH] Localize k-d-tree traversal function --- closest_color.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/closest_color.lua b/closest_color.lua index 0811413..7710d49 100644 --- a/closest_color.lua +++ b/closest_color.lua @@ -31,7 +31,7 @@ function kd_closest_color_finder(colors) return function(color) local min_distance=math.huge local closest_color - f=function(tree) + local function f(tree) local axis=tree.axis if #tree > 0 then -- Subtree is leaf local distance = distance(tree, color) @@ -43,7 +43,7 @@ function kd_closest_color_finder(colors) else local new_tree, other_tree = tree.right, tree.left if color[axis] < tree.pivot[axis] then - new_tree, other_tree = tree.left, tree.right + new_tree, other_tree = other_tree, new_tree end f(other_tree) if tree.pivot then