Constructor
new Grid(size)
Creates an empty grid
Name | Type | Default | Description |
---|---|---|---|
size | number | 2000 | Size of each grid cell |
- Source
Members
grid :Object
Grid cells. You can access grid cells with grid.grid[id]
, with id
being the grid cell id corresponding to the x/y position of the cell. You can find the grid cell id with grid.pair(cellPosition)
- Object
- Source
gridIds :Set
Set of all created grid ids
- Set
- Source
gridSize :number
The grid size
- number
- Source
Methods
pair(pos) → {Number}
Takes a cell position and returns the corresponding grid cell id
Name | Type | Description |
---|---|---|
pos | vec |
- Source
grid cell id
- Type:
- Number
unpair(n) → {vec}
Takes a grid cell id and returns the corresponding cell position
Name | Type | Description |
---|---|---|
n | Number | Grid cell id |
- Source
Cell position
- Type:
- vec
getBounds(body) → {Bounds}
Takes a body with a bounding box and returns the range of grid cells that the body is in
Name | Type | Description |
---|---|---|
body | RigidBody | | the RigidBody, global space vec, or global space bounds to convert to grid space Bounds |
- Source
Grid space bounds
- Type:
- Bounds
getBucketIds(bounds) → {Array.<Number>}
Takes grid-space bounds and returns an array of all bucket ids within those bounds
Name | Type | Description |
---|---|---|
bounds | Bounds | Bounding box in form of |
- Source
Array of grid cell ids
- Type:
- Array.<Number>
getBuckets(bounds)
Takes global-space bounds and returns an array of all buckets in those bounds
Name | Type | Description |
---|---|---|
bounds | * |
- Source
addBody(body)
Adds the body to the grid
Name | Type | Description |
---|---|---|
body | RigidBody | Body added to the grid |
- Source
removeBody(body)
Removes the body from the grid
Name | Type | Description |
---|---|---|
body | RigidBody | Body removed from the grid |
- Source
addPoint(point)
Adds a vector point to the grid
Name | Type | Description |
---|---|---|
point | vec | Point added |
- Source
removePoint(point)
Remove a vector point from the grid
Name | Type | Description |
---|---|---|
point | vec | Point removed |
- Source
updateBody(body)
Updates the body's position in the grid
- Source