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 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'structs.go') 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() } -- cgit 1.4.1