pub enum CombineRule {
Average,
Geometric,
Minimum,
Maximum,
Multiply,
}Expand description
A coefficient mixing rule, in increasing priority order:
Average < Geometric < Minimum < Maximum < Multiply.
A material pair selects a_rule.max(b_rule), regardless of collider order.
Friction and restitution select their rules independently. With one zero
coefficient, Geometric, Minimum and Multiply yield zero; Average
yields half the other coefficient and Maximum yields the other coefficient.
Variants§
Average
Arithmetic mean: (a + b) / 2.
Geometric
Geometric mean: sqrt(a * b). Default for friction.
Minimum
Smaller coefficient.
Maximum
Larger coefficient.
Multiply
Product; friction may exceed either authored coefficient.
Implementations§
Source§impl CombineRule
impl CombineRule
Sourcepub fn combine(self, a: f32, b: f32) -> f32
pub fn combine(self, a: f32, b: f32) -> f32
Apply this rule without validating the coefficients or selecting priority.
Average and geometric mean avoid intermediate overflow/underflow for
finite inputs. Ordinary calculations retain their existing f32 rounding;
only extreme intermediates use f64. Multiplication can overflow to
infinity or round tiny products to zero. NaN, infinity and negative inputs
follow floating-point arithmetic; use Self::try_combine to reject them.
Sourcepub fn try_combine(self, a: f32, b: f32) -> Result<f32, CombineError>
pub fn try_combine(self, a: f32, b: f32) -> Result<f32, CombineError>
Combine finite, nonnegative coefficients without clamping.
This scalar helper does not enforce material authoring bounds or select
the higher-priority rule. Both inputs are checked, including a coefficient
that Minimum/Maximum would otherwise ignore. The first invalid input
wins. A non-finite result is an overflow error; underflow to zero in
Multiply is allowed. Signed zero is accepted.
use ferravex_physics::CombineRule;
assert_eq!(CombineRule::Geometric.try_combine(0.0, 0.8).unwrap(), 0.0);
assert_eq!(CombineRule::Average.try_combine(f32::MAX, f32::MAX).unwrap(), f32::MAX);
assert!(CombineRule::Multiply.try_combine(f32::MAX, 2.0).is_err());
assert!(CombineRule::Minimum.try_combine(0.0, f32::NAN).is_err());Trait Implementations§
Source§impl Clone for CombineRule
impl Clone for CombineRule
Source§fn clone(&self) -> CombineRule
fn clone(&self) -> CombineRule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more