//Find Searches the tree for a given node that contains a point func (n *Node) Find(point geo.Point) *Node { concat, last := point.GetMortonAt(n.level) if n.descend(concat).ContainsPoint(point) { return n.descend(concat) } if last { //Point not found return nil } return n.descend(concat).Find(point) }
//Insert inserts a point into the first availbe descendand of a node func (n *Node) Insert(point geo.Point) *Node { concat, last := point.GetMortonAt(n.level) n = n.split().descend(concat) //.split() only splits if node not splitted if n.addPoint(point) { return n } if last { fmt.Println(n.points, n.treePos(), n.level) log.Fatal("Couldnt insert, not enough point", point) } return n.Insert(point) }