Rename stuff to what it is, not how it’s used
This commit is contained in:
parent
61e861816d
commit
0ae05fd730
|
|
@ -615,8 +615,8 @@ struct Tube {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tube {
|
impl Tube {
|
||||||
fn fx(&self) -> fns::TubeX { fns::TubeX { min: self.inner_radius, max: self.outer_radius } }
|
fn fx(&self) -> fns::LinearLimiter { fns::LinearLimiter { min: self.inner_radius, max: self.outer_radius } }
|
||||||
fn fy(&self) -> fns::TubeY { fns::TubeY { internal: self.internal_halflength, external: self.external_halflength } }
|
fn fy(&self) -> fns::QuadraticAccelerator { fns::QuadraticAccelerator { internal: self.internal_halflength, external: self.external_halflength } }
|
||||||
|
|
||||||
pub fn y(&self, v: f32) -> f32 { self.fy().x(v) }
|
pub fn y(&self, v: f32) -> f32 { self.fy().x(v) }
|
||||||
pub fn v(&self, y: f32) -> f32 { self.fy().u(y) }
|
pub fn v(&self, y: f32) -> f32 { self.fy().u(y) }
|
||||||
|
|
@ -627,17 +627,17 @@ impl Tube {
|
||||||
mod fns {
|
mod fns {
|
||||||
use crate::FloatExt2;
|
use crate::FloatExt2;
|
||||||
|
|
||||||
pub struct TubeX {
|
pub struct LinearLimiter {
|
||||||
pub min: f32,
|
pub min: f32,
|
||||||
pub max: f32,
|
pub max: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TubeX {
|
impl LinearLimiter {
|
||||||
pub fn value(&self, x: f32) -> f32 { (self.min, self.max).inverse_lerp(x.abs()).clamp(0.0, 1.0) }
|
pub fn value(&self, x: f32) -> f32 { (self.min, self.max).inverse_lerp(x.abs()).clamp(0.0, 1.0) }
|
||||||
pub fn derivative(&self, x: f32) -> f32 { if x.abs() > self.min && x.abs() < self.max { x.signum() / (self.max - self.min) } else { 0.0 } }
|
pub fn derivative(&self, x: f32) -> f32 { if x.abs() > self.min && x.abs() < self.max { x.signum() / (self.max - self.min) } else { 0.0 } }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TubeY {
|
pub struct QuadraticAccelerator {
|
||||||
pub internal: f32,
|
pub internal: f32,
|
||||||
pub external: f32,
|
pub external: f32,
|
||||||
}
|
}
|
||||||
|
|
@ -652,7 +652,7 @@ mod fns {
|
||||||
if t.abs() <= lim { f(t) } else { val }
|
if t.abs() <= lim { f(t) } else { val }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TubeY {
|
impl QuadraticAccelerator {
|
||||||
fn a(&self) -> f32 { -(self.external - self.internal) / self.internal.powi(2) }
|
fn a(&self) -> f32 { -(self.external - self.internal) / self.internal.powi(2) }
|
||||||
fn b(&self) -> f32 { 2.0 * self.external / self.internal - 1.0 }
|
fn b(&self) -> f32 { 2.0 * self.external / self.internal - 1.0 }
|
||||||
fn root(&self, x: f32) -> f32 { (self.b().powi(2) + 4.0 * self.a() * x.abs()).sqrt() }
|
fn root(&self, x: f32) -> f32 { (self.b().powi(2) + 4.0 * self.a() * x.abs()).sqrt() }
|
||||||
|
|
@ -669,8 +669,8 @@ mod fns {
|
||||||
use approx::{abs_diff_eq, AbsDiffEq, assert_abs_diff_eq};
|
use approx::{abs_diff_eq, AbsDiffEq, assert_abs_diff_eq};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tube_x() {
|
fn test_linear_limiter() {
|
||||||
let testee = super::TubeX { min: 20.0, max: 30.0 };
|
let testee = super::LinearLimiter { min: 20.0, max: 30.0 };
|
||||||
let ε = 1.0e-4f32;
|
let ε = 1.0e-4f32;
|
||||||
let δ = 1.0 / 8.0; // Mathematically, you want this to be small. Computationally, you don’t.
|
let δ = 1.0 / 8.0; // Mathematically, you want this to be small. Computationally, you don’t.
|
||||||
let margin = 1.0 / 16.0;
|
let margin = 1.0 / 16.0;
|
||||||
|
|
@ -695,8 +695,8 @@ mod fns {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tube_y() {
|
fn test_quadratic_accelerator() {
|
||||||
let testee = super::TubeY { internal: 100.0, external: 150.0 };
|
let testee = super::QuadraticAccelerator { internal: 100.0, external: 150.0 };
|
||||||
let ε = 1.0e-4f32;
|
let ε = 1.0e-4f32;
|
||||||
let δ = 1.0 / 8.0; // Mathematically, you want this to be small. Computationally, you don’t.
|
let δ = 1.0 / 8.0; // Mathematically, you want this to be small. Computationally, you don’t.
|
||||||
let margin = 1.0 / 16.0;
|
let margin = 1.0 / 16.0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user