[−][src]Trait zvxryb_broadphase::SpatialIndex
An index representing an object's position and scale
The Ord
trait must be implemented such that sorting produces a topological ordering.
This may be accomplished using trivial comparison operators for a primitive integer type by:
- Packing bits such that
origin
is higher-significance thandepth
- Storing the value of
origin
as a Morton code - Truncating
origin
bits to the level specified bydepth
, such that it represents the minimum bound of the cell at the given scale
Currently, requirement #3 (truncating origin) is not the responsibility of the particular SpatialIndex
implementation — an appropriately-truncated value must be passed as an argument to set_origin
Ord
should be implemented such that an X-bit is lower significance (changes more rapidly) than the
corresponding a Y-bit (which should, likewise, be lower significance than the corresponding Z-bit for
3D indices)
<SpatialIndex as Default>::default()
is required to return an index which encompasses the entire system
bounds (i.e. zero origin and zero depth)
Associated Types
type Diff: VectorSpace<Scalar = u32>
type Point: Copy + EuclideanSpace<Diff = Self::Diff, Scalar = u32>
type SubdivideResult: AsRef<[Self]>
Required methods
fn clamp_depth(_: u32) -> u32
clamps a depth value to the representable range
fn origin(self) -> Self::Point
fn depth(self) -> u32
fn set_origin(self, _: Self::Point) -> Self
fn set_depth(self, _: u32) -> Self
fn subdivide(self) -> Option<Self::SubdivideResult>
Subdivide the cell represented by this index into cells of depth + 1
This is required to return results in sorted order. Returns None
if depth limit has been reached.
fn overlaps(self, other: Self) -> bool
Check if two indices represent overlapping regions of space
fn same_cell_at_depth(lhs: Self, rhs: Self, depth: u32) -> bool
Check if two indices would fall into the same cell at a given (truncated) depth