Skip to content

Commit b93772f

Browse files
committed
Somehow branchless duff got overwritten - fixed. Removed warning from tests about mutable vector.
1 parent d80891a commit b93772f

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎src/math.rs‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ use super::*;
44
/// Duff et al., JCGT 2017
55
/// http://jcgt.org/published/0006/01/01/
66
pub fn duff_orthonormal_basis(n: Vector) -> (Vector, Vector) {
7-
if n.z < 0. {
8-
let a = 1.0 / (1.0 - n.z);
9-
let b = n.x * n.y * a;
10-
let b1 = Vector::new(1.0 - n.x*n.x*a, -b, n.x);
11-
let b2 = Vector::new(b, n.y * n.y*a- 1.0, -n.y);
12-
(b1, b2)
13-
} else {
14-
let a = 1.0 / (1.0 + n.z);
15-
let b = -n.x * n.y * a;
16-
let b1 = Vector::new(1.0 - n.x*n.x*a, b, -n.x);
17-
let b2 = Vector::new(b, 1.0 - n.y*n.y*a, -n.y);
18-
(b1, b2)
19-
}
7+
let sign = (1.0_f64).copysign(n.z);
8+
let a = -1.0_f64 / (sign + n.z);
9+
let b = n.x*n.y*a;
10+
let b1 = Vector::new(1.0 + sign*n.x*n.x*a, sign*b, -sign*n.x);
11+
let b2 = Vector::new(b, sign + n.y*n.y*a, -n.y);
12+
(b1, b2)
2013
}

‎src/tests.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,10 @@ fn test_momentum_conservation() {
781781
InteractionPotential::MORSE{D: 5.4971E-20, r0: 2.782E-10, alpha: 1.4198E10}
782782
];
783783

784+
#[cfg(feature = "cpr_rootfinder")]
784785
let mut rootfinders = vec![Rootfinder::NEWTON{max_iterations: 100, tolerance: 1E-3}; 4];
786+
#[cfg(not(feature = "cpr_rootfinder"))]
787+
let rootfinders = vec![Rootfinder::NEWTON{max_iterations: 100, tolerance: 1E-3}; 4];
785788

786789
//[[{"CPR"={n0=2, nmax=100, epsilon=1E-9, complex_threshold=1E-3, truncation_threshold=1E-9, far_from_zero=1E9, interval_limit=1E-12, derivative_free=true}}]]
787790
#[cfg(feature = "cpr_rootfinder")]

0 commit comments

Comments
 (0)