summaryrefslogtreecommitdiff
path: root/src/animation.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/animation.zig')
-rw-r--r--src/animation.zig21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/animation.zig b/src/animation.zig
index 37d74813..ce0b382a 100644
--- a/src/animation.zig
+++ b/src/animation.zig
@@ -280,10 +280,6 @@ pub fn sample(easing: Easing, raw: f32) f32 {
};
}
-pub fn progress(effect: Transition, frame: u16) f32 {
- return progressEased(effect.easing(), effect.frames(), frame);
-}
-
fn progressEased(easing: Easing, frames: u16, frame: u16) f32 {
if (frames <= 1 or frame >= frames - 1) return 1.0;
return sample(easing, @as(f32, @floatFromInt(frame)) / @as(f32, @floatFromInt(frames - 1)));
@@ -460,12 +456,12 @@ test "easing presets have exact endpoints and intended shapes" {
test "transition progress completes exactly" {
inline for (std.enums.values(Transition)) |effect| {
- try std.testing.expectEqual(@as(f32, 1), progress(effect, effect.frames()));
+ try std.testing.expectEqual(@as(f32, 1), progressEased(effect.easing(), effect.frames(), effect.frames()));
if (effect.frames() > 0)
- try std.testing.expectEqual(@as(f32, 1), progress(effect, effect.frames() - 1));
- try std.testing.expectEqual(@as(f32, 1), progress(effect, std.math.maxInt(u16)));
+ try std.testing.expectEqual(@as(f32, 1), progressEased(effect.easing(), effect.frames(), effect.frames() - 1));
+ try std.testing.expectEqual(@as(f32, 1), progressEased(effect.easing(), effect.frames(), std.math.maxInt(u16)));
}
- try std.testing.expectEqual(@as(f32, 1), progress(.off, 0));
+ try std.testing.expectEqual(@as(f32, 1), progressEased(Transition.off.easing(), Transition.off.frames(), 0));
const shrinking = lerpBox(.{ .w = 100, .h = 40 }, .{}, sample(.out_back, 0.8));
try std.testing.expectEqual(@as(f32, 0), shrinking.w);
@@ -639,7 +635,7 @@ test "opening presets separate geometry and content transitions" {
};
try std.testing.expectEqual(target, closing.contentBox());
closing.frame = 2;
- try std.testing.expect(closing.amount() < progress(.vertical, closing.frame));
+ try std.testing.expect(closing.amount() < progressEased(Transition.vertical.easing(), Transition.vertical.frames(), closing.frame));
}
test "the ordered dissolve reveals a 4x4 block evenly, each cell once" {
@@ -740,11 +736,8 @@ pub const Motion = struct {
return spring.value(@intFromFloat(u * std.time.ns_per_s));
}
- /// The same move's speed at `u`, in lengths per unit of `u`.
- pub fn speed(motion: Motion, u: f32) f32 {
- return motion.speedFrom(u, 0);
- }
-
+ /// The same move's speed at `u`, in lengths per unit of `u`, set off at
+ /// `launch` as `easeFrom` is.
pub fn speedFrom(motion: Motion, u: f32, launch: f32) f32 {
const h: f32 = 1.0 / 256.0;
return (motion.easeFrom(@min(1, u + h), launch) - motion.easeFrom(@max(0, u - h), launch)) / (@min(1, u + h) - @max(0, u - h));