use super::*;
mod collect;
pub use self::collect::*;
use alloc::boxed::Box;
mod inner;
#[repr(transparent)]
struct Ptr<T: ?Sized>(*mut T);
impl<T: ?Sized> Copy for Ptr<T> {}
impl<T: ?Sized> Clone for Ptr<T> {
#[inline(always)]
fn clone(&self) -> Ptr<T> {
*self
}
}
unsafe impl<T: ?Sized> Send for Ptr<T> {}
unsafe impl<T: ?Sized> Sync for Ptr<T> {}
pub struct TreeRefInd<'a, A: Axis, N: Num, T> {
tree: inner::TreeIndInner<A,N,T>,
_p: PhantomData<&'a mut (T, N)>,
}
impl<'a, N: Num, T> TreeRefInd<'a, DefaultA, N, T> {
pub fn new(
arr: &'a mut [T],
func: impl FnMut(&mut T) -> Rect<N>,
) -> TreeRefInd<'a, DefaultA, N, T> {
Self::with_axis(default_axis(),arr,func)
}
}
impl<'a, N: Num, T:Send+Sync> TreeRefInd<'a, DefaultA, N, T> {
pub fn new_par(
arr: &'a mut [T],
func: impl FnMut(&mut T) -> Rect<N>,
) -> TreeRefInd<'a, DefaultA, N, T> {
Self::with_axis_par(default_axis(),arr,func)
}
}
impl<'a, A: Axis, N: Num, T:Send+Sync> TreeRefInd<'a, A, N, T> {
pub fn with_axis_par(
axis: A,
arr: &'a mut [T],
func: impl FnMut(&mut T) -> Rect<N>,
) -> TreeRefInd<'a, A, N, T> {
TreeRefInd{tree:inner::TreeIndInner::with_axis_par(axis,arr,func),_p:PhantomData}
}
}
impl<'a, A: Axis, N: Num, T> TreeRefInd<'a, A, N, T> {
pub fn with_axis(
axis: A,
arr: &'a mut [T],
func: impl FnMut(&mut T) -> Rect<N>,
) -> TreeRefInd<'a, A, N, T> {
TreeRefInd{tree:inner::TreeIndInner::with_axis(axis,arr,func),_p:PhantomData}
}
pub fn get_elements(&self) -> &[T] {
unsafe { &*self.tree.orig.0 }
}
pub fn get_elements_mut(&mut self) -> &'a mut [T] {
unsafe { &mut *self.tree.orig.0 }
}
}
impl<'a, A: Axis, N: Num + 'a, T> core::ops::Deref for TreeRefInd<'a, A, N, T> {
type Target = TreeRef<'a, A, BBox<N, &'a mut T>>;
fn deref(&self) -> &Self::Target {
unsafe { &*(self.tree.inner.as_tree() as *const _ as *const _) }
}
}
impl<'a, A: Axis, N: Num + 'a, T> core::ops::DerefMut for TreeRefInd<'a, A, N, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self.tree.inner.as_tree_mut() as *mut _ as *mut _) }
}
}
pub struct TreeRef<'a, A: Axis, T: Aabb> {
tree: inner::TreeRefInner<A, T>,
_p: PhantomData<&'a mut T>,
}
impl<'a, A: Axis, T: Aabb> core::ops::Deref for TreeRef<'a, A, T> {
type Target = Tree<'a, A, T>;
fn deref(&self) -> &Self::Target {
unsafe { &*(&self.tree.inner as *const _ as *const _) }
}
}
impl<'a, A: Axis, T: Aabb> core::ops::DerefMut for TreeRef<'a, A, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(&mut self.tree.inner as *mut _ as *mut _) }
}
}
impl<'a, T: Aabb> TreeRef<'a, DefaultA, T> {
pub fn new(arr: &'a mut [T]) -> TreeRef<'a, DefaultA, T> {
TreeRef::with_axis(default_axis(), arr)
}
}
impl<'a, T: Aabb + Send + Sync> TreeRef<'a, DefaultA, T> {
pub fn new_par(arr: &'a mut [T]) -> TreeRef<'a, DefaultA, T> {
TreeRef::with_axis_par(default_axis(), arr)
}
}
impl<'a, A: Axis, T: Aabb + Send + Sync> TreeRef<'a, A, T> {
pub fn with_axis_par(a: A, arr: &'a mut [T]) -> TreeRef<'a, A, T> {
TreeRef {
tree: inner::TreeRefInner::with_axis_par(a,arr),
_p: PhantomData,
}
}
}
impl<'a, A: Axis, T: Aabb> TreeRef<'a, A, T> {
pub fn with_axis(a: A, arr: &'a mut [T]) -> TreeRef<'a, A, T> {
TreeRef {
tree: inner::TreeRefInner::with_axis(a,arr),
_p: PhantomData,
}
}
pub fn get_bbox_elements(&self) -> &[T] {
unsafe { &*self.tree.orig.0 }
}
pub fn get_bbox_elements_mut(&mut self) -> PMut<'a, [T]> {
PMut::new(unsafe { &mut *self.tree.orig.0 })
}
}
pub(crate) struct NodePtr<T: Aabb> {
_range: PMutPtr<[T]>,
_cont: Option<axgeom::Range<T::Num>>,
_div: Option<T::Num>,
}
pub struct TreeOwnedInd<A: Axis, N: Num, T> {
tree:inner::TreeIndInner<A,N,T>,
_bots: Box<[T]>,
}
impl<N: Num, T: Send + Sync> TreeOwnedInd<DefaultA, N, T> {
pub fn new_par(bots: Box<[T]>, func: impl FnMut(&mut T) -> Rect<N>) -> TreeOwnedInd<DefaultA, N, T> {
TreeOwnedInd::with_axis_par(default_axis(), bots, func)
}
}
impl<A: Axis, N: Num, T: Send + Sync> TreeOwnedInd<A, N, T> {
pub fn with_axis_par(
axis: A,
mut bots: Box<[T]>,
func: impl FnMut(&mut T) -> Rect<N>,
) -> TreeOwnedInd<A, N, T> {
TreeOwnedInd { tree:inner::TreeIndInner::with_axis_par(axis,&mut bots,func), _bots:bots }
}
}
impl<N: Num, T> TreeOwnedInd<DefaultA, N, T> {
pub fn new(bots: Box<[T]>, func: impl FnMut(&mut T) -> Rect<N>) -> TreeOwnedInd<DefaultA, N, T> {
Self::with_axis(default_axis(), bots, func)
}
}
impl<A: Axis, N: Num, T> TreeOwnedInd<A, N, T> {
pub fn with_axis(
axis: A,
mut bots: Box<[T]>,
func: impl FnMut(&mut T) -> Rect<N>,
) -> TreeOwnedInd<A, N, T> {
TreeOwnedInd { tree:inner::TreeIndInner::with_axis(axis,&mut bots,func), _bots:bots }
}
pub fn as_tree(&self) -> &TreeRefInd<A,N, T> {
unsafe { &*(&self.tree as *const _ as *const _) }
}
pub fn as_tree_mut(&mut self) -> &mut TreeRefInd<A,N,T> {
unsafe { &mut *(&mut self.tree as *mut _ as *mut _) }
}
}
pub struct TreeOwned<A: Axis, T: Aabb> {
tree: inner::TreeRefInner<A, T>,
_bots: Box<[T]>,
}
impl<T: Aabb + Send + Sync> TreeOwned<DefaultA, T> {
pub fn new_par(bots: Box<[T]>) -> TreeOwned<DefaultA, T> {
TreeOwned::with_axis_par(default_axis(), bots)
}
}
impl<A: Axis, T: Aabb + Send + Sync> TreeOwned<A, T> {
pub fn with_axis_par(axis: A, mut bots: Box<[T]>) -> TreeOwned<A, T> {
TreeOwned {
tree: inner::TreeRefInner::with_axis_par(axis,&mut bots),
_bots:bots,
}
}
}
impl<T: Aabb> TreeOwned<DefaultA, T> {
pub fn new(bots: Box<[T]>) -> TreeOwned<DefaultA, T> {
Self::with_axis(default_axis(), bots)
}
}
impl<A: Axis, T: Aabb> TreeOwned<A, T> {
pub fn with_axis(axis: A, mut bots: Box<[T]>) -> TreeOwned<A, T> {
TreeOwned {
tree: inner::TreeRefInner::with_axis(axis,&mut bots),
_bots:bots,
}
}
pub fn as_tree(&self) -> &TreeRef<A, T> {
unsafe { &*(&self.tree as *const _ as *const _) }
}
pub fn as_tree_mut(&mut self) -> &mut TreeRef<A, T> {
unsafe { &mut *(&mut self.tree as *mut _ as *mut _) }
}
}