pub struct BoundingBox<const D: usize> { /* private fields */ }Expand description
Axis-aligned bounding box for D-dimensional points. Storage is
stack-allocated [f64; D] so the compiler can unroll the
per-dim loops, vectorise via SIMD, and avoid any heap traffic.
§Examples
use anomstream_core::BoundingBox;
let mut bbox = BoundingBox::<2>::from_point(&[0.0, 0.0]).unwrap();
bbox.extend(&[3.0, 4.0]).unwrap();
assert_eq!(bbox.range_sum(), 7.0);Implementations§
Source§impl<const D: usize> BoundingBox<D>
impl<const D: usize> BoundingBox<D>
Sourcepub fn from_point(point: &[f64]) -> RcfResult<Self>
pub fn from_point(point: &[f64]) -> RcfResult<Self>
Build a degenerate bounding box from a single point.
§Errors
RcfError::EmptyBoundingBoxwhenD == 0.RcfError::DimensionMismatchwhenpoint.len() != D.
Sourcepub fn range_at(&self, d: usize) -> f64
pub fn range_at(&self, d: usize) -> f64
Range (max_d − min_d) for dimension d.
§Panics
Panics when d >= D — call sites are internal and always
size-checked.
Sourcepub fn range_sum(&self) -> f64
pub fn range_sum(&self) -> f64
Sum of per-dimension ranges (Σ_d (max_d − min_d)).
This is the denominator used by Cut::random_cut to pick a
dimension weighted by its range. Vectorised in 4-lane f64
chunks via wide::f64x4 for the AWS-default D = 16 hot
path; a scalar tail handles dims that are not a multiple of 4.
Sourcepub fn extend(&mut self, point: &[f64]) -> RcfResult<()>
pub fn extend(&mut self, point: &[f64]) -> RcfResult<()>
Extend the box in place to include point.
§Errors
Returns RcfError::DimensionMismatch when point.len() != D.
Sourcepub fn merge_with(&mut self, other: &Self)
pub fn merge_with(&mut self, other: &Self)
Merge other into self in place. Both boxes have the same
type-level dimensionality so this is infallible.
Sourcepub fn merged(&self, other: &Self) -> Self
pub fn merged(&self, other: &Self) -> Self
Return a new box equal to the union of self and other.
Sourcepub fn extension_per_dim(&self, point: &[f64]) -> RcfResult<[f64; D]>
pub fn extension_per_dim(&self, point: &[f64]) -> RcfResult<[f64; D]>
Per-dimension extension required to accommodate point —
Δ_d = max(0, point_d − max_d) + max(0, min_d − point_d).
When point already lies inside the box every Δ_d is 0 and
the cut probability is 0.
§Errors
Returns RcfError::DimensionMismatch when point.len() != D.
Sourcepub fn probability_of_cut(&self, point: &[f64]) -> RcfResult<(f64, [f64; D])>
pub fn probability_of_cut(&self, point: &[f64]) -> RcfResult<(f64, [f64; D])>
Probability that a uniform random cut over the augmented box
would isolate point from the original box.
Returns (total_probability, per_dim_contributions) where the
per-dim array sums to total_probability.
§Errors
Returns RcfError::DimensionMismatch when point.len() != D.
Sourcepub fn per_dim_cut_probabilities(&self, point: &[f64]) -> RcfResult<[f64; D]>
pub fn per_dim_cut_probabilities(&self, point: &[f64]) -> RcfResult<[f64; D]>
Convenience accessor returning only the per-dim contributions (ignores the total).
§Errors
Returns RcfError::DimensionMismatch when point.len() != D.
Sourcepub fn augmented_range_at(&self, d: usize, point: &[f64]) -> f64
pub fn augmented_range_at(&self, d: usize, point: &[f64]) -> f64
Per-dimension range of the bounding box augmented by point
without materialising a fresh BoundingBox.
§Panics
Panics in debug builds when d >= D or point.len() != D.
Sourcepub fn augmented_range_sum(&self, point: &[f64]) -> f64
pub fn augmented_range_sum(&self, point: &[f64]) -> f64
Sum of augmented_range_at over
every dimension.
§Panics
Panics in debug builds when point.len() != D.
Sourcepub fn augmented_random_cut<R: Rng + ?Sized>(
&self,
point: &[f64],
rng: &mut R,
) -> RcfResult<Cut>
pub fn augmented_random_cut<R: Rng + ?Sized>( &self, point: &[f64], rng: &mut R, ) -> RcfResult<Cut>
Sample a random cut over the bounding box augmented by
point without materialising the augmented box.
§Errors
Returns RcfError::EmptyBoundingBox when every per-dim
range of the augmented box is zero.
Sourcepub fn total_probability_of_cut(&self, point: &[f64]) -> RcfResult<f64>
pub fn total_probability_of_cut(&self, point: &[f64]) -> RcfResult<f64>
Total cut probability without allocating the per-dim
breakdown — fast path for crate::ScalarScoreVisitor.
Fuses the range_sum and extension passes into a single SIMD
loop so self.min / self.max are loaded once per chunk. The
previous split implementation did two passes and ate 2× the L1
bandwidth on deep tree descents where bbox reload dominates.
§Errors
Returns RcfError::DimensionMismatch when point.len() != D.
Trait Implementations§
Source§impl<const D: usize> Clone for BoundingBox<D>
impl<const D: usize> Clone for BoundingBox<D>
Source§fn clone(&self) -> BoundingBox<D>
fn clone(&self) -> BoundingBox<D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const D: usize> Debug for BoundingBox<D>
impl<const D: usize> Debug for BoundingBox<D>
Source§impl<'de, const D: usize> Deserialize<'de> for BoundingBox<D>
impl<'de, const D: usize> Deserialize<'de> for BoundingBox<D>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<const D: usize> PartialEq for BoundingBox<D>
impl<const D: usize> PartialEq for BoundingBox<D>
Source§impl<const D: usize> Serialize for BoundingBox<D>
impl<const D: usize> Serialize for BoundingBox<D>
impl<const D: usize> StructuralPartialEq for BoundingBox<D>
Auto Trait Implementations§
impl<const D: usize> Freeze for BoundingBox<D>
impl<const D: usize> RefUnwindSafe for BoundingBox<D>
impl<const D: usize> Send for BoundingBox<D>
impl<const D: usize> Sync for BoundingBox<D>
impl<const D: usize> Unpin for BoundingBox<D>
impl<const D: usize> UnsafeUnpin for BoundingBox<D>
impl<const D: usize> UnwindSafe for BoundingBox<D>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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