From d85773ffda4a6a2602b319cc0ee8ec757cc0042b Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 3 Nov 2018 17:53:44 +0100 Subject: Exported the quadtree function (quadtree -> Quadtree) --- structs.go | 34 +++++++++++++++++----------------- structs_test.go | 8 ++++---- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/structs.go b/structs.go index fa503ec..5f916bd 100644 --- a/structs.go +++ b/structs.go @@ -8,14 +8,14 @@ type Coord struct { y float64 } -// BoundingBox defines a single cell in the quadtree +// BoundingBox defines a single cell in the Quadtree type BoundingBox struct { center Coord halfDimension float64 } -// quadtree defining the whole quadtree and a node in itself (recursively) -type quadtree struct { +// Quadtree defining the whole Quadtree and a node in itself (recursively) +type Quadtree struct { // general information (node capacity, spacial outreach) nodeCapacity int boundary BoundingBox @@ -23,11 +23,11 @@ type quadtree struct { // slice storing the star coordinates pointsSlice []Coord - // the quadtree leaves - northWest *quadtree - northEast *quadtree - southWest *quadtree - southEast *quadtree + // the Quadtree leaves + northWest *Quadtree + northEast *Quadtree + southWest *Quadtree + southEast *Quadtree depth int } @@ -45,7 +45,7 @@ func NewBoundingBox(inCenter Coord, inHalfDimension float64) BoundingBox { } } -func (point Coord) InsideOf(quadtreeCell *quadtree) bool { +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 @@ -67,9 +67,9 @@ func (point Coord) InsideOf(quadtreeCell *quadtree) bool { return false } -// NewQuadtree returns a new quadtree -func NewQuadtree(boundary BoundingBox, depth int) *quadtree { - return &quadtree{ +// NewQuadtree returns a new Quadtree +func NewQuadtree(boundary BoundingBox, depth int) *Quadtree { + return &Quadtree{ nodeCapacity: 0, boundary: boundary, pointsSlice: nil, @@ -81,7 +81,7 @@ func NewQuadtree(boundary BoundingBox, depth int) *quadtree { } } -func (quadtree *quadtree) subdivide() { +func (quadtree *Quadtree) subdivide() { // Create the new NorthWest boundingbox var newCellBoundingNorthWest = BoundingBox{ @@ -124,11 +124,11 @@ func (quadtree *quadtree) subdivide() { 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 + // subdivide the Quadtree into four new cells quadtree.subdivide() // if the maxDepth is not reached... @@ -154,7 +154,7 @@ func (quadtree *quadtree) Insert(point Coord) { quadtree.pointsSlice = append(quadtree.pointsSlice, point) } -func (quadtree *quadtree) Print() { +func (quadtree *Quadtree) Print() { if quadtree.northEast != nil { quadtree.northEast.Print() } diff --git a/structs_test.go b/structs_test.go index ceeace7..5b00aa5 100644 --- a/structs_test.go +++ b/structs_test.go @@ -7,7 +7,7 @@ import ( // Quadtree Test func TestQuadtree(t *testing.T) { - testQuadtree := quadtree{ + testQuadtree := Quadtree{ nodeCapacity: 0, boundary: BoundingBox{}, pointsSlice: nil, @@ -110,16 +110,16 @@ func TestSubdivide(t *testing.T) { // test the Insert function func TestInsert(t *testing.T) { - // Define a new quadtree-root-boundary + // Define a new Quadtree-root-boundary var boundary = BoundingBox{ center: Coord{0, 0}, halfDimension: 3, } - // create a new quadtree using the boundary + // create a new Quadtree using the boundary 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) -- cgit 1.4.1