about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <hanemile@protonmail.com>2018-11-03 17:49:55 +0100
committerhanemile <hanemile@protonmail.com>2018-11-03 17:49:55 +0100
commite2751726e199f5b50d702a61672c037be96a2673 (patch)
tree3c39456722a3fa52f5e2b474156fec41225ef853
parent9980713b96ede448e90a0d285356c42901d59f7b (diff)
the insideOf function is now called InsideOf and can be now called from everywhere!
-rw-r--r--structs.go27
-rw-r--r--structs_test.go3
2 files changed, 23 insertions, 7 deletions
diff --git a/structs.go b/structs.go
index 2d7f6a9..0fcdc14 100644
--- a/structs.go
+++ b/structs.go
@@ -1,5 +1,7 @@
 package quadtree
 
+import "fmt"
+
 // coordinate type storing a position
 type Coord struct {
 	x float64
@@ -17,7 +19,20 @@ func NewCoord(x float64, y float64) Coord {
 	return Coord{x, y}
 }
 
-func (point Coord) insideOf(quadtreeCell *quadtree) bool {
+func ExampleNewCoord() {
+	fmt.Println(NewCoord(1, 1))
+	// Output: {1, 1}
+}
+
+// NewBoundingBox returns a new bounding with the given struct elements
+func NewBoundingBox(inCenter Coord, inHalfDimension float64) BoundingBox {
+	return BoundingBox{
+		center:        inCenter,
+		halfDimension: inHalfDimension,
+	}
+}
+
+func (point Coord) InsideOf(quadtreeCell *quadtree) bool {
 	// define the bounds
 	var lowerXBound = quadtreeCell.boundary.center.x - quadtreeCell.boundary.halfDimension
 	var upperXBound = quadtreeCell.boundary.center.x + quadtreeCell.boundary.halfDimension
@@ -125,16 +140,16 @@ func (quadtree *quadtree) Insert(point Coord) {
 	if quadtree.depth < 4 {
 		// ... test if the given point is inside the one of the cells
 		// and add Insert it to that specific cell
-		if point.insideOf(quadtree.northWest) {
+		if point.InsideOf(quadtree.northWest) {
 			quadtree.northWest.Insert(point)
 		}
-		if point.insideOf(quadtree.northEast) {
+		if point.InsideOf(quadtree.northEast) {
 			quadtree.northEast.Insert(point)
 		}
-		if point.insideOf(quadtree.southWest) {
+		if point.InsideOf(quadtree.southWest) {
 			quadtree.southWest.Insert(point)
 		}
-		if point.insideOf(quadtree.southEast) {
+		if point.InsideOf(quadtree.southEast) {
 			quadtree.southEast.Insert(point)
 		}
 	}
@@ -157,5 +172,5 @@ func (quadtree *quadtree) Print() {
 	if quadtree.southWest != nil {
 		quadtree.southWest.Print()
 	}
-	print(quadtree.pointsSlice)
+	fmt.Println(quadtree)
 }
diff --git a/structs_test.go b/structs_test.go
index 685557b..108cbc3 100644
--- a/structs_test.go
+++ b/structs_test.go
@@ -48,6 +48,7 @@ func TestNewCoord(t *testing.T) {
 	t.Log(newCoordinate)
 }
 
+// TestBoundingBox creates a bounding box
 func TestBoundingBox(t *testing.T) {
 	var newBoundingBox = BoundingBox{
 		center: Coord{
@@ -70,7 +71,7 @@ func TestInsideOf(t *testing.T) {
 		halfDimension: 1,
 	}, 0)
 
-	var isInsideOf = testCoordinate.insideOf(testQuadTree)
+	var isInsideOf = testCoordinate.InsideOf(testQuadTree)
 	t.Log(isInsideOf)
 }