Skip to main content

SimdIndex2D

Struct SimdIndex2D 

Source
pub struct SimdIndex2D { /* private fields */ }
Available on crate feature simd only.
Expand description

Finished read-only SIMD index.

Created through Index2DBuilder::finish_simd. It has the same public search and nearest-neighbor API as Index2D, but stores box coordinates in structure-of-arrays form for SIMD traversal.

§Example

use packed_spatial_index::{Index2DBuilder, Box2D};

let mut builder = Index2DBuilder::new(1);
builder.add(Box2D::new(0.0, 0.0, 1.0, 1.0));

let index = builder.finish_simd().unwrap();
assert_eq!(index.search(Box2D::new(0.5, 0.5, 0.5, 0.5)), vec![0]);

Implementations§

Source§

impl SimdIndex2D

Source

pub fn raycast_closest_with( &self, ray: Ray2D, workspace: &mut NeighborWorkspace, ) -> Option<(usize, f64)>

SoA/SIMD ordered closest-hit raycast (2D). Same result as Index2D::raycast_closest_with, with the slab test evaluated four (or eight, on AVX-512) children at a time.

Axis-parallel rays are handled by the wide::f64x4 path with a masked slab test to avoid 0 * inf = NaN at box faces.

Source

pub fn raycast_closest(&self, ray: Ray2D) -> Option<(usize, f64)>

Return the nearest item whose box the ray segment enters, as (item index, entry t), or None when the segment hits nothing.

Nodes are visited front-to-back by entry distance and pruned once a closer hit is known, so the cost is roughly independent of max_distance after the first hit. t is 0.0 when the ray origin starts inside the item’s box.

Source

pub fn raycast(&self, ray: Ray2D) -> Vec<usize>

Return the indices of all items whose boxes the ray segment touches.

Source

pub fn raycast_into(&self, ray: Ray2D, results: &mut Vec<usize>)

Raycast with a reusable result buffer.

Source

pub fn raycast_with<'a>( &self, ray: Ray2D, workspace: &'a mut SearchWorkspace, ) -> &'a [usize]

Raycast with reusable result and traversal buffers.

Source§

impl SimdIndex2D

Source

pub fn visit_raycast<B, F>(&self, ray: Ray2D, visitor: F) -> ControlFlow<B>
where F: FnMut(usize, f64) -> ControlFlow<B>,

Visit items in nondecreasing entry-t order along the ray segment.

The visitor receives (item index, entry t). Return ControlFlow::Break to stop early - for example after the first N occluders. t is 0.0 when the ray origin starts inside a box.

Source§

impl SimdIndex2D

Source

pub fn to_bytes(&self) -> Vec<u8>

Serialize into the stable little-endian PSINDEX format.

The output is byte-identical to Index2D::to_bytes for the same items, so a SimdIndex2D and an Index2D are interchangeable on disk: either can load bytes produced by the other.

Source

pub fn to_bytes_into(&self, out: &mut Vec<u8>)

Serialize into a caller-provided buffer, reusing its allocation.

Equivalent to to_bytes but writes into out (cleared first).

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, LoadError>

Load a SIMD index from bytes produced by to_bytes or by Index2D::to_bytes; the AoS box records are scattered into the structure-of-arrays columns.

Source§

impl SimdIndex2D

Source

pub fn num_items(&self) -> usize

Number of indexed items.

Source

pub fn extent(&self) -> Option<Box2D>

Return the total extent of indexed items, or None for an empty index.

Source

pub fn node_size(&self) -> usize

Return the packed node size used by this index.

Source

pub fn search(&self, query: Box2D) -> Vec<usize>

Return the indices of all items whose boxes intersect query.

Source

pub fn search_into(&self, query: Box2D, out: &mut Vec<usize>)

Search with a reusable result buffer.

This automatically dispatches to the widest available kernel at runtime: AVX-512 (VPCOMPRESSQ collection), then an explicit AVX2 tier (left-pack collection), then the SSE2 wide fallback.

Source

pub fn search_with<'a>( &self, query: Box2D, workspace: &'a mut SearchWorkspace, ) -> &'a [usize]

Search with reusable result and traversal buffers.

Source

pub fn any(&self, query: Box2D) -> bool

Return true if at least one item intersects query.

Source

pub fn first(&self, query: Box2D) -> Option<usize>

Return one intersecting item, if any.

Source

pub fn neighbors(&self, point: Point2D, max_results: usize) -> Vec<usize>

Return up to max_results item indices nearest to point.

Source

pub fn neighbors_within( &self, point: Point2D, max_results: usize, max_distance: f64, ) -> Vec<usize>

Return up to max_results item indices within max_distance of point.

Source

pub fn neighbors_into( &self, point: Point2D, max_results: usize, max_distance: f64, results: &mut Vec<usize>, )

Nearest-neighbor search with a reusable result buffer.

Source

pub fn neighbors_with<'a>( &self, point: Point2D, max_results: usize, max_distance: f64, workspace: &'a mut NeighborWorkspace, ) -> &'a [usize]

Nearest-neighbor search with reusable result and priority-queue buffers.

Source

pub fn visit_neighbors<B, F>( &self, point: Point2D, max_distance: f64, visitor: F, ) -> ControlFlow<B>
where F: FnMut(usize, f64) -> ControlFlow<B>,

Visit items in nondecreasing squared-distance order from point.

Source

pub fn neighbors_of_box(&self, query: Box2D, max_results: usize) -> Vec<usize>

Return up to max_results item indices nearest to the box query. See Index2D::neighbors_of_box.

Source

pub fn neighbors_of_box_within( &self, query: Box2D, max_results: usize, max_distance: f64, ) -> Vec<usize>

Return up to max_results item indices within max_distance of the box query. See Index2D::neighbors_of_box.

Source

pub fn neighbors_of_box_into( &self, query: Box2D, max_results: usize, max_distance: f64, results: &mut Vec<usize>, )

Box-query nearest-neighbor search with a reusable result buffer.

Source

pub fn neighbors_of_box_with<'na>( &self, query: Box2D, max_results: usize, max_distance: f64, workspace: &'na mut NeighborWorkspace, ) -> &'na [usize]

Box-query nearest-neighbor search with reusable result and priority-queue buffers.

Source

pub fn visit_neighbors_of_box<B, F>( &self, query: Box2D, max_distance: f64, visitor: F, ) -> ControlFlow<B>
where F: FnMut(usize, f64) -> ControlFlow<B>,

Visit items in nondecreasing box-to-box distance order from query. See Index2D::visit_neighbors_of_box.

Source

pub fn visit<B, F>(&self, query: Box2D, visitor: F) -> ControlFlow<B>
where F: FnMut(usize) -> ControlFlow<B>,

Visit intersecting items without collecting a result Vec.

Source

pub fn join(&self, other: &SimdIndex2D) -> Vec<(usize, usize)>

Return every pair (i, j) where item i of self intersects item j of other. See Index2D::join.

Source

pub fn join_with<B, F>(&self, other: &SimdIndex2D, visitor: F) -> ControlFlow<B>
where F: FnMut(usize, usize) -> ControlFlow<B>,

Visit every intersecting pair between self and other. See Index2D::join_with.

Source

pub fn self_join(&self) -> Vec<(usize, usize)>

Return every unordered pair of distinct intersecting items within this index, each pair exactly once. See Index2D::self_join.

Source

pub fn self_join_with<B, F>(&self, visitor: F) -> ControlFlow<B>
where F: FnMut(usize, usize) -> ControlFlow<B>,

Visit every unordered pair of distinct intersecting items within this index. See Index2D::self_join_with.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.