pub struct SimdIndex2DView<'a> { /* private fields */ }simd only.Expand description
Zero-copy SIMD view over bytes produced by SimdIndex2D::to_bytes or
Index2D::to_bytes.
Like Index2DView it borrows the buffer without
allocating owned tree storage, but the traversal uses wide::f64x4 overlap
tests, assembling lane vectors from four contiguous box records. Ideal for
querying memory-mapped indexes without allocating.
Nearest-neighbor results are returned in nondecreasing distance order. Ties between equal-distance items are not stable across index layouts.
§Example
use packed_spatial_index::{Index2DBuilder, SimdIndex2DView, Box2D};
let mut builder = Index2DBuilder::new(1);
builder.add(Box2D::new(0.0, 0.0, 1.0, 1.0));
let bytes = builder.finish_simd().unwrap().to_bytes();
let view = SimdIndex2DView::from_bytes(&bytes)?;
assert_eq!(view.search(Box2D::new(0.5, 0.5, 0.5, 0.5)), vec![0]);Implementations§
Source§impl<'a> SimdIndex2DView<'a>
impl<'a> SimdIndex2DView<'a>
Sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<Self, LoadError>
pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, LoadError>
Borrow a zero-copy view over the canonical PSINDEX 2D bytes.
Sourcepub fn extent(&self) -> Option<Box2D>
pub fn extent(&self) -> Option<Box2D>
Return the total extent of indexed items, or None for an empty view.
Sourcepub fn search(&self, query: Box2D) -> Vec<usize>
pub fn search(&self, query: Box2D) -> Vec<usize>
Return the indices of all items whose boxes intersect query.
Sourcepub fn search_into(&self, query: Box2D, out: &mut Vec<usize>)
pub fn search_into(&self, query: Box2D, out: &mut Vec<usize>)
Search with a reusable result buffer.
Sourcepub fn search_with<'b>(
&self,
query: Box2D,
workspace: &'b mut SearchWorkspace,
) -> &'b [usize]
pub fn search_with<'b>( &self, query: Box2D, workspace: &'b mut SearchWorkspace, ) -> &'b [usize]
Search with reusable result and traversal buffers.
Sourcepub fn visit<B, F>(&self, query: Box2D, visitor: F) -> ControlFlow<B>
pub fn visit<B, F>(&self, query: Box2D, visitor: F) -> ControlFlow<B>
Visit intersecting items without collecting a result Vec.
Sourcepub fn neighbors(&self, point: Point2D, max_results: usize) -> Vec<usize>
pub fn neighbors(&self, point: Point2D, max_results: usize) -> Vec<usize>
Return up to max_results item indices nearest to point.
Sourcepub fn neighbors_within(
&self,
point: Point2D,
max_results: usize,
max_distance: f64,
) -> Vec<usize>
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.
Sourcepub fn neighbors_into(
&self,
point: Point2D,
max_results: usize,
max_distance: f64,
results: &mut Vec<usize>,
)
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.
Sourcepub fn neighbors_with<'b>(
&self,
point: Point2D,
max_results: usize,
max_distance: f64,
workspace: &'b mut NeighborWorkspace,
) -> &'b [usize]
pub fn neighbors_with<'b>( &self, point: Point2D, max_results: usize, max_distance: f64, workspace: &'b mut NeighborWorkspace, ) -> &'b [usize]
Nearest-neighbor search with reusable result and priority-queue buffers.
Sourcepub fn visit_neighbors<B, F>(
&self,
point: Point2D,
max_distance: f64,
visitor: F,
) -> ControlFlow<B>
pub fn visit_neighbors<B, F>( &self, point: Point2D, max_distance: f64, visitor: F, ) -> ControlFlow<B>
Visit items in nondecreasing squared-distance order from point.
Sourcepub fn neighbors_of_box(&self, query: Box2D, max_results: usize) -> Vec<usize>
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.
Sourcepub fn neighbors_of_box_within(
&self,
query: Box2D,
max_results: usize,
max_distance: f64,
) -> Vec<usize>
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.
Sourcepub fn neighbors_of_box_into(
&self,
query: Box2D,
max_results: usize,
max_distance: f64,
results: &mut Vec<usize>,
)
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.
Sourcepub fn neighbors_of_box_with<'na>(
&self,
query: Box2D,
max_results: usize,
max_distance: f64,
workspace: &'na mut NeighborWorkspace,
) -> &'na [usize]
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.
Sourcepub fn visit_neighbors_of_box<B, F>(
&self,
query: Box2D,
max_distance: f64,
visitor: F,
) -> ControlFlow<B>
pub fn visit_neighbors_of_box<B, F>( &self, query: Box2D, max_distance: f64, visitor: F, ) -> ControlFlow<B>
Visit items in nondecreasing box-to-box distance order from query.
See Index2D::visit_neighbors_of_box.
Sourcepub fn join(&self, other: &SimdIndex2DView<'_>) -> Vec<(usize, usize)>
pub fn join(&self, other: &SimdIndex2DView<'_>) -> Vec<(usize, usize)>
Return every pair (i, j) where item i of self intersects item j
of other. See Index2D::join.
Sourcepub fn join_with<B, F>(
&self,
other: &SimdIndex2DView<'_>,
visitor: F,
) -> ControlFlow<B>
pub fn join_with<B, F>( &self, other: &SimdIndex2DView<'_>, visitor: F, ) -> ControlFlow<B>
Visit every intersecting pair between self and other. See
Index2D::join_with.
Sourcepub fn self_join(&self) -> Vec<(usize, usize)>
pub fn self_join(&self) -> Vec<(usize, usize)>
Return every unordered pair of distinct intersecting items within this
view, each pair exactly once. See
Index2D::self_join.
Sourcepub fn self_join_with<B, F>(&self, visitor: F) -> ControlFlow<B>
pub fn self_join_with<B, F>(&self, visitor: F) -> ControlFlow<B>
Visit every unordered pair of distinct intersecting items within this
view. See Index2D::self_join_with.
Source§impl SimdIndex2DView<'_>
impl SimdIndex2DView<'_>
Sourcepub fn raycast(&self, ray: Ray2D) -> Vec<usize>
pub fn raycast(&self, ray: Ray2D) -> Vec<usize>
Return the indices of all items whose boxes the ray segment touches.
Sourcepub fn raycast_into(&self, ray: Ray2D, results: &mut Vec<usize>)
pub fn raycast_into(&self, ray: Ray2D, results: &mut Vec<usize>)
Raycast with a reusable result buffer.
Sourcepub fn raycast_with<'na>(
&self,
ray: Ray2D,
workspace: &'na mut SearchWorkspace,
) -> &'na [usize]
pub fn raycast_with<'na>( &self, ray: Ray2D, workspace: &'na mut SearchWorkspace, ) -> &'na [usize]
Raycast with reusable result and traversal buffers.
Sourcepub fn raycast_closest(&self, ray: Ray2D) -> Option<(usize, f64)>
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.
See Index2D::raycast_closest.
Sourcepub fn raycast_closest_with(
&self,
ray: Ray2D,
workspace: &mut NeighborWorkspace,
) -> Option<(usize, f64)>
pub fn raycast_closest_with( &self, ray: Ray2D, workspace: &mut NeighborWorkspace, ) -> Option<(usize, f64)>
Closest-hit raycast with a reusable priority-queue workspace.
Sourcepub fn visit_raycast<B, F>(&self, ray: Ray2D, visitor: F) -> ControlFlow<B>
pub fn visit_raycast<B, F>(&self, ray: Ray2D, visitor: F) -> 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.
Auto Trait Implementations§
impl<'a> Freeze for SimdIndex2DView<'a>
impl<'a> RefUnwindSafe for SimdIndex2DView<'a>
impl<'a> Send for SimdIndex2DView<'a>
impl<'a> Sync for SimdIndex2DView<'a>
impl<'a> Unpin for SimdIndex2DView<'a>
impl<'a> UnsafeUnpin for SimdIndex2DView<'a>
impl<'a> UnwindSafe for SimdIndex2DView<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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