Constructor
new Grid()
- Description:
- Creates a new two-dimensional grid.
- Source:
Example
const grid = new Grid();
grid.set(position, data);
grid.traverse(aabb, handler);
Methods
clear() → {this}
- Description:
- Clears the grid.
- Source:
Returns:
- Type
- this
delete($position) → {this}
- Description:
- Deletes the data from the given position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The position to delete the data from. |
Returns:
- Type
- this
get($position) → {TypeGeneric}
- Description:
- Gets the data from the given position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The position to get the data from. |
Returns:
- Type
- TypeGeneric
has($position) → {boolean}
- Description:
- Checks if the given position stores any data.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The given position to check. |
Returns:
- Type
- boolean
iterate($handler)
- Description:
- Iterates through the grid applying the given handler.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$handler |
TypeHandlerTraverse | The handler to apply to each cell in the sector. |
set($position, $data) → {this}
- Description:
- Sets the given data to the given position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The position to set the data to (with integer values). |
$data |
TypeGeneric | The data to set. |
Returns:
- Type
- this
traverse($aabb, $handler)
- Description:
- Traverses the given sector applying the given handler.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$aabb |
AABB | The sector to traverse (with integer boundaries). |
$handler |
TypeHandlerTraverse | The handler to apply to each cell in the sector. |
Type Definitions
(protected) TypeHandlerTraverse($parameters) → {void}
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$parameters |
object | The given parameters. |
$parameters.$data |
TypeGeneric | The data of the cell. |
$parameters.$grid |
Grid.<TypeGeneric> | The reference grid. |
$parameters.$position |
Vector2 | The position of the cell. |
$parameters.$terminate |
TypeHandlerTraverseTerminate | Terminates the traversal of the grid. |
Returns:
- Type
- void
(protected) TypeHandlerTraverseTerminate() → {void}
- Source:
Returns:
- Type
- void