hashbounds
Version:
Collision detection optimized 2d datastructure for usage in games
786 lines (482 loc) • 29.8 kB
Markdown
[](https://www.npmjs.com/package/hashbounds)
[](https://ajs-development.github.io/HashBounds/dist/visual/)
# HashBounds
Collision detection optimized 2d datastructure for usage in games. Particularily useful when:
* Objects have varying sizes
* Objects are continually moving
* Map size is not determinable/fixed at start
# Usage
> npm install hashbounds@5
```js
const HashBounds = require("hashbounds");
// Initialize hashbounds with min grid size of 16 and 3 levels and pre-initialize buckets in 1000x1000 map.
let myData = new HashBounds(16, 3, {
x: 0,
y: 0,
width: 1000,
height: 1000
});
// You don't have to pre-initialize buckets
myData = new HashBounds(16, 3);
// An entry is some sort of object
const entry = {
foo: "bar"
}
// Insert an entry
myData.insert(entry, {
x: 0,
y: 0,
width: 10,
height: 10
});
// Get array at bounds
myData.toArray({ x: 0, y: 0, width: 5, height: 5 }).length // 1
// Iterate at bounds
myData.forEach({ x: 0, y: 0, width: 5, height: 5 }, (item)=>{
});
// Iterate at bounds cancellable
myData.every({ x: 0, y: 0, width: 5, height: 5 }, (item)=>{
return true; // True to continue iteration
});
// Update the entry's bounds
myData.update(entry, {
x: 10,
y: 10,
width: 3,
height: 4
});
// You can also use min/max format for all bounds.
myData.update(entry, {
minX: 10,
minY: 10,
maxX: 13,
maxY: 14
});
// Remove entry
myData.remove(entry);
```
# API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
* [BoundsPS](#boundsps)
* [Properties](#properties)
* [BoundsMM](#boundsmm)
* [Properties](#properties-1)
* [Bounds](#bounds)
* [Entry](#entry)
* [EntryCache](#entrycache)
* [ForEachCallback](#foreachcallback)
* [Parameters](#parameters)
* [EveryCallback](#everycallback)
* [Parameters](#parameters-1)
* [HashBounds](#hashbounds)
* [Parameters](#parameters-2)
* [getQueryID](#getqueryid)
* [setupLog2](#setuplog2)
* [createLevels](#createlevels)
* [initializeArea](#initializearea)
* [Parameters](#parameters-3)
* [init](#init)
* [clear](#clear)
* [prune](#prune)
* [update](#update)
* [Parameters](#parameters-4)
* [getLevel](#getlevel)
* [Parameters](#parameters-5)
* [insert](#insert)
* [Parameters](#parameters-6)
* [remove](#remove)
* [Parameters](#parameters-7)
* [contains](#contains)
* [Parameters](#parameters-8)
* [getHashCache](#gethashcache)
* [Parameters](#parameters-9)
* [toArray](#toarray)
* [Parameters](#parameters-10)
* [every](#every)
* [Parameters](#parameters-11)
* [forEach](#foreach)
* [Parameters](#parameters-12)
* [boundsFitsInHash](#boundsfitsinhash)
* [Parameters](#parameters-13)
* [mmToPS](#mmtops)
* [Parameters](#parameters-14)
* [psToMM](#pstomm)
* [Parameters](#parameters-15)
* [boundsOverlap](#boundsoverlap)
* [Parameters](#parameters-16)
* [boundsContains](#boundscontains)
* [Parameters](#parameters-17)
* [truncateBounds](#truncatebounds)
* [Parameters](#parameters-18)
* [convertBounds](#convertbounds)
* [Parameters](#parameters-19)
* [HashGrid](#hashgrid)
* [Parameters](#parameters-20)
* [initializeArea](#initializearea-1)
* [Parameters](#parameters-21)
* [deleteBucket](#deletebucket)
* [Parameters](#parameters-22)
* [setBucket](#setbucket)
* [Parameters](#parameters-23)
* [getBucket](#getbucket)
* [Parameters](#parameters-24)
* [createBucket](#createbucket)
* [Parameters](#parameters-25)
* [prune](#prune-1)
* [pruneBucket](#prunebucket)
* [Parameters](#parameters-26)
* [update](#update-1)
* [Parameters](#parameters-27)
* [insert](#insert-1)
* [Parameters](#parameters-28)
* [remove](#remove-1)
* [Parameters](#parameters-29)
* [every](#every-1)
* [Parameters](#parameters-30)
* [TreeBucket](#treebucket)
* [Parameters](#parameters-31)
* [updateQuadCache](#updatequadcache)
* [add](#add)
* [subtract](#subtract)
* [getQuad](#getquad)
* [Parameters](#parameters-32)
* [\_every](#\_every)
* [Parameters](#parameters-33)
* [every](#every-2)
* [Parameters](#parameters-34)
* [everyAll](#everyall)
* [Parameters](#parameters-35)
* [remove](#remove-2)
* [Parameters](#parameters-36)
* [set](#set)
* [Parameters](#parameters-37)
## BoundsPS
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L26-L33 "Source code on GitHub")
A 2d bounding box represented by a point and sizes.
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
### Properties
* `x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `width` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `height` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
## BoundsMM
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L35-L42 "Source code on GitHub")
A 2d bounding box represented by min/max points.
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
### Properties
* `minX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `minY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `maxX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `maxY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
## Bounds
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L44-L47 "Source code on GitHub")
An object representing a 2d bounding box.
Type: ([BoundsPS](#boundsps) | [BoundsMM](#boundsmm))
## Entry
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L49-L52 "Source code on GitHub")
Represents an entry
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
## EntryCache
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L54-L57 "Source code on GitHub")
Represents an entry's cache object
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
## ForEachCallback
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L59-L63 "Source code on GitHub")
Callback function used in .forEach() calls
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
### Parameters
* `entry` **[Entry](#entry)** Entry
## EveryCallback
[src/HashBounds.js:72-72](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L65-L70 "Source code on GitHub")
Callback function used in .every() calls
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
### Parameters
* `entry` **[Entry](#entry)** Entry
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Return true to continue iteration, false to cancel.
## HashBounds
[src/HashBounds.js:80-361](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L80-L361 "Source code on GitHub")
HashBounds
Stores/Organizes arbitrary objects with 2d bounding box data in the form of a spatial grid tree that is quick to query.
It is particularily efficient when objects have varying sizes. Constant time insertion and removal, and n log n search.
### Parameters
* `minSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The size of the smallest grid cell.
* `levelCount` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Specifies the number of levels/depth. Each additional level has a grid size twice as large then the previous in one axis, 4x size in area.
* `initialBounds` **[Bounds](#bounds)?** Optionally specifies the bounds used to pre-initilize the datastructure. These bounds are not enforced.
* `id` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Optionally specify a unique ID of the hash.
### getQueryID
[src/HashBounds.js:113-119](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L113-L119 "Source code on GitHub")
Returns an incremented number used to filter non-unique entries during search queries.
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
### setupLog2
[src/HashBounds.js:124-131](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L124-L131 "Source code on GitHub")
Initializes a dictionary of ceiled log2 values that are frequently used by the data structure
### createLevels
[src/HashBounds.js:136-150](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L136-L150 "Source code on GitHub")
Initializes the basic hierarchical structure of levels.
### initializeArea
[src/HashBounds.js:155-157](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L155-L157 "Source code on GitHub")
Pre-initializes an area according to some bounds
#### Parameters
* `initialBounds`
### init
[src/HashBounds.js:162-165](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L162-L165 "Source code on GitHub")
Initializes the data structure and pre-initializes area if applicable
### clear
[src/HashBounds.js:170-174](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L170-L174 "Source code on GitHub")
Clear the data structure and reinitialize it.
### prune
[src/HashBounds.js:179-181](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L179-L181 "Source code on GitHub")
Removes empty buckets.
### update
[src/HashBounds.js:191-207](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L191-L207 "Source code on GitHub")
Updates the entry when its bounds have changed.
#### Parameters
* `entry` **[Entry](#entry)** The entry to update.
* `bounds` **[Bounds](#bounds)** The 2d bounding box of the entry.
<!---->
* Throws **any** Will throw an error if the entry is not present.
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** A boolean value that is true to indicate something has changed
### getLevel
[src/HashBounds.js:216-229](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L216-L229 "Source code on GitHub")
Gets the level index the entry should belong to with the appropriate bounding box.
#### Parameters
* `bounds` **[Bounds](#bounds)** The 2d bounding box of the entry.
* `entryCache` **[EntryCache](#entrycache)** Cache object
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the level.
### insert
[src/HashBounds.js:238-264](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L238-L264 "Source code on GitHub")
Inserts a entry with a specified 2d bounding box.
#### Parameters
* `entry` **[Entry](#entry)** The entry to insert.
* `bounds` **[Bounds](#bounds)** The 2d bounding box of the entry.
<!---->
* Throws **any** Will throw an error if the entry is already present.
### remove
[src/HashBounds.js:272-277](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L272-L277 "Source code on GitHub")
Removes an entry.
#### Parameters
* `entry` **[Entry](#entry)** The entry to remove.
<!---->
* Throws **any** Will throw an error if the entry is not present.
### contains
[src/HashBounds.js:284-286](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L284-L286 "Source code on GitHub")
Returns true if the entry is present.
#### Parameters
* `entry` **[Entry](#entry)**
Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### getHashCache
[src/HashBounds.js:293-295](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L293-L295 "Source code on GitHub")
Returns the cache object from a entry
#### Parameters
* `entry` **[Entry](#entry)**
Returns **[EntryCache](#entrycache)**
### toArray
[src/HashBounds.js:302-312](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L302-L312 "Source code on GitHub")
Retrieves an array of unique entries that may overlap with a 2d bounding box.
#### Parameters
* `bounds` **[Bounds](#bounds)?** A 2d bounding box to search.
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** An array of entries.
### every
[src/HashBounds.js:323-330](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L323-L330 "Source code on GitHub")
Iterates through unique entries that may overlap with a 2d bounding box. Iteration may be stopped.
Similar to Array.every
#### Parameters
* `bounds` **[Bounds](#bounds)?** A 2d bounding box to search.
* `call` **[EveryCallback](#everycallback)** A callback function with the first argument indicating the entry. Return true to continue iteration, return false to stop.
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns false if cancelled.
### forEach
[src/HashBounds.js:340-350](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L340-L350 "Source code on GitHub")
Iterates through unique entries that may overlap with a 2d bounding box. Iteration cannot be stopped.
Similar to Array.forEach
#### Parameters
* `bounds` **[Bounds](#bounds)?** A 2d bounding box to search.
* `call` **[ForEachCallback](#foreachcallback)** A callback function with the first argument indicating the entry.
### boundsFitsInHash
[src/HashBounds.js:357-360](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L357-L360 "Source code on GitHub")
Check if bounds exceeds the pre-initialized size of the datastructure
#### Parameters
* `bounds` **[Bounds](#bounds)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### mmToPS
[src/HashBounds.js:368-373](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L368-L373 "Source code on GitHub")
Converts a min-max 2d bound to pos-size format in place
#### Parameters
* `bounds` **[Bounds](#bounds)**
### psToMM
[src/HashBounds.js:379-385](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L379-L385 "Source code on GitHub")
Converts a pos-size 2d bound to min-max format in place
#### Parameters
* `bounds` **[Bounds](#bounds)**
### boundsOverlap
[src/HashBounds.js:393-395](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L393-L395 "Source code on GitHub")
Checks if two 2d bounding boxes are overlapping.
#### Parameters
* `bounds1` **[Bounds](#bounds)**
* `bounds2` **[Bounds](#bounds)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### boundsContains
[src/HashBounds.js:403-405](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L403-L405 "Source code on GitHub")
Checks if one 2d bounding box is fully contained in another.
#### Parameters
* `bounds1` **[Bounds](#bounds)** Inner box
* `bounds2` **[Bounds](#bounds)** Outer box
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### truncateBounds
[src/HashBounds.js:416-435](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L416-L435 "Source code on GitHub")
Truncates bounds to fit a certain area
#### Parameters
* `bounds` **[Bounds](#bounds)**
* `minX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `minY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `maxX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `maxY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
<!---->
* Throws **any** Will throw error if bounds are unformatted.
### convertBounds
[src/HashBounds.js:442-458](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashBounds.js#L442-L458 "Source code on GitHub")
Formats/converts 2d bounding boxes.
#### Parameters
* `bounds` **[Bounds](#bounds)**
<!---->
* Throws **any** Error if invalid
## HashGrid
[src/HashGrid.js:34-302](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L34-L302 "Source code on GitHub")
HashGrid.
A doubly linked 2d spatial hash/grid which stores TreeBuckets. Multiple grids are typically used by HashBounds.
Allows for constant time insertion and deletion by using Math.floor(X / gridSize).
### Parameters
* `bucketSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The size of the buckets
* `level` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The level/index of the grid. Higher levels have double the bucketSize than the preceding.
### initializeArea
[src/HashGrid.js:53-64](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L53-L64 "Source code on GitHub")
Pre-initializes buckets in a 2d bounding box. While these bounds are not strictly enforced for entries, pre-initialization will increase performance.
#### Parameters
* `initialBounds` **[Bounds](#bounds)** Bounds to initialize area with.
### deleteBucket
[src/HashGrid.js:71-77](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L71-L77 "Source code on GitHub")
Deletes a bucket from the bucket grid.
#### Parameters
* `bucketX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucketY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
### setBucket
[src/HashGrid.js:85-92](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L85-L92 "Source code on GitHub")
Inserts a bucket into the bucket grid.
#### Parameters
* `bucketX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucketY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucket` **[TreeBucket](#treebucket)**
### getBucket
[src/HashGrid.js:100-103](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L100-L103 "Source code on GitHub")
Gets a bucket from the bucket grid
#### Parameters
* `bucketX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucketY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[TreeBucket](#treebucket)**
### createBucket
[src/HashGrid.js:111-135](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L111-L135 "Source code on GitHub")
Creates, initializes, and returns a bucket at a certain position. Any parent buckets will be created.
#### Parameters
* `bucketX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucketY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[TreeBucket](#treebucket)**
### prune
[src/HashGrid.js:140-150](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L140-L150 "Source code on GitHub")
Prunes empty buckets.
### pruneBucket
[src/HashGrid.js:156-169](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L156-L169 "Source code on GitHub")
Prunes an empty bucket and its empty parents.
#### Parameters
* `bucket` **[TreeBucket](#treebucket)**
### update
[src/HashGrid.js:178-196](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L178-L196 "Source code on GitHub")
Updates a entry.
#### Parameters
* `entry` **[Entry](#entry)**
* `bounds` **[Bounds](#bounds)**
* `entryCache` **[EntryCache](#entrycache)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true if there was a change.
### insert
[src/HashGrid.js:208-239](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L208-L239 "Source code on GitHub")
Inserts a entry.
#### Parameters
* `entry` **[Entry](#entry)**
* `bounds` **[Bounds](#bounds)**
* `entryCache` **[EntryCache](#entrycache)**
* `k1x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
* `k1y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
* `k2x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
* `k2y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
### remove
[src/HashGrid.js:245-257](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L245-L257 "Source code on GitHub")
Removes a entry.
#### Parameters
* `entryCache` **[EntryCache](#entrycache)**
### every
[src/HashGrid.js:268-301](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/HashGrid.js#L268-L301 "Source code on GitHub")
Iterates entries that may overlap with bounds. Cancellable.
Similar to Array.every()
#### Parameters
* `bounds` **([Bounds](#bounds) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**
* `call` **[EveryCallback](#everycallback)**
* `QID` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
## TreeBucket
[src/TreeBucket.js:31-221](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L31-L221 "Source code on GitHub")
TreeBucket.
The class that actually contains the data
### Parameters
* `bucketX` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucketY` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
* `bucketSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
### updateQuadCache
[src/TreeBucket.js:64-76](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L64-L76 "Source code on GitHub")
Update QuadCache with appropriate child buckets.
### add
[src/TreeBucket.js:81-84](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L81-L84 "Source code on GitHub")
Increments a counter and propagates it upwards.
### subtract
[src/TreeBucket.js:89-92](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L89-L92 "Source code on GitHub")
Decrements a counter and propagates it upwards.
### getQuad
[src/TreeBucket.js:99-135](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L99-L135 "Source code on GitHub")
Returns the quads that collide with the bounding box. Returns -1 if bounds is completely enclosing bucket.
#### Parameters
* `bounds` **[Bounds](#bounds)**
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
### \_every
[src/TreeBucket.js:145-153](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L145-L153 "Source code on GitHub")
Internal method that iterates through the items contained in the bucket while filtering non-unique entries.
Similar to Array.every();
#### Parameters
* `call` **[EveryCallback](#everycallback)**
* `QID` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### every
[src/TreeBucket.js:162-173](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L162-L173 "Source code on GitHub")
Recursive method that iterates through entries that may collide with the specified bounds.
#### Parameters
* `bounds` **[Bounds](#bounds)**
* `call` **[EveryCallback](#everycallback)**
* `QID` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### everyAll
[src/TreeBucket.js:181-189](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L181-L189 "Source code on GitHub")
Recursive method that iterates through all entries contained in this bucket and its children.
#### Parameters
* `call` **[EveryCallback](#everycallback)**
* `QID` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
### remove
[src/TreeBucket.js:196-207](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L196-L207 "Source code on GitHub")
Removes a entry
#### Parameters
* `entryCache` **[EntryCache](#entrycache)**
* `indexKey` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
### set
[src/TreeBucket.js:215-220](https://andrews54757@github.com/AJS-development/HashBounds/blob/340acee586495137485ad37ab378f2a2ad178c8c/src/TreeBucket.js#L215-L220 "Source code on GitHub")
Sets a entry
#### Parameters
* `entry` **[Entry](#entry)**
* `entryCache` **[EntryCache](#entrycache)**
* `indexKey` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**