Localize k-d-tree traversal function
parent
4e425823b0
commit
dfba3c44df
|
@ -31,7 +31,7 @@ function kd_closest_color_finder(colors)
|
||||||
return function(color)
|
return function(color)
|
||||||
local min_distance=math.huge
|
local min_distance=math.huge
|
||||||
local closest_color
|
local closest_color
|
||||||
f=function(tree)
|
local function f(tree)
|
||||||
local axis=tree.axis
|
local axis=tree.axis
|
||||||
if #tree > 0 then -- Subtree is leaf
|
if #tree > 0 then -- Subtree is leaf
|
||||||
local distance = distance(tree, color)
|
local distance = distance(tree, color)
|
||||||
|
@ -43,7 +43,7 @@ function kd_closest_color_finder(colors)
|
||||||
else
|
else
|
||||||
local new_tree, other_tree = tree.right, tree.left
|
local new_tree, other_tree = tree.right, tree.left
|
||||||
if color[axis] < tree.pivot[axis] then
|
if color[axis] < tree.pivot[axis] then
|
||||||
new_tree, other_tree = tree.left, tree.right
|
new_tree, other_tree = other_tree, new_tree
|
||||||
end
|
end
|
||||||
f(other_tree)
|
f(other_tree)
|
||||||
if tree.pivot then
|
if tree.pivot then
|
||||||
|
|
Loading…
Reference in New Issue