Skip to main content

SpatialIndex

Trait SpatialIndex 

Source
pub trait SpatialIndex:
    Clone
    + Copy
    + Default
    + Ord
    + Send
    + Debug {
    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;
    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>;
    fn overlaps(self, other: Self) -> bool;
    fn same_cell_at_depth(lhs: Self, rhs: Self, depth: u32) -> bool;
}
Expand description

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:

  1. Packing bits such that origin is higher-significance than depth
  2. Storing the value of origin as a Morton code
  3. Truncating origin bits to the level specified by depth, 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)

The following index types are provided:

  • Index32_2D: A 32-bit 2D index type providing 14 bits’ precision per axis
  • Index64_2D: A 64-bit 2D index type providing 29 bits’ precision per axis
  • Index64_3D: A 64-bit 3D index type providing 19 bits’ precision per axis

Required Associated Types§

Source

type Diff: VectorSpace<Scalar = u32>

Source

type Point: Copy + EuclideanSpace<Diff = Self::Diff, Scalar = u32>

Source

type SubdivideResult: AsRef<[Self]>

Required Methods§

Source

fn clamp_depth(_: u32) -> u32

clamps a depth value to the representable range

Source

fn origin(self) -> Self::Point

Source

fn depth(self) -> u32

Source

fn set_origin(self, _: Self::Point) -> Self

Source

fn set_depth(self, _: u32) -> Self

Source

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.

Source

fn overlaps(self, other: Self) -> bool

Check if two indices represent overlapping regions of space

Source

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§