Skip to content

Instantly share code, notes, and snippets.

@eriadam
Created June 24, 2019 21:02
Show Gist options
  • Save eriadam/dc1fb4ca1a7ec12a2b863c192bd0ea57 to your computer and use it in GitHub Desktop.
Save eriadam/dc1fb4ca1a7ec12a2b863c192bd0ea57 to your computer and use it in GitHub Desktop.
/// Nearest neigbour to a defined point.
let nearest = tree.element(nearestTo: float2(0, 0))
/// You may filter for different types (classes) when performing
/// a nearest element search.
let nearestLocation = tree.element(
nearestTo: float2(0, 0),
type: CLLocation.self)
/// All of the elements in the quadtree node this point would be placed in.
let elementsAtPoint = tree.elements(at: float2(0, 0))
/// All of the elements that resides in quadtree nodes which intersect
/// the given quad. Recursively check if the earch quad contains the points
/// in the quad.
let searchQuad = BMQuad(
quadMin: float2(-10, -10),
quadMax: float2(10, 10))
let elementsInQuad = tree.elements(in: searchQuad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment