//! A minimal static strength check at a single stress value. //! //! The load path and stress distribution are the caller's business; this module //! only compares a stress with the material's yield strength. use fabrilis_core::units::Pascals; /// Yield data used for a static check. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Strength { /// Yield strength of the material, Pa. pub yield_strength: Pascals, } impl Strength { /// Yield strength divided by the applied stress. /// /// `None` for a non-positive or non-finite stress, and when the resulting /// factor is not finite. #[must_use] pub fn factor_of_safety(self, stress: Pascals) -> Option { let stress = stress.get(); if !stress.is_finite() || stress <= 0.0 { return None; } let factor = self.yield_strength.get() / stress; if factor.is_finite() { Some(factor) } else { None } } /// True when the factor of safety reaches `required`. /// /// `required` must be finite and positive; any invalid input is unsafe. #[must_use] pub fn is_safe(self, stress: Pascals, required: f64) -> bool { if !required.is_finite() || required <= 0.0 { return false; } match self.factor_of_safety(stress) { Some(factor) => factor >= required, None => false, } } } #[cfg(test)] mod tests;