Retrieve returns all objects that could collide with the given bounding box
(pRect AABB)
| 311 | |
| 312 | // Retrieve returns all objects that could collide with the given bounding box |
| 313 | func (qt *quadtreeNode) Retrieve(pRect AABB) []AABBer { |
| 314 | index := qt.getIndex(pRect) |
| 315 | |
| 316 | // Array with all detected objects |
| 317 | result := make([]AABBer, len(qt.Objects)) |
| 318 | for i, o := range qt.Objects { |
| 319 | result[i] = o.Value |
| 320 | } |
| 321 | |
| 322 | //if we have subnodes ... |
| 323 | if qt.hasNodes { |
| 324 | //if pRect fits into a subnode .. |
| 325 | if index != -1 { |
| 326 | result = append(result, qt.Nodes[index].Retrieve(pRect)...) |
| 327 | } else { |
| 328 | //if pRect does not fit into a subnode, check it against all subnodes |
| 329 | for i := 0; i < 4; i++ { |
| 330 | result = append(result, qt.Nodes[i].Retrieve(pRect)...) |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return result |
| 336 | |
| 337 | } |
| 338 | |
| 339 | // Retrieve returns all objects that could collide with the given bounding box and passing the given filter function. |
| 340 | func (qt *Quadtree) Retrieve(find AABB, filter func(aabb AABBer) bool) []AABBer { |