From 3396d8a7519e3d1180b42624165ee36eda63625c Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 12 Jan 2019 18:18:18 +0100 Subject: . --- quadtree.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/quadtree.go b/quadtree.go index a0a29ec..a9e60e6 100644 --- a/quadtree.go +++ b/quadtree.go @@ -58,6 +58,7 @@ func (n *Node) subdivide() { // Insert inserts the given star into the Node or the tree it is called on func (n *Node) Insert(star Star2D) { + fmt.Printf("Hello, this is the insert function, I'm inserting the star %v", star) // prevent the function to recurse to deep into the tree if n.Boundry.Width < 0.1 { @@ -95,8 +96,9 @@ func (n *Node) Insert(star Star2D) { QuadrantBlockingNew := star.getRelativePositionInt(n.Boundry) n.Subtrees[QuadrantBlockingNew].Insert(star) star = Star2D{} - } + + fmt.Println("Done inserting %v, the tree noe looks like this: %v", star, n) } // GenForestTree draws the subtree it is called on. If there is a star inside of the root node, the node is drawn @@ -165,3 +167,28 @@ for tree={,draw, s sep+=0.25em} panic(runerr) } } + +// GetAllStars returns all the stars in the tree it is called on in an array +func (n Node) GetAllStars() []Star2D { + + // define a list to store the stars + listOfNodes := []Star2D{} + + // if there is a star in the node, append the star to the list + if n.Star != (Star2D{}) { + listOfNodes = append(listOfNodes, n.Star) + } + + // iterate over all the subtrees + for i := 0; i < len(n.Subtrees); i++ { + if n.Subtrees[i] != nil { + + // insert all the stars from the subtrees into the list of nodes + for _, star := range n.Subtrees[i].GetAllStars() { + listOfNodes = append(listOfNodes, star) + } + } + } + + return listOfNodes +} -- cgit 1.4.1