MCPcopy Create free account
hub / github.com/EngoEngine/engo / getIndex

Method getIndex

quadtree.go:217–244  ·  view source on GitHub ↗

getIndex - Determine which quadrant the object belongs to (0-3)

(pRect AABB)

Source from the content-addressed store, hash-verified

215
216// getIndex - Determine which quadrant the object belongs to (0-3)
217func (qt *quadtreeNode) getIndex(pRect AABB) int {
218 horzMidpoint := qt.Bounds.Min.X + (aabbWidth(qt.Bounds) / 2)
219 vertMidpoint := qt.Bounds.Min.Y + (aabbHeight(qt.Bounds) / 2)
220
221 //pRect can completely fit within the top quadrants
222 topQuadrant := (pRect.Min.Y < vertMidpoint) && (pRect.Max.Y < vertMidpoint)
223
224 //pRect can completely fit within the bottom quadrants
225 bottomQuadrant := (pRect.Min.Y > vertMidpoint)
226
227 //pRect can completely fit within the left quadrants
228 if (pRect.Min.X < horzMidpoint) && (pRect.Max.X < horzMidpoint) {
229 if topQuadrant {
230 return 1
231 } else if bottomQuadrant {
232 return 2
233 }
234 } else if pRect.Min.X > horzMidpoint {
235 //pRect can completely fit within the right quadrants
236 if topQuadrant {
237 return 0
238 } else if bottomQuadrant {
239 return 3
240 }
241 }
242
243 return -1 // index of the subnode (0-3), or -1 if pRect cannot completely fit within a subnode and is part of the parent node
244}
245
246// Insert inserts the given item to the quadtree
247func (qt *Quadtree) Insert(item AABBer) {

Callers 3

InsertMethod · 0.95
RemoveMethod · 0.95
RetrieveMethod · 0.95

Calls 2

aabbWidthFunction · 0.85
aabbHeightFunction · 0.85

Tested by

no test coverage detected