Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reimplement bezier with correct behavior #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ffigiel
Copy link

@ffigiel ffigiel commented Nov 22, 2021

Following the discussion in #4, this PR fixes the bezier function so that it behaves correctly.
The problem was the invalid assumption that the x coordinate of the calculated point is equal to the time parameter in the equation. The new implementation performs a binary search to find a point whose x coordinate is closer to the time parameter.

The original point-calculating function was replaced with a simpler one, and turned out to be much more performant (even after some optimizations).

I came up with a few binary search implementations, but they all perform kinda the same. I also asked @MartinSStewart if he still had his binary search implementation - he had it, but for some reason it was much slower than others, so it was abandoned.

Here are the benchmarks. This PR usesbezierBinFixed and bezierPointSimple implementations.
The repo with the benchmarks can be found here.

Should the benchmarks be included in this repo?

@@ -73,28 +73,93 @@ linear =

{-| A cubic bezier function using 4 parameters: x and y position of first control point, and x and y position of second control point.

See [here](http://greweb.me/glsl-transition/example/ "glsl-transitions") for examples or [here](http://cubic-bezier.com/ "tester") to test.
See [here](http://cubic-bezier.com/ "tester") to test.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this link since it does not work anymore. Are there other resources we could link to?

lerp from to v =
from + (to - from) * v
f =
bezierPoint x1 y1 x2 y2
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git kinda shredded this diff, it's better to view it side-by-side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant