Enum CombineRule

Source
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

Source

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.

Source

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

Source§

fn clone(&self) -> CombineRule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CombineRule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for CombineRule

Source§

fn default() -> CombineRule

Returns the “default value” for a type. Read more
Source§

impl Ord for CombineRule

Source§

fn cmp(&self, other: &CombineRule) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for CombineRule

Source§

fn eq(&self, other: &CombineRule) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for CombineRule

Source§

fn partial_cmp(&self, other: &CombineRule) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for CombineRule

Source§

impl Eq for CombineRule

Source§

impl StructuralPartialEq for CombineRule

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.