Skip to content

Commit f40bb8a

Browse files
Fix lerpOverTime (#6)
1 parent 24cdd20 commit f40bb8a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/zmath.zig

+5-2
Original file line numberDiff line numberDiff line change
@@ -1386,16 +1386,19 @@ test "zmath.lerpInverse" {
13861386
// Reference: https://www.gamedeveloper.com/programming/improved-lerp-smoothing-
13871387
pub inline fn lerpOverTime(v0: anytype, v1: anytype, rate: anytype, dt: anytype) @TypeOf(v0, v1) {
13881388
const t = std.math.exp2(-rate * dt);
1389-
return lerp(v0, v1, t);
1389+
return lerp(v1, v0, t);
13901390
}
13911391

13921392
pub inline fn lerpVOverTime(v0: anytype, v1: anytype, rate: anytype, dt: anytype) @TypeOf(v0, v1, rate, dt) {
13931393
const t = std.math.exp2(-rate * dt);
1394-
return lerpV(v0, v1, t);
1394+
return lerpV(v1, v0, t);
13951395
}
1396+
13961397
test "zmath.lerpOverTime" {
13971398
try expect(math.approxEqAbs(f32, lerpVOverTime(0.0, 1.0, 1.0, 1.0), 0.5, 0.0005));
13981399
try expect(math.approxEqAbs(f32, lerpVOverTime(0.5, 1.0, 1.0, 1.0), 0.75, 0.0005));
1400+
try expect(math.approxEqAbs(f32, lerpVOverTime(0.0, 1.0, 1.0, 0.0), 0.0, 0.0005));
1401+
try expect(math.approxEqAbs(f32, lerpVOverTime(0.0, 1.0, 1.0, std.math.inf(f32)), 1.0, 0.0005));
13991402
try expectVecApproxEqAbs(lerpOverTime(f32x4(0, 0, 10, 10), f32x4(100, 200, 100, 100), 1.0, 1.0), f32x4(50, 100, 55, 55), 0.0005);
14001403
}
14011404

0 commit comments

Comments
 (0)