pub trait Occasion {
type Datum;
type Satisfaction;
fn datum(&self) -> &Self::Datum;
fn is_satisfied(&self) -> bool;
fn satisfaction(&self) -> Option<&Self::Satisfaction>;
}
pub trait Society {
type Member: Occasion;
fn members(&self) -> &[Self::Member];
fn diameter(&self) -> f64;
}
pub trait Concrescence {
type Antecedent;
type Unified;
fn prehensions(&self) -> &[Self::Antecedent];
fn unify(self) -> Self::Unified;
}
pub trait PublicWorld {
type Inhabitant;
fn deposit(&mut self, x: Self::Inhabitant);
}
#[derive(Copy, Clone, Debug)]
pub struct SpectralBudget {
pub principal_period: f64,
pub ring_down_factor: f64,
}
impl SpectralBudget {
pub fn for_scene_diameter(diam_m: f64, c: f64) -> Self {
Self { principal_period: 2.0 * diam_m / c, ring_down_factor: 3.0 }
}
pub fn try_admit(&self, diameter: f64) -> Result<(), BudgetError> {
let bound = self.ring_down_factor * self.principal_period;
if diameter <= bound {
Ok(())
} else {
Err(BudgetError::Exceeded {
diameter,
bound,
principal_period: self.principal_period,
ring_down_factor: self.ring_down_factor,
})
}
}
pub fn admits(&self, diameter: f64) -> bool {
self.try_admit(diameter).is_ok()
}
}
#[derive(Debug)]
pub enum BudgetError {
Exceeded {
diameter: f64,
bound: f64,
principal_period: f64,
ring_down_factor: f64,
},
}
impl std::fmt::Display for BudgetError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BudgetError::Exceeded { diameter, bound, principal_period, ring_down_factor } => {
write!(
f,
"spectral budget exceeded: diameter {:.3e} > bound {:.3e} \
(T_1 = {:.3e}, ring-down factor = {:.2}); a closed domain \
has finite becoming — see NOTES_PROCESS.md §3",
diameter, bound, principal_period, ring_down_factor
)
}
}
}
}
impl std::error::Error for BudgetError {}