use crate::bounding_volume::SimdAabb;
use crate::math::{Point, Real, SimdReal, SIMD_WIDTH};
use crate::partitioning::{SimdVisitStatus, SimdVisitor};
use simba::simd::{SimdBool as _, SimdValue};
use std::marker::PhantomData;
pub struct PointIntersectionsVisitor<'a, T, F> {
simd_point: Point<SimdReal>,
callback: &'a mut F,
_phantom: PhantomData<T>,
}
impl<'a, T, F> PointIntersectionsVisitor<'a, T, F>
where
F: FnMut(&T) -> bool,
{
#[inline]
pub fn new(point: &'a Point<Real>, callback: &'a mut F) -> PointIntersectionsVisitor<'a, T, F> {
PointIntersectionsVisitor {
simd_point: Point::splat(*point),
callback,
_phantom: PhantomData,
}
}
}
impl<'a, T, F> SimdVisitor<T, SimdAabb> for PointIntersectionsVisitor<'a, T, F>
where
F: FnMut(&T) -> bool,
{
#[inline]
fn visit(&mut self, bv: &SimdAabb, b: Option<[Option<&T>; SIMD_WIDTH]>) -> SimdVisitStatus {
let mask = bv.contains_local_point(&self.simd_point);
if let Some(data) = b {
let bitmask = mask.bitmask();
for (ii, data) in data.iter().enumerate() {
if (bitmask & (1 << ii)) != 0 {
let Some(data) = data else { continue };
if !(self.callback)(data) {
return SimdVisitStatus::ExitEarly;
}
}
}
}
SimdVisitStatus::MaybeContinue(mask)
}
}