From 563482f80ec62439ebd1d4caeda39eb05a4c4a50 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 24 Dec 2018 22:47:07 +0100 Subject: overall push --- draw.go | 2 +- quadtree.go | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/draw.go b/draw.go index 1d7eb4f..5f96e87 100644 --- a/draw.go +++ b/draw.go @@ -42,7 +42,7 @@ func drawQuadtree(context *gg.Context, q Quadtree) { // define the current star x := q.Star.C.X y := q.Star.C.Y - starsize := 1 + starsize := 2 // set the color of the stars to green context.SetRGB(0, 1, 1) diff --git a/quadtree.go b/quadtree.go index 7adae8b..2de791b 100644 --- a/quadtree.go +++ b/quadtree.go @@ -1,6 +1,7 @@ package structs import ( + "fmt" "log" ) @@ -130,13 +131,12 @@ func (q *Quadtree) Insert(point Star2D) { // Insert thee given star into the galaxy // Case 1: There is no star inside of the node if q.Star == (Star2D{Vec2{}, Vec2{}, 0}) { - log.Printf("[ + ] There was no star inside of the node -> inserting directly") + log.Printf("[ ] There was no star inside of the node -> inserting directly") q.Star = point - return // Case 2: There is all ready a star inside of the node } else { - log.Printf("[ + ] There is allready a star inside of the node -> subdividing") + log.Printf("[ ! ] There is allready a star inside of the node -> subdividing") // Test if the star is left or right of the center point if point.C.X < bx && point.C.X > bx-bw { @@ -196,6 +196,23 @@ func (q *Quadtree) Insert(point Star2D) { } log.Printf("[ ] Tree after insertion: %v", q) + q.print() +} + +// print recursively prints the given quadtree +func (q *Quadtree) print() { + + // iterate over all four child nodes + for i := 0; i < 4; i++ { + + // if the child node is no an empty tree, print it + if *q.Quadrants[i] != (Quadtree{}) { + fmt.Println(q.Quadrants[i]) + + // make a recursive call on the child printing all it's quadtrees + q.Quadrants[i].print() + } + } } // subdivide subdivides the quadtree it is called on -- cgit 1.4.1