Cleanup math
This commit is contained in:
parent
aa6779ff4b
commit
b22c36a983
|
|
@ -536,14 +536,13 @@ struct Rect {
|
|||
|
||||
impl Rect {
|
||||
fn γ(&self) -> f32 { self.external_halflength / self.internal_halflength }
|
||||
fn ri(&self) -> f32 { self.internal_halflength }
|
||||
fn a(&self) -> f32 { (1.0 - self.γ()) / self.ri() }
|
||||
fn a(&self) -> f32 { -(self.γ() - 1.0) / self.internal_halflength }
|
||||
fn b(&self) -> f32 { 2.0 * self.γ() - 1.0 }
|
||||
|
||||
fn root(&self, x: f32) -> f32 { ((2.0 * self.γ() - 1.0).powi(2) + 4.0 * (1.0 - self.γ()) * x / self.ri()).sqrt() }
|
||||
fn root(&self, x: f32) -> f32 { (self.b().powi(2) + 4.0 * self.a() * x).sqrt() }
|
||||
fn d(&self, u: f32) -> f32 { 2.0 * self.a() * u + self.b() }
|
||||
pub fn x(&self, u: f32) -> f32 { (self.a() * u.abs() + self.b()) * u }
|
||||
pub fn u(&self, x: f32) -> f32 { 0.5 * self.ri() * (1.0 - 2.0 * self.γ() + self.root(x.abs())) / (1.0 - self.γ()) * x.signum() }
|
||||
pub fn u(&self, x: f32) -> f32 { 0.5 * x.signum() * (-self.b() + self.root(x.abs())) / self.a() }
|
||||
pub fn dx(&self, u: f32, du: f32) -> f32 { du * self.d(u.abs()) }
|
||||
pub fn du(&self, x: f32, dx: f32) -> f32 { dx / self.root(x.abs()) }
|
||||
}
|
||||
|
|
@ -608,7 +607,7 @@ impl Metric for Rect {
|
|||
let sy = if y <= self.external_halflength { 1.0 / self.root(y) } else { 1.0 };
|
||||
let s = sy.lerp(1.0, sx);
|
||||
let dsx_dx = if x > self.inner_radius && x < self.outer_radius { pos.x.signum() / (self.outer_radius - self.inner_radius) } else { 0.0 };
|
||||
let dsy_dy = if y <= self.external_halflength { -2.0 * (1.0 - self.γ()) / self.internal_halflength * sy.powi(3) * pos.y.signum() } else { 0.0 };
|
||||
let dsy_dy = if y <= self.external_halflength { -2.0 * pos.y.signum() * self.a() * sy.powi(3) } else { 0.0 };
|
||||
let ds2_dx = 2.0 * s * (1.0 - sy) * dsx_dx;
|
||||
let ds2_dy = 2.0 * s * (1.0 - sx) * dsy_dy;
|
||||
[
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user