query method

List query(
  1. Vector3 position,
  2. double radius,
  3. List result
)

Performs a query to the spatial index according the the given position and radius. The method approximates the query position and radius with an AABB and then performs an intersection test with all non-empty cells in order to determine relevant partitions. Stores the result in the given result array.

Implementation

List query(Vector3 position, double radius, List result ) {
	final cells = this.cells;

	result.length = 0;

	// approximate range with an AABB which allows fast intersection test
	aabb.min.copy( position ).subScalar( radius );
	aabb.max.copy( position ).addScalar( radius );

	// test all non-empty cells for an intersection
	for ( int i = 0, l = cells.length; i < l; i ++ ) {
		final cell = cells[ i ];

		if ( cell.empty() == false && cell.intersects( aabb ) == true ) {
			result.addAll( cell.entries );
		}
	}

	return result;
}