kd tree and nearest neighbour