1681-engine / index / SpatialHash
Class: SpatialHash ​
Defined in: src/net/SpatialHash.ts:16
Points sorted into square cells, for asking who is near a spot without looking at everyone: a room's interest management, a server's hit test. Moving a point within its cell costs a write; across cells, a set delete and add. Pure and transport-free, so the same class serves the client.
Constructors ​
Constructor ​
new SpatialHash(cellSize): SpatialHash;Defined in: src/net/SpatialHash.ts:21
cellSize: world px per cell. About the radius queries ask for keeps a query to a 3×3 block.
Parameters ​
| Parameter | Type |
|---|---|
cellSize | number |
Returns ​
SpatialHash
Properties ​
cellSize ​
readonly cellSize: number;Defined in: src/net/SpatialHash.ts:21
Accessors ​
size ​
Get Signature ​
get size(): number;Defined in: src/net/SpatialHash.ts:25
Returns ​
number
Methods ​
clear() ​
clear(): void;Defined in: src/net/SpatialHash.ts:56
Returns ​
void
delete() ​
delete(id): void;Defined in: src/net/SpatialHash.ts:49
Parameters ​
| Parameter | Type |
|---|---|
id | number |
Returns ​
void
has() ​
has(id): boolean;Defined in: src/net/SpatialHash.ts:29
Parameters ​
| Parameter | Type |
|---|---|
id | number |
Returns ​
boolean
inRect() ​
inRect(
x0,
y0,
x1,
y1,
out?
): number[];Defined in: src/net/SpatialHash.ts:73
The ids inside the box from (x0, y0) to (x1, y1), edges included.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
x0 | number | undefined |
y0 | number | undefined |
x1 | number | undefined |
y1 | number | undefined |
out | number[] | [] |
Returns ​
number[]
near() ​
near(
x,
y,
radius,
out?
): number[];Defined in: src/net/SpatialHash.ts:62
The ids within radius of (x, y), edge included, pushed onto out in no set order.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
x | number | undefined |
y | number | undefined |
radius | number | undefined |
out | number[] | [] |
Returns ​
number[]
set() ​
set(
id,
x,
y
): void;Defined in: src/net/SpatialHash.ts:34
Puts id at (x, y), or moves it there.
Parameters ​
| Parameter | Type |
|---|---|
id | number |
x | number |
y | number |
Returns ​
void