M3: STL/OBJ import with mesh validation, mass/COM/inertia, material database, RON scene with content-addressed blobs and v0->v1 migration. M4: deterministic heightmap terrain, trimesh colliders, wgpu renderer with instancing and depth, winit app with 1 kHz physics, fly camera, on-screen metrics overlay and per-frame CSV/dev logs. Docs: UI, logging, network and headless CLI plans.
35 lines
955 B
Rust
35 lines
955 B
Rust
//! A fixed-length FIFO that models the transport delay of a sensor bus.
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
/// A FIFO of `steps` samples.
|
|
///
|
|
/// The queue starts filled with `initial`, so the first `steps` calls to
|
|
/// [`Delay::push`] report that value while the queue drains.
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct Delay<T> {
|
|
initial: T,
|
|
queue: VecDeque<T>,
|
|
}
|
|
|
|
impl<T: Clone> Delay<T> {
|
|
/// A delay of `steps` samples, reporting `initial` until the queue fills.
|
|
pub fn new(steps: usize, initial: T) -> Self {
|
|
Self {
|
|
initial: initial.clone(),
|
|
queue: core::iter::repeat_n(initial, steps).collect(),
|
|
}
|
|
}
|
|
|
|
/// Pushes a new sample and returns the one measured `steps` samples ago, or the
|
|
/// new sample itself when the delay is zero.
|
|
pub fn push(&mut self, value: T) -> T {
|
|
if self.queue.is_empty() {
|
|
return value;
|
|
}
|
|
self.queue.push_back(value);
|
|
self.queue
|
|
.pop_front()
|
|
.unwrap_or_else(|| self.initial.clone())
|
|
}
|
|
}
|