Import std.collections.spatial
std.collections.spatial
SpatialHash<T>, QuadTree<T>, and Octree<T>: values at points, found by where they are, the
ones in a box or near a point, without going over the others. A SpatialHash keeps the points in
square cells of a size, for things spread over a world of any size; a QuadTree splits its bounds
in four where points crowd, and an Octree, in 3D, in eight. A box holds the points on its edges,
a point near another is no more than the radius from it, so a negative or NaN radius finds
nothing and an infinite one finds everything, and what's found comes in no order to count on. A
coordinate that's NaN panics. Distances and boxes are worked out in Doubles, so no Float
overflows on the way.
std/collections/spatial.fb
Types
SpatialHash
class
@DebugElements Public Class SpatialHash<T> Implements Iterable<T>, Cloneable
Values at 2D points, kept in square cells of a size, for things spread over a world of any size.
std/collections/spatial.fb, line 104
-
An empty SpatialHash whose cells are
sizeacross, which has to be above 0 and finite. -
How many values it holds.
-
Adds the
valueat (x,y). -
Removes the first
valueequal tovalueat (x,y), and tells whether there was one. -
Whether a value equal to
valueis at (x,y). -
@PanicsAtCaller Public Method Move(value: T, x: Float, y: Float, toX: Float, toY: Float): Boolmethod #Moves the first
valueequal tovalueat (x,y) to (toX,toY), and tells whether there was one. -
Takes every value out.
-
@PanicsAtCaller Public Method Query(minX: Float, minY: Float, maxX: Float, maxY: Float): T[]method #The values in the box from (
minX,minY) to (maxX,maxY), in a new array. -
The values no more than
radiusfrom (x,y), in a new array. -
Every value, in a new array.
-
A new SpatialHash with the same cells and values at the same points.
-
Every value. Adding or removing one while going over them panics.
SpatialIterator
struct
Public Struct SpatialIterator<T> Implements Iterator<T>
The values of a SpatialHash, a QuadTree, or an Octree, from a copy made when the loop began, with what the collection has changed by, which a change that panics is the only one to reach.
std/collections/spatial.fb, line 281
-
The next value, or Null when there are no more.
Doc from
std.core.iterator.Iterator.Next.
QuadTree
class
@DebugElements Public Class QuadTree<T> Implements Iterable<T>, Cloneable
Values at 2D points, in bounds it splits in four where points crowd.
std/collections/spatial.fb, line 533
-
An empty QuadTree for the points in the box from (
minX,minY) to (maxX,maxY), which has to be finite. A box whose max is below its min along an axis panics. -
How many values it holds.
-
Adds the
valueat (x,y). A point outside the QuadTree's box panics. -
Removes the first
valueequal tovalueat (x,y), and tells whether there was one. -
Whether a value equal to
valueis at (x,y). -
@PanicsAtCaller Public Method Move(value: T, x: Float, y: Float, toX: Float, toY: Float): Boolmethod #Moves the first
valueequal tovalueat (x,y) to (toX,toY), and tells whether there was one. A point outside the QuadTree's box panics. -
Takes every value out.
-
@PanicsAtCaller Public Method Query(minX: Float, minY: Float, maxX: Float, maxY: Float): T[]method #The values in the box from (
minX,minY) to (maxX,maxY), in a new array. -
The values no more than
radiusfrom (x,y), in a new array. -
Every value, in a new array.
-
A new QuadTree with the same box and values at the same points.
-
Every value. Adding or removing one while going over them panics.
Octree
class
@DebugElements Public Class Octree<T> Implements Iterable<T>, Cloneable
Values at 3D points, in bounds it splits in eight where points crowd.
std/collections/spatial.fb, line 612
-
@PanicsAtCaller Public New(minX: Float, minY: Float, minZ: Float, maxX: Float, maxY: Float, maxZ: Float)constructor #An empty Octree for the points in the box from (
minX,minY,minZ) to (maxX,maxY,maxZ), which has to be finite. A box whose max is below its min along an axis panics. -
How many values it holds.
-
Adds the
valueat (x,y,z). A point outside the Octree's box panics. -
Removes the first
valueequal tovalueat (x,y,z), and tells whether there was one. -
Whether a value equal to
valueis at (x,y,z). -
@PanicsAtCaller Public Method Move(value: T, x: Float, y: Float, z: Float, toX: Float, toY: Float, toZ: Float): Boolmethod #Moves the first
valueequal tovalueat (x,y,z) to (toX,toY,toZ), and tells whether there was one. A point outside the Octree's box panics. -
Takes every value out.
-
@PanicsAtCaller Public Method Query(minX: Float, minY: Float, minZ: Float, maxX: Float, maxY: Float, maxZ: Float): T[]method #The values in the box from (
minX,minY,minZ) to (maxX,maxY,maxZ), in a new array. -
The values no more than
radiusfrom (x,y,z), in a new array. -
Every value, in a new array.
-
A new Octree with the same box and values at the same points.
-
Every value. Adding or removing one while going over them panics.
Report an issue with this page or with FutureBlitz on GitHub.