about summary refs log tree commit diff
path: root/structs.go
diff options
context:
space:
mode:
Diffstat (limited to 'structs.go')
-rw-r--r--structs.go27
1 files changed, 21 insertions, 6 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)
 }