blob: ea99d96063b21388008b349e631055195c224eac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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
}
|