about summary refs log tree commit diff
path: root/structs/structs.go
blob: b4b550a199368af18439a461003ca97a784692bc (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
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
}