package quadtree import ( "fmt" "testing" ) // Quadtree Test func TestQuadtree(t *testing.T) { testQuadtree := Quadtree{ nodeCapacity: 0, boundary: BoundingBox{}, pointsSlice: nil, northWest: nil, northEast: nil, southWest: nil, southEast: nil, } t.Log(testQuadtree) } // NewQuadTree test func TestNewQuadtree(t *testing.T) { var boundary = BoundingBox{ center: Coord{0, 0}, halfDimension: 3, } var newQuadtree = *NewQuadtree(boundary, 0) t.Log(newQuadtree) } // Coordinate Test func TestCoord(t *testing.T) { testCoord := Coord{ x: 0, y: 1, } t.Log(testCoord) } // NewCoord test func TestNewCoord(t *testing.T) { var newCoordinate = NewCoord(1, 2) t.Log(newCoordinate) } // TestBoundingBox creates a bounding box func TestBoundingBox(t *testing.T) { var newBoundingBox = BoundingBox{ center: Coord{ x: 1, y: 2, }, halfDimension: 3, } t.Log(newBoundingBox) } func TestInsideOf(t *testing.T) { var testCoordinate = Coord{0, 0} var testQuadTree = NewQuadtree(BoundingBox{ center: Coord{ x: 0, y: 0, }, halfDimension: 1, }, 0) var isInsideOf = testCoordinate.InsideOf(testQuadTree) t.Log(isInsideOf) } // Test the NewBoundingBox function func TestNewBoundingBox(t *testing.T) { // Initialize some values that are needed var newCenter = Coord{1, 2} var newHalfDimension float64 = 3 // Initialize the bounding box using the values above var newBoundingBox = NewBoundingBox(newCenter, newHalfDimension) // Print the NewBoundingBox t.Log(newBoundingBox) } func TestSubdivide(t *testing.T) { var boundary = BoundingBox{ center: Coord{0, 0}, halfDimension: 3, } var newQuadtree = *NewQuadtree(boundary, 0) newQuadtree.subdivide() t.Logf("newQuadTree: %v\n", newQuadtree) t.Logf("NorthWestCell: %v\n", newQuadtree.northWest) t.Logf("NorthEestCell: %v\n", newQuadtree.northEast) t.Logf("SouthWestCell: %v\n", newQuadtree.southWest) t.Logf("SouthEastCell: %v\n", newQuadtree.southEast) } // test the Insert function func TestInsert(t *testing.T) { // Define a new Quadtree-root-boundary var boundary = BoundingBox{ center: Coord{0, 0}, halfDimension: 3, } // create a new Quadtree using the boundary var newQuadtree = *NewQuadtree(boundary, 0) // Define a star and Insert it into the Quadtree singleCoord := Coord{0.5, 0.5} newQuadtree.Insert(singleCoord) // Print the stuff generated t.Logf("Complete Tree: %v\n", newQuadtree.northEast.southWest.southWest.northEast) } // The NewCoord function can be used to create a new Coordinate in the following way: func ExampleNewCoord() { fmt.Println(NewCoord(1, 1)) // Output: {1 1} } // The NewBoundingBox function can combine a coordinate resulting in a BoundingBox: func ExampleNewBoundingBox() { fmt.Println(NewBoundingBox(NewCoord(0, 0), 10)) // Output: {{0 0} 10} } // Using the InsideOf() method, it can be determined if a point is inside of a bounding box // or not. The Example below can be used as a reference: func ExampleInsideOf_Coord() { var point Coord = NewCoord(0, 0) var bounadry BoundingBox = NewBoundingBox(NewCoord(0, 0), 10) var quadtreeCell *Quadtree = NewQuadtree(bounadry, 0) fmt.Println(point.InsideOf(quadtreeCell)) // Output: true }