spirv_backend: use Real:: constants instead of inlined ones
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::support::Optional;
|
||||
use coremem_types::mat::Material;
|
||||
use coremem_types::vec::Vec3;
|
||||
use coremem_types::real::{Real as _};
|
||||
|
||||
|
||||
/// M(B) parallelogram
|
||||
@@ -74,23 +75,20 @@ pub struct MHPgram {
|
||||
impl MHPgram {
|
||||
/// h_intercept: X coordinate at which M is always zero.
|
||||
/// mu_r: relative mu value along the non-flat edges of the parallelogram.
|
||||
pub const fn new(h_intercept: f32, mu_r: f32, max_m: f32) -> Self {
|
||||
const MU0_INV: f32 = 795774.715025073;
|
||||
pub fn new(h_intercept: f32, mu_r: f32, max_m: f32) -> Self {
|
||||
let one_minus_mu_r_inv = 1.0 - 1.0/mu_r;
|
||||
Self {
|
||||
b_mult: MU0_INV * one_minus_mu_r_inv,
|
||||
b_mult: f32::mu0_inv() * one_minus_mu_r_inv,
|
||||
m_offset: h_intercept * one_minus_mu_r_inv,
|
||||
max_m,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn h_intercept(&self) -> f32 {
|
||||
const MU0_INV: f32 = 795774.715025073;
|
||||
MU0_INV * self.m_offset / self.b_mult
|
||||
f32::mu0_inv() * self.m_offset / self.b_mult
|
||||
}
|
||||
pub fn mu_r(&self) -> f32 {
|
||||
const MU0: f32 = 1.2566370621219e-06;
|
||||
let mu_r_inv = 1.0 - MU0*self.b_mult;
|
||||
let mu_r_inv = 1.0 - f32::mu0()*self.b_mult;
|
||||
1.0 / mu_r_inv
|
||||
}
|
||||
|
||||
@@ -177,8 +175,8 @@ pub struct Ferroxcube3R1MH;
|
||||
|
||||
impl Into<MHPgram> for Ferroxcube3R1MH {
|
||||
fn into(self) -> MHPgram {
|
||||
const CURVE: MHPgram = MHPgram::new(25.0, 881.33, 44000.0);
|
||||
CURVE
|
||||
// TODO: how much (if any) penalty do we pay for this not being `const`?
|
||||
MHPgram::new(25.0, 881.33, 44000.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,55 +310,55 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn mh_curve_edge_travel() {
|
||||
const MU0: f32 = 1.2566370621219e-06;
|
||||
let mu0 = f32::mu0();
|
||||
let curve = MHPgram::new(50.0, 101.0, 500.0);
|
||||
|
||||
assert_eq_approx(curve.move_b(0.0, 151.0*MU0), 100.0, 0.1); // rightward travel along edge
|
||||
assert_eq_approx(curve.move_b(100.0, 252.0*MU0), 200.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(200.0, 555.0*MU0), 500.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(500.0, 500.0*MU0), 500.0, 0.1); // back (leftward) travel to H=0
|
||||
assert_eq_approx(curve.move_b(500.0, 455.0*MU0), 500.0, 0.1); // back (leftward) travel to H=-45
|
||||
assert_eq_approx(curve.move_b(500.0, 354.0*MU0), 400.0, 0.1); // back (leftward) travel to H=-46
|
||||
assert_eq_approx(curve.move_b(400.0, 253.0*MU0), 300.0, 0.1); // back (leftward) travel to H=-47
|
||||
assert_eq_approx(curve.move_b(300.0, -50.0*MU0), 0.0, 0.1); // back (leftward) travel to H=-50
|
||||
assert_eq_approx(curve.move_b(0.0, -151.0*MU0), -100.0, 0.1); // back (leftward) travel to H=-51
|
||||
assert_eq_approx(curve.move_b(-100.0, -555.0*MU0), -500.0, 0.1); // back (leftward) travel to H=-55
|
||||
assert_eq_approx(curve.move_b(-500.0, -456.0*MU0), -500.0, 0.1); // interior (rightward) travel to H=44
|
||||
assert_eq_approx(curve.move_b(-500.0, -354.0*MU0), -400.0, 0.1); // interior (rightward) travel to H=46
|
||||
assert_eq_approx(curve.move_b(-400.0, -253.0*MU0), -300.0, 0.1); // interior (rightward) travel to H=47
|
||||
assert_eq_approx(curve.move_b(-300.0, 50.0*MU0), 0.0, 0.1); // interior (rightward) travel to H=50
|
||||
assert_eq_approx(curve.move_b(0.0, 151.0*mu0), 100.0, 0.1); // rightward travel along edge
|
||||
assert_eq_approx(curve.move_b(100.0, 252.0*mu0), 200.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(200.0, 555.0*mu0), 500.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(500.0, 500.0*mu0), 500.0, 0.1); // back (leftward) travel to H=0
|
||||
assert_eq_approx(curve.move_b(500.0, 455.0*mu0), 500.0, 0.1); // back (leftward) travel to H=-45
|
||||
assert_eq_approx(curve.move_b(500.0, 354.0*mu0), 400.0, 0.1); // back (leftward) travel to H=-46
|
||||
assert_eq_approx(curve.move_b(400.0, 253.0*mu0), 300.0, 0.1); // back (leftward) travel to H=-47
|
||||
assert_eq_approx(curve.move_b(300.0, -50.0*mu0), 0.0, 0.1); // back (leftward) travel to H=-50
|
||||
assert_eq_approx(curve.move_b(0.0, -151.0*mu0), -100.0, 0.1); // back (leftward) travel to H=-51
|
||||
assert_eq_approx(curve.move_b(-100.0, -555.0*mu0), -500.0, 0.1); // back (leftward) travel to H=-55
|
||||
assert_eq_approx(curve.move_b(-500.0, -456.0*mu0), -500.0, 0.1); // interior (rightward) travel to H=44
|
||||
assert_eq_approx(curve.move_b(-500.0, -354.0*mu0), -400.0, 0.1); // interior (rightward) travel to H=46
|
||||
assert_eq_approx(curve.move_b(-400.0, -253.0*mu0), -300.0, 0.1); // interior (rightward) travel to H=47
|
||||
assert_eq_approx(curve.move_b(-300.0, 50.0*mu0), 0.0, 0.1); // interior (rightward) travel to H=50
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_interior() {
|
||||
const MU0: f32 = 1.2566370621219e-06;
|
||||
let mu0 = f32::mu0();
|
||||
let curve = MHPgram::new(50.0, 101.0, 500.0);
|
||||
// max M (right) happens at H=55; B = 555*MU0;
|
||||
// min M (right) happens at H=45; B = -455*MU0;
|
||||
// max M (left) happens at H=-45; B = 455*MU0;
|
||||
// min M (left) happens at H=-55; B = -555*MU0;
|
||||
// max M (right) happens at H=55; B = 555*mu0;
|
||||
// min M (right) happens at H=45; B = -455*mu0;
|
||||
// max M (left) happens at H=-45; B = 455*mu0;
|
||||
// min M (left) happens at H=-55; B = -555*mu0;
|
||||
|
||||
assert_eq_approx(curve.move_b(0.0, 40.0*MU0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, 50.0*MU0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, -40.0*MU0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, -50.0*MU0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, 40.0*mu0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, 50.0*mu0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, -40.0*mu0), 0.0, 0.1);
|
||||
assert_eq_approx(curve.move_b(0.0, -50.0*mu0), 0.0, 0.1);
|
||||
|
||||
assert_eq_approx(curve.move_b(-400.0, -400.0*MU0), -400.0, 0.1); // rightward travel from H=-54 to NOT H=-53.5
|
||||
assert_eq_approx(curve.move_b(-400.0, -355.0*MU0), -400.0, 0.1); // rightward travel from H=-54 to H=45
|
||||
assert_eq_approx(curve.move_b(-400.0, -354.0*MU0), -400.0, 0.1); // rightward travel from H=-54 to H=46
|
||||
assert_eq_approx(curve.move_b(-400.0, 5000.0*MU0), 500.0, 0.1); // rightward travel from H=-54 to H>>55
|
||||
assert_eq_approx(curve.move_b(-400.0, -400.0*mu0), -400.0, 0.1); // rightward travel from H=-54 to NOT H=-53.5
|
||||
assert_eq_approx(curve.move_b(-400.0, -355.0*mu0), -400.0, 0.1); // rightward travel from H=-54 to H=45
|
||||
assert_eq_approx(curve.move_b(-400.0, -354.0*mu0), -400.0, 0.1); // rightward travel from H=-54 to H=46
|
||||
assert_eq_approx(curve.move_b(-400.0, 5000.0*mu0), 500.0, 0.1); // rightward travel from H=-54 to H>>55
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_exterior() {
|
||||
const MU0: f32 = 1.2566370621219e-06;
|
||||
let mu0 = f32::mu0();
|
||||
let curve = MHPgram::new(50.0, 101.0, 500.0);
|
||||
|
||||
assert_eq_approx(curve.move_b(500.0, 556.0*MU0), 500.0, 0.1); // exterior travel to H=56
|
||||
assert_eq_approx(curve.move_b(500.0, 5000.0*MU0), 500.0, 0.1); // exterior travel to H>>55
|
||||
assert_eq_approx(curve.move_b(500.0, 556.0*mu0), 500.0, 0.1); // exterior travel to H=56
|
||||
assert_eq_approx(curve.move_b(500.0, 5000.0*mu0), 500.0, 0.1); // exterior travel to H>>55
|
||||
|
||||
assert_eq_approx(curve.move_b(500.0, -5000.0*MU0), -500.0, 0.1); // exterior travel from H>>55 to H << -55
|
||||
assert_eq_approx(curve.move_b(-501.0, 454.0*MU0), 400.0, 0.1); // exterior travel from H<<-55 (rounding error) to H=54
|
||||
assert_eq_approx(curve.move_b(500.0, -5000.0*mu0), -500.0, 0.1); // exterior travel from H>>55 to H << -55
|
||||
assert_eq_approx(curve.move_b(-501.0, 454.0*mu0), 400.0, 0.1); // exterior travel from H<<-55 (rounding error) to H=54
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user