Example #1
0
//ContainsPoint returns true if a point is in the given node
func (n Node) ContainsPoint(p geo.Point) bool {
	for _, v := range n.points {
		if p.Equals(v) {
			return true
		}
	}
	return false
}
Example #2
0
//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)
}
Example #3
0
//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)
}
Example #4
0
func (n Node) isWithinRange(min geo.Point, max geo.Point) bool {
	return n.zx.CompareTo(min.GetX()) >= zero &&
		n.zy.CompareTo(min.GetY()) >= zero &&
		n.zx.CompareTo(max.GetX()) <= zero &&
		n.zy.CompareTo(max.GetY()) <= zero
}