Skip to content

Backporting the 3.2 solver to projects that embed bezier-easing #85

Open

Description

@gre

bezier-easing is embedded (copied or ported) in many projects, most of them with the 2015 implementation: an 11-sample table, then Newton-Raphson or bisection to find t for a given x. I've sent PRs to backport the 3.2 closed-form solver to them.

Why

  • A real bug on steep curves. With the old search, (1, 0, 0, 1) returns 0.348 instead of 0.431 at x = 0.4996, so the animation goes backwards for a frame around the middle. The same curve is CSS easeInOutExpo and what After Effects exports for 100% influence keyframes. Every copy I tested had it.
  • Precision. The old search was off by up to ~1e-3 (~8e-5 on ease-in / ease-out). The closed form is within ~1e-14 on regular curves and stays monotonic.
  • Speed and size. There's no table to build when a curve is created, and the code is usually smaller. With Hermes, RN's Easing.bezier calls are 3-5x faster.
  • Behavior change. Inputs outside [0, 1] now saturate to 0 / 1, as in 3.2. The old values there were unspecified and not a real extrapolation: ease(1.5) returned 0.897. lottie-web keeps the old search for that case and for its non-monotonic After Effects curves.

Each port was checked against 3.2 (bit-identical in JS, within 4e-15 in the other languages) and with the project's own tests, lint or a standalone harness.

Image

PRs

JavaScript / TypeScript:

Other languages:

The README showcase that lists these projects is in #84.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions