pub struct ToleranceEngine { /* private fields */ }Expand description
Component tolerance engine.
Given a seed (representing a specific physical pedal unit), generates deterministic variations for each component. The same seed always produces the same set of component variations.
Usage:
ⓘ
let tol = ToleranceEngine::new(42, ToleranceGrade::Loose);
let actual_r = tol.apply(nominal_r, 0); // component index 0
let actual_c = tol.apply(nominal_c, 1); // component index 1Implementations§
Source§impl ToleranceEngine
impl ToleranceEngine
Sourcepub fn new(seed: u64, grade: ToleranceGrade) -> Self
pub fn new(seed: u64, grade: ToleranceGrade) -> Self
Create a new tolerance engine with uniform grade for all components.
Sourcepub fn with_grades(
seed: u64,
resistor_grade: ToleranceGrade,
capacitor_grade: ToleranceGrade,
) -> Self
pub fn with_grades( seed: u64, resistor_grade: ToleranceGrade, capacitor_grade: ToleranceGrade, ) -> Self
Create with separate grades for resistors and capacitors.
Capacitors typically have looser tolerances than resistors in vintage pedals. A common combination: ±5% resistors, ±10% caps.
Sourcepub fn apply_resistor(&self, nominal: f64, component_index: usize) -> f64
pub fn apply_resistor(&self, nominal: f64, component_index: usize) -> f64
Apply tolerance to a resistor value.
Returns the actual value after applying a deterministic random offset based on the seed and component index.
Sourcepub fn apply_capacitor(&self, nominal: f64, component_index: usize) -> f64
pub fn apply_capacitor(&self, nominal: f64, component_index: usize) -> f64
Apply tolerance to a capacitor value.
Trait Implementations§
Source§impl Clone for ToleranceEngine
impl Clone for ToleranceEngine
Source§fn clone(&self) -> ToleranceEngine
fn clone(&self) -> ToleranceEngine
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ToleranceEngine
impl RefUnwindSafe for ToleranceEngine
impl Send for ToleranceEngine
impl Sync for ToleranceEngine
impl Unpin for ToleranceEngine
impl UnsafeUnpin for ToleranceEngine
impl UnwindSafe for ToleranceEngine
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