@@ -7,29 +7,34 @@ use crate::math::Real;
7
7
/// Each collider has its combination rule of type
8
8
/// `CoefficientCombineRule`. And the rule
9
9
/// actually used is given by `max(first_combine_rule as usize, second_combine_rule as usize)`.
10
- #[ derive( Default , Copy , Clone , Debug , PartialEq , Eq ) ]
10
+ #[ derive( Default , Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
11
11
#[ cfg_attr( feature = "serde-serialize" , derive( Serialize , Deserialize ) ) ]
12
12
pub enum CoefficientCombineRule {
13
13
/// The two coefficients are averaged.
14
14
#[ default]
15
15
Average = 0 ,
16
16
/// The smallest coefficient is chosen.
17
- Min ,
17
+ Min = 1 ,
18
18
/// The two coefficients are multiplied.
19
- Multiply ,
19
+ Multiply = 2 ,
20
20
/// The greatest coefficient is chosen.
21
- Max ,
21
+ Max = 3 ,
22
22
}
23
23
24
24
impl CoefficientCombineRule {
25
- pub ( crate ) fn combine ( coeff1 : Real , coeff2 : Real , rule_value1 : u8 , rule_value2 : u8 ) -> Real {
25
+ pub ( crate ) fn combine (
26
+ coeff1 : Real ,
27
+ coeff2 : Real ,
28
+ rule_value1 : CoefficientCombineRule ,
29
+ rule_value2 : CoefficientCombineRule ,
30
+ ) -> Real {
26
31
let effective_rule = rule_value1. max ( rule_value2) ;
27
32
28
33
match effective_rule {
29
- 0 => ( coeff1 + coeff2) / 2.0 ,
30
- 1 => coeff1. min ( coeff2) ,
31
- 2 => coeff1 * coeff2,
32
- _ => coeff1. max ( coeff2) ,
34
+ CoefficientCombineRule :: Average => ( coeff1 + coeff2) / 2.0 ,
35
+ CoefficientCombineRule :: Min => coeff1. min ( coeff2) ,
36
+ CoefficientCombineRule :: Multiply => coeff1 * coeff2,
37
+ CoefficientCombineRule :: Max => coeff1. max ( coeff2) ,
33
38
}
34
39
}
35
40
}
0 commit comments