QuadTree implementation in Elm.
QuadTree type. Keeps its elements in the leaves and keeps track of the maximum number of items that can be inserted in each leaf.
init : BoundingBox2d units coordinates -> Basics.Int -> QuadTree units coordinates a
Construct an empty QuadTree given a bounding box and a maxSize. The maxSize limits the number of elements that each leaf of the QuadTree can hold.
{ a | boundingBox : BoundingBox2d units coordinates }
Extend this record type in order to use the QuadTree.
length : QuadTree units coordinates a -> Basics.Int
Find the number of items in a quadTree. If elements are duplicated in different leaves, they will be counted multiple times.
getMaxSize : QuadTree units coordinates a -> Basics.Int
Get the maxSize of a quadTree.
getBoundingBox : QuadTree units coordinates a -> BoundingBox2d units coordinates
Get the bounding box of a quadTree.
insert : Bounded units coordinates a -> QuadTree units coordinates (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a)
Insert an item into a quadTree.
insertList : List (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a)
remove : a -> QuadTree units coordinates a -> QuadTree units coordinates a
Remove an item from a quadTree and return the new quadTree. If an item is found in multiple leaves, then the item will be removed from all leaves.
update : (Bounded units coordinates a -> Bounded units coordinates a) -> Bounded units coordinates a -> QuadTree units coordinates (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a)
Update an item in a quadTree. This is useful if you just want to update a single item. This removes the item from the quadTree, applies the given updateFunction, and then inserts the updated item into the quadTree.
findItems : Bounded units coordinates a -> QuadTree units coordinates (Bounded units coordinates a) -> List (Bounded units coordinates a)
Find all items in the quadTree which share a leaf with the given item or would share a leaf with the given item were the item in the quadTree. Useful for finding items close to the given item.
findIntersecting : Bounded units coordinates a -> QuadTree units coordinates (Bounded units coordinates a) -> List (Bounded units coordinates a)
Find all items that actually intersect with the given item.
Similar to findItems
but will return only intersection items, without neighboring items.
neighborsWithin : Quantity Basics.Float units -> BoundingBox2d units coordinates -> QuadTree units coordinates (Bounded units coordinates a) -> List (Bounded units coordinates a)
Find all the neighbors that are within a particular distance from an input object.
toList : QuadTree units coordinates a -> List a
Get all items from a quadTree. Conserves duplicates.
apply : (a -> List a -> a) -> QuadTree units coordinates a -> QuadTree units coordinates a
Apply a function, that takes an item and an array of items and returns an item, to a quadTree. This function is a useful helper for collision detection and response where the input function updates an object after colliding it with an array of objects.
applySafe : (Bounded units coordinates a -> List (Bounded units coordinates a) -> Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a)
Safe version of apply. Automatically calls reset after applying the function on the quadTree.
map : (a -> b) -> QuadTree units coordinates a -> QuadTree units coordinates b
The good 'ol map function.
Maps a function over a quadTree and returns a new quadTree.
Note: If your function modifies in any way the items'
bounding boxes, consider using mapSafe
or calling reset
after you are done as the quadTree may have items in the
wrong place. This function doesn't do the clean-up
automatically. If you want such functionality, use mapSafe
.
mapSafe : (Bounded units coordinates a -> Bounded units coordinates b) -> QuadTree units coordinates (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates b)
Version of map
where the quadTree is reset
automatically after applying the function.
reset : QuadTree units coordinates (Bounded units coordinates a) -> QuadTree units coordinates (Bounded units coordinates a)
Reset a quadTree. This function gets all items in a quadTree and pours them into an empty quadTree. Useful if the items in the quadTree find themselves in the wrong leaves.
isValid : QuadTree units coordinates (Bounded units coordinates a) -> Result Error ()