about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-12-24 22:47:07 +0100
committerhanemile <hanemile@protonmail.com>2018-12-24 22:47:07 +0100
commit563482f80ec62439ebd1d4caeda39eb05a4c4a50 (patch)
treec0883ef3ead3f2fc923d4c52c059d7722aca26d7
parent50d8c3ac6e25e1c6637a13681cb53946c6c5dd9d (diff)
overall push
-rw-r--r--draw.go2
-rw-r--r--quadtree.go23
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