pub struct AABBGrid<O: Copy, AB: AABB> { /* private fields */ }
Expand description

ShapeGrid is a generic aabb-based spatial partitioning structure that uses a generic storage of cells which acts as a grid instead of a tree.

Fast queries

In theory, ShapeGrid should be faster than a quadtree/r-tree because it has no log costs (calculating the cells around a point is trivial).
However, it only works if the cell size is adapted to the problem, much like how a tree has to be balanced to be efficient.

Dynamicity

ShapeGrid's allows eager removals and position updates, however for big aabbs (spanning many cells) this can be expensive, so beware.

Use this grid for mostly static objects with the occasional removal/position update if needed.

A SlotMap is used for objects managing, adding a level of indirection between aabbs and objects. SlotMap is used because removal doesn’t alter handles given to the user, while still having constant time access. However it requires O to be copy, but SlotMap's author stated that they were working on a similar map where Copy isn’t required.

About object management

In theory, you don’t have to use the object management directly, you can make your custom Handle -> Object map by specifying “()” to be the object type. (This can be useful if your object is not Copy) Since () is zero sized, it should probably optimize away a lot of the object management code.

use flat_spatial::AABBGrid;
use euclid::default::Rect;

let mut g: AABBGrid<(), Rect<f32>> = AABBGrid::new(10);
let handle = g.insert(Rect::new([0.0, 0.0].into(), [10.0, 10.0].into()), ());
// Use handle however you want

Implementations

Creates an empty grid. The cell size should be about the same magnitude as your queries size.

Clears the grid.

Inserts a new object with a position and an associated object Returns the unique and stable handle to be used with get_obj

Updates the aabb of an object.

Removes an object from the grid.

Iterate over all handles

Iterate over all objects

Returns a reference to the associated object and its position, using the handle.

Returns a mutable reference to the associated object and its position, using the handle.

The underlying storage

Queries for objects intersecting a given AABB.

Queries for all objects in the cells intersecting the given AABB

Queries for objects intersecting a given AABB. Uses a visitor for slightly better performance.

Queries for all objects in the cells intersecting the given AABB Uses a visitor for slightly better performance.

Returns the number of objects currently available

Checks if the grid contains objects or not

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.