From 91003487acda056be18c9efecedd951ca9629f26 Mon Sep 17 00:00:00 2001 From: hanemile Date: Sat, 3 Nov 2018 00:48:01 +0100 Subject: refactored some names, they are now being exported. --- structs.go | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'structs.go') diff --git a/structs.go b/structs.go index 9406a5b..68ccea3 100644 --- a/structs.go +++ b/structs.go @@ -33,15 +33,15 @@ func (point Coord) insideOf(quadtreeCell *quadtree) bool { return false } -// boundingBox defines a single cell in the quadtree -type boundingBox struct { +// BoundingBox defines a single cell in the quadtree +type BoundingBox struct { center Coord halfDimension float64 } -// newBoundingBox returns a new bounding with the given struct elements -func newBoundingBox(inCenter Coord, inHalfDimension float64) boundingBox { - return boundingBox{ +// NewBoundingBox returns a new bounding with the given struct elements +func NewBoundingBox(inCenter Coord, inHalfDimension float64) BoundingBox { + return BoundingBox{ center: inCenter, halfDimension: inHalfDimension, } @@ -51,7 +51,7 @@ func newBoundingBox(inCenter Coord, inHalfDimension float64) boundingBox { type quadtree struct { // general information (node capacity, spacial outreach) nodeCapacity int - boundary boundingBox + boundary BoundingBox // slice storing the star coordinates pointsSlice []Coord @@ -65,8 +65,8 @@ type quadtree struct { depth int } -// newQuadtree returns a new quadtree -func newQuadtree(boundary boundingBox, depth int) *quadtree { +// NewQuadtree returns a new quadtree +func NewQuadtree(boundary BoundingBox, depth int) *quadtree { return &quadtree{ nodeCapacity: 0, boundary: boundary, @@ -82,49 +82,49 @@ func newQuadtree(boundary boundingBox, depth int) *quadtree { func (quadtree *quadtree) subdivide() { // Create the new NorthWest boundingbox - var newCellBoundingNorthWest = boundingBox{ + var newCellBoundingNorthWest = BoundingBox{ center: Coord{ x: quadtree.boundary.center.x - quadtree.boundary.halfDimension/2, y: quadtree.boundary.center.y + quadtree.boundary.halfDimension/2, }, halfDimension: quadtree.boundary.halfDimension / 2, } - quadtree.northWest = newQuadtree(newCellBoundingNorthWest, quadtree.depth+1) + quadtree.northWest = NewQuadtree(newCellBoundingNorthWest, quadtree.depth+1) // Create the new NorthWest boundingbox - var newCellBoundingNorthEast = boundingBox{ + var newCellBoundingNorthEast = BoundingBox{ center: Coord{ x: quadtree.boundary.center.x + quadtree.boundary.halfDimension/2, y: quadtree.boundary.center.y + quadtree.boundary.halfDimension/2, }, halfDimension: quadtree.boundary.halfDimension / 2, } - quadtree.northEast = newQuadtree(newCellBoundingNorthEast, quadtree.depth+1) + quadtree.northEast = NewQuadtree(newCellBoundingNorthEast, quadtree.depth+1) // Create the new NorthWest boundingbox - var newCellBoundingSouthWest = boundingBox{ + var newCellBoundingSouthWest = BoundingBox{ center: Coord{ x: quadtree.boundary.center.x - quadtree.boundary.halfDimension/2, y: quadtree.boundary.center.y - quadtree.boundary.halfDimension/2, }, halfDimension: quadtree.boundary.halfDimension / 2, } - quadtree.southWest = newQuadtree(newCellBoundingSouthWest, quadtree.depth+1) + quadtree.southWest = NewQuadtree(newCellBoundingSouthWest, quadtree.depth+1) // Create the new NorthWest boundingbox - var newCellBoundingSouthEast = boundingBox{ + var newCellBoundingSouthEast = BoundingBox{ center: Coord{ x: quadtree.boundary.center.x + quadtree.boundary.halfDimension/2, y: quadtree.boundary.center.y - quadtree.boundary.halfDimension/2, }, halfDimension: quadtree.boundary.halfDimension / 2, } - quadtree.southEast = newQuadtree(newCellBoundingSouthEast, quadtree.depth+1) + 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 quadtree.subdivide() @@ -132,22 +132,22 @@ func (quadtree *quadtree) insert(point Coord) { // if the maxDepth is not reached... if quadtree.depth < 4 { // ... test if the given point is inside the one of the cells - // and add insert it to that specific cell + // and add Insert it to that specific cell if point.insideOf(quadtree.northWest) { - quadtree.northWest.insert(point) + quadtree.northWest.Insert(point) } if point.insideOf(quadtree.northEast) { - quadtree.northEast.insert(point) + quadtree.northEast.Insert(point) } if point.insideOf(quadtree.southWest) { - quadtree.southWest.insert(point) + quadtree.southWest.Insert(point) } if point.insideOf(quadtree.southEast) { - quadtree.southEast.insert(point) + quadtree.southEast.Insert(point) } } // if the maximal depth of the tree has been reached: - // insert the point into the slice + // Insert the point into the slice quadtree.pointsSlice = append(quadtree.pointsSlice, point) } -- cgit 1.4.1