dijkstra3d-core 0.1.0

Voxel-grid Dijkstra and rolling-ball invalidation, ported from seung-lab/dijkstra3d and seung-lab/kimimaro
Documentation
//! The 26-bit-per-voxel connectivity graph.

use crate::voxel::VolumeShape;

/// A read-only view over a voxel connectivity graph buffer.
///
/// The buffer must have one `u32` per voxel, in the same order as the volume.
#[derive(Debug, Clone, Copy)]
pub struct ConnectivityGraph<'a> {
    buf: &'a [u32],
    shape: VolumeShape,
}

impl<'a> ConnectivityGraph<'a> {
    /// Wrap an existing buffer. Returns `None` if the buffer length doesn't
    /// match the shape's voxel count.
    pub fn new(buf: &'a [u32], shape: VolumeShape) -> Option<Self> {
        if buf.len() as u64 == shape.total() {
            Some(Self { buf, shape })
        } else {
            None
        }
    }

    /// Volume shape this graph corresponds to.
    pub fn shape(&self) -> VolumeShape {
        self.shape
    }

    /// Check whether direction `dir_bit` is permitted at linear index `loc`.
    ///
    /// `dir_bit` should come from `neighborhood::neighborhood_masks()`.
    #[inline]
    pub fn allows(&self, loc: u64, dir_bit: u32) -> bool {
        // The caller is expected to pass a valid `loc`; retain a bounds check
        // because its cost is small relative to queue processing.
        self.buf
            .get(loc as usize)
            .is_some_and(|word| (*word & dir_bit) != 0)
    }
}