pub struct Cut { /* private fields */ }Expand description
A random cut along one dimension at a given coordinate.
Implementations§
Source§impl Cut
impl Cut
Sourcepub fn new(dim: usize, value: f64) -> Self
pub fn new(dim: usize, value: f64) -> Self
Build a cut explicitly. Used by tests and the persistence layer.
Sourcepub fn left_of(&self, point: &[f64]) -> bool
pub fn left_of(&self, point: &[f64]) -> bool
Decide which side of the cut a point lies on.
Returns true when point[dim] <= self.value. The exact-tie
behaviour is consistent with the AWS reference (left subtree
gets the equal-or-below half).
§Panics
Panics when self.dim() >= point.len() — call sites always
size-check the point first via
crate::domain::ensure_dim.
Sourcepub fn random_cut<const D: usize, R: Rng + ?Sized>(
bbox: &BoundingBox<D>,
rng: &mut R,
) -> RcfResult<Self>
pub fn random_cut<const D: usize, R: Rng + ?Sized>( bbox: &BoundingBox<D>, rng: &mut R, ) -> RcfResult<Self>
Sample a random cut over bbox with the dimension chosen
proportionally to its range and the value uniform in
[min_d, max_d].
§Errors
Returns RcfError::EmptyBoundingBox when every per-dimension
range is zero (no cut is meaningful).
§Examples
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use anomstream_core::domain::{BoundingBox, Cut};
let mut rng = ChaCha8Rng::seed_from_u64(42);
let mut bbox = BoundingBox::<2>::from_point(&[0.0, 0.0]).unwrap();
bbox.extend(&[1.0, 4.0]).unwrap(); // dim 1 has 4× the range of dim 0
let cut = Cut::random_cut(&bbox, &mut rng).unwrap();
assert!(cut.dim() < bbox.dim());
let lo = bbox.min()[cut.dim()];
let hi = bbox.max()[cut.dim()];
assert!(cut.value() >= lo && cut.value() <= hi);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cut
impl<'de> Deserialize<'de> for Cut
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Cut
impl StructuralPartialEq for Cut
Auto Trait Implementations§
impl Freeze for Cut
impl RefUnwindSafe for Cut
impl Send for Cut
impl Sync for Cut
impl Unpin for Cut
impl UnsafeUnpin for Cut
impl UnwindSafe for Cut
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
Mutably borrows from an owned value. Read more
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>
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 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>
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