implement simple kd tree builder