Handle bezier easing function returning negative values

This commit is contained in:
Kovid Goyal 2024-07-19 08:27:58 +05:30
parent e1730b4c84
commit 3db2ce33b1
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 9 deletions

View file

@ -159,7 +159,7 @@ cubic_bezier_easing_curve(void *p_, double t, monotonic_t duration) {
BezierParameters *p = p_;
// The longer the animation, the more precision we need
double epsilon = 1.0 / monotonic_t_to_ms(duration);
return solve_unit_bezier(p, t, epsilon);
return fabs(solve_unit_bezier(p, t, epsilon));
}
// }}}
@ -180,8 +180,8 @@ apply_easing_curve(const Animation *a, double val, monotonic_t duration) {
size_t idx = MIN((size_t)(val * a->count), a->count - 1);
animation_function *f = a->functions + idx;
double interval_size = 1. / a->count, interval_start = idx * interval_size;
val = (val - interval_start) / interval_size;
double ans = f->curve(&f->params, val, duration);
double scaled_val = (val - interval_start) / interval_size;
double ans = f->curve(&f->params, scaled_val, duration);
return f->y_at_start + unit_value(ans) * f->y_size;
}

View file

@ -676,14 +676,14 @@ collect_cursor_info(CursorRenderInfo *ans, Window *w, monotonic_t now, OSWindow
ans->opacity = 1;
if (cursor_blinking) {
if (animation_is_valid(OPT(animation.cursor))) {
monotonic_t den = OPT(cursor_blink_interval) * 2;
monotonic_t time_into_cycle = time_since_start_blink % den;
double frac_into_cycle = (double)time_into_cycle / (double)den;
ans->opacity = (float)apply_easing_curve(OPT(animation.cursor), frac_into_cycle, den);
set_maximum_wait(ms_to_monotonic_t(75));
monotonic_t duration = OPT(cursor_blink_interval) * 2;
monotonic_t time_into_cycle = time_since_start_blink % duration;
double frac_into_cycle = (double)time_into_cycle / (double)duration;
ans->opacity = (float)apply_easing_curve(OPT(animation.cursor), frac_into_cycle, duration);
set_maximum_wait(ms_to_monotonic_t(50));
} else {
monotonic_t n = time_since_start_blink / OPT(cursor_blink_interval);
ans->opacity = n % 2 == 0 ? 1 : 0;
ans->opacity = 1 - n % 2;
set_maximum_wait((n + 1) * OPT(cursor_blink_interval) - time_since_start_blink);
}
}