This commit is contained in:
numzero 2024-06-10 14:52:57 +03:00
parent 69cc1904a8
commit e8fdd5f338

View File

@ -593,6 +593,16 @@ fn test_rect() {
assert_abs_diff_eq!(r.dx(10.0, r.du(r.x(10.0), 3.0)), 3.0, epsilon = 1.0e-5);
}
trait FloatExt2 {
fn lerp(&self, t: f32) -> f32;
}
impl FloatExt2 for (f32, f32) {
fn lerp(&self, t: f32) -> f32 {
self.0.lerp(self.1, t)
}
}
impl Metric for Rect {
fn sqrt_at(&self, pos: Vec2) -> Decomp2 {
let y = pos.y.abs();
@ -603,7 +613,7 @@ impl Metric for Rect {
assert!(sy > 0.0);
Decomp2 {
ortho: Mat2::IDENTITY,
diag: vec2(1.0, sy.lerp(1.0, sx)),
diag: vec2(1.0, (sy, 1.0).lerp(sx)),
}
}
@ -612,7 +622,7 @@ impl Metric for Rect {
let y = pos.y.abs();
let sx = ((x - self.inner_radius) / (self.outer_radius - self.inner_radius)).clamp(0.0, 1.0);
let sy = if y <= self.external_halflength { 1.0 / self.root(y) } else { 1.0 };
let s = sy.lerp(1.0, sx);
let s = (sy, 1.0).lerp(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 * pos.y.signum() * self.a() * sy.powi(3) } else { 0.0 };
let ds2_dx = 2.0 * s * (1.0 - sy) * dsx_dx;