about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-11-03 00:48:01 +0100
committerhanemile <hanemile@protonmail.com>2018-11-03 00:48:01 +0100
commit91003487acda056be18c9efecedd951ca9629f26 (patch)
treeddaf14a60346ce1fafd2fad7c172af4000304f2b
parent6bc79c4fb9a3251a6c45932576c9c131c8c6efc3 (diff)
refactored some names, they are now being exported.
-rw-r--r--structs.go48
-rw-r--r--structs_test.go30
2 files changed, 39 insertions, 39 deletions
diff --git a/structs.go b/structs.go
index 9406a5b..68ccea3 100644
--- a/structs.go
+++ b/structs.go
@@ -33,15 +33,15 @@ func (point Coord) insideOf(quadtreeCell *quadtree) bool {
 	return false
 }
 
-// boundingBox defines a single cell in the quadtree
-type boundingBox struct {
+// BoundingBox defines a single cell in the quadtree
+type BoundingBox struct {
 	center        Coord
 	halfDimension float64
 }
 
-// newBoundingBox returns a new bounding with the given struct elements
-func newBoundingBox(inCenter Coord, inHalfDimension float64) boundingBox {
-	return boundingBox{
+// NewBoundingBox returns a new bounding with the given struct elements
+func NewBoundingBox(inCenter Coord, inHalfDimension float64) BoundingBox {
+	return BoundingBox{
 		center:        inCenter,
 		halfDimension: inHalfDimension,
 	}
@@ -51,7 +51,7 @@ func newBoundingBox(inCenter Coord, inHalfDimension float64) boundingBox {
 type quadtree struct {
 	// general information (node capacity, spacial outreach)
 	nodeCapacity int
-	boundary     boundingBox
+	boundary     BoundingBox
 
 	// slice storing the star coordinates
 	pointsSlice []Coord
@@ -65,8 +65,8 @@ type quadtree struct {
 	depth int
 }
 
-// newQuadtree returns a new quadtree
-func newQuadtree(boundary boundingBox, depth int) *quadtree {
+// NewQuadtree returns a new quadtree
+func NewQuadtree(boundary BoundingBox, depth int) *quadtree {
 	return &quadtree{
 		nodeCapacity: 0,
 		boundary:     boundary,
@@ -82,49 +82,49 @@ func newQuadtree(boundary boundingBox, depth int) *quadtree {
 func (quadtree *quadtree) subdivide() {
 
 	// Create the new NorthWest boundingbox
-	var newCellBoundingNorthWest = boundingBox{
+	var newCellBoundingNorthWest = BoundingBox{
 		center: Coord{
 			x: quadtree.boundary.center.x - quadtree.boundary.halfDimension/2,
 			y: quadtree.boundary.center.y + quadtree.boundary.halfDimension/2,
 		},
 		halfDimension: quadtree.boundary.halfDimension / 2,
 	}
-	quadtree.northWest = newQuadtree(newCellBoundingNorthWest, quadtree.depth+1)
+	quadtree.northWest = NewQuadtree(newCellBoundingNorthWest, quadtree.depth+1)
 
 	// Create the new NorthWest boundingbox
-	var newCellBoundingNorthEast = boundingBox{
+	var newCellBoundingNorthEast = BoundingBox{
 		center: Coord{
 			x: quadtree.boundary.center.x + quadtree.boundary.halfDimension/2,
 			y: quadtree.boundary.center.y + quadtree.boundary.halfDimension/2,
 		},
 		halfDimension: quadtree.boundary.halfDimension / 2,
 	}
-	quadtree.northEast = newQuadtree(newCellBoundingNorthEast, quadtree.depth+1)
+	quadtree.northEast = NewQuadtree(newCellBoundingNorthEast, quadtree.depth+1)
 
 	// Create the new NorthWest boundingbox
-	var newCellBoundingSouthWest = boundingBox{
+	var newCellBoundingSouthWest = BoundingBox{
 		center: Coord{
 			x: quadtree.boundary.center.x - quadtree.boundary.halfDimension/2,
 			y: quadtree.boundary.center.y - quadtree.boundary.halfDimension/2,
 		},
 		halfDimension: quadtree.boundary.halfDimension / 2,
 	}
-	quadtree.southWest = newQuadtree(newCellBoundingSouthWest, quadtree.depth+1)
+	quadtree.southWest = NewQuadtree(newCellBoundingSouthWest, quadtree.depth+1)
 
 	// Create the new NorthWest boundingbox
-	var newCellBoundingSouthEast = boundingBox{
+	var newCellBoundingSouthEast = BoundingBox{
 		center: Coord{
 			x: quadtree.boundary.center.x + quadtree.boundary.halfDimension/2,
 			y: quadtree.boundary.center.y - quadtree.boundary.halfDimension/2,
 		},
 		halfDimension: quadtree.boundary.halfDimension / 2,
 	}
-	quadtree.southEast = newQuadtree(newCellBoundingSouthEast, quadtree.depth+1)
+	quadtree.southEast = NewQuadtree(newCellBoundingSouthEast, quadtree.depth+1)
 }
 
-// insert inserts the given point into the quadtree the method is applied on
+// Insert inserts the given point into the quadtree the method is applied on
 // it returns an error incase the point is not in bounds
-func (quadtree *quadtree) insert(point Coord) {
+func (quadtree *quadtree) Insert(point Coord) {
 
 	// subdivide the quadtree into four new cells
 	quadtree.subdivide()
@@ -132,22 +132,22 @@ func (quadtree *quadtree) insert(point Coord) {
 	// if the maxDepth is not reached...
 	if quadtree.depth < 4 {
 		// ... test if the given point is inside the one of the cells
-		// and add insert it to that specific cell
+		// and add Insert it to that specific cell
 		if point.insideOf(quadtree.northWest) {
-			quadtree.northWest.insert(point)
+			quadtree.northWest.Insert(point)
 		}
 		if point.insideOf(quadtree.northEast) {
-			quadtree.northEast.insert(point)
+			quadtree.northEast.Insert(point)
 		}
 		if point.insideOf(quadtree.southWest) {
-			quadtree.southWest.insert(point)
+			quadtree.southWest.Insert(point)
 		}
 		if point.insideOf(quadtree.southEast) {
-			quadtree.southEast.insert(point)
+			quadtree.southEast.Insert(point)
 		}
 	}
 
 	// if the maximal depth of the tree has been reached:
-	// insert the point into the slice
+	// Insert the point into the slice
 	quadtree.pointsSlice = append(quadtree.pointsSlice, point)
 }
diff --git a/structs_test.go b/structs_test.go
index 66598bf..685557b 100644
--- a/structs_test.go
+++ b/structs_test.go
@@ -8,7 +8,7 @@ import (
 func TestQuadtree(t *testing.T) {
 	testQuadtree := quadtree{
 		nodeCapacity: 0,
-		boundary:     boundingBox{},
+		boundary:     BoundingBox{},
 		pointsSlice:  nil,
 		northWest:    nil,
 		northEast:    nil,
@@ -21,12 +21,12 @@ func TestQuadtree(t *testing.T) {
 
 // NewQuadTree test
 func TestNewQuadtree(t *testing.T) {
-	var boundary = boundingBox{
+	var boundary = BoundingBox{
 		center:        Coord{0, 0},
 		halfDimension: 3,
 	}
 
-	var newQuadtree = *newQuadtree(boundary, 0)
+	var newQuadtree = *NewQuadtree(boundary, 0)
 
 	t.Log(newQuadtree)
 }
@@ -49,7 +49,7 @@ func TestNewCoord(t *testing.T) {
 }
 
 func TestBoundingBox(t *testing.T) {
-	var newBoundingBox = boundingBox{
+	var newBoundingBox = BoundingBox{
 		center: Coord{
 			x: 1,
 			y: 2,
@@ -62,7 +62,7 @@ func TestBoundingBox(t *testing.T) {
 
 func TestInsideOf(t *testing.T) {
 	var testCoordinate = Coord{0, 0}
-	var testQuadTree = newQuadtree(boundingBox{
+	var testQuadTree = NewQuadtree(BoundingBox{
 		center: Coord{
 			x: 0,
 			y: 0,
@@ -74,7 +74,7 @@ func TestInsideOf(t *testing.T) {
 	t.Log(isInsideOf)
 }
 
-// Test the newBoundingBox function
+// Test the NewBoundingBox function
 func TestNewBoundingBox(t *testing.T) {
 
 	// Initialize some values that are needed
@@ -82,19 +82,19 @@ func TestNewBoundingBox(t *testing.T) {
 	var newHalfDimension float64 = 3
 
 	// Initialize the bounding box using the values above
-	var newBoundingBox = newBoundingBox(newCenter, newHalfDimension)
+	var newBoundingBox = NewBoundingBox(newCenter, newHalfDimension)
 
-	// Print the newBoundingBox
+	// Print the NewBoundingBox
 	t.Log(newBoundingBox)
 }
 
 func TestSubdivide(t *testing.T) {
-	var boundary = boundingBox{
+	var boundary = BoundingBox{
 		center:        Coord{0, 0},
 		halfDimension: 3,
 	}
 
-	var newQuadtree = *newQuadtree(boundary, 0)
+	var newQuadtree = *NewQuadtree(boundary, 0)
 
 	newQuadtree.subdivide()
 
@@ -106,20 +106,20 @@ func TestSubdivide(t *testing.T) {
 
 }
 
-// test the insert function
+// test the Insert function
 func TestInsert(t *testing.T) {
 	// Define a new quadtree-root-boundary
-	var boundary = boundingBox{
+	var boundary = BoundingBox{
 		center:        Coord{0, 0},
 		halfDimension: 3,
 	}
 
 	// create a new quadtree using the boundary
-	var newQuadtree = *newQuadtree(boundary, 0)
+	var newQuadtree = *NewQuadtree(boundary, 0)
 
-	// Define a star and insert it into the quadtree
+	// Define a star and Insert it into the quadtree
 	singleCoord := Coord{0.5, 0.5}
-	newQuadtree.insert(singleCoord)
+	newQuadtree.Insert(singleCoord)
 
 	// Print the stuff generated
 	t.Logf("Complete Tree: %v\n", newQuadtree.northEast.southWest.southWest.northEast)