Skip to content

Commit

Permalink
Preserve order of points list in kdtree.create()
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoegl committed Jun 25, 2016
1 parent 090f32f commit cd4cad2
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions kdtree.py
Expand Up @@ -213,8 +213,6 @@ def __init__(self, data=None, left=None, right=None, axis=None,
sel_axis(axis) is used when creating subnodes of the current node. It
receives the axis of the parent node and returns the axis of the child
node. """
if type(data) == 'list':
data = list(data)
super(KDNode, self).__init__(data, left, right)
self.axis = axis
self.sel_axis = sel_axis
Expand Down Expand Up @@ -581,6 +579,7 @@ def create(point_list=None, dimensions=None, axis=0, sel_axis=None):
return KDNode(sel_axis=sel_axis, axis=axis, dimensions=dimensions)

# Sort point list and choose median as pivot element
point_list = list(point_list)
point_list.sort(key=lambda point: point[axis])
median = len(point_list) // 2

Expand Down

1 comment on commit cd4cad2

@TennyZhuang
Copy link
Contributor

@TennyZhuang TennyZhuang commented on cd4cad2 Jun 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some wrong while reading the source code..
I have just found that the argument data of KDNode is only a point not the point list.
This move is correct, sorry.

Please sign in to comment.