package structs // coordinate type storing a position type coord struct { x float64 y float64 } // newCoord returns a new coordinate using the given values func newCoord(x float64, y float64) coord { return coord{x, y} } // boundingBox defines a single cell in the quadtree type boundingBox struct { center coord halfDimension float64 } // containsPoint returns true if the given point is inside of the boundingBox the method is called on func (boundingBox *boundingBox) containsPoint(point coord) bool { // find out if the point is in or outside of the box if boundingBox.center.x-boundingBox.halfDimension < point.x && boundingBox.center.x+boundingBox.halfDimension > point.x { if boundingBox.center.y-boundingBox.halfDimension < point.y && boundingBox.center.y+boundingBox.halfDimension > point.y { // the point is inside of the cell -> return true return true } } // the point is outside of the cell -> return false return false } // quadtree defining the whole quadtree and a node in itself (recursively) type quadtree struct { nodeCapacity int boundary boundingBox // the quadtree leaves northWest *quadtree northEast *quadtree southWest *quadtree southEast *quadtree }