Skip to content

fix: reimplement bezier with correct behavior#7

Open
ffigiel wants to merge 3 commits intoelm-community:masterfrom
ffigiel:fix-bezier
Open

fix: reimplement bezier with correct behavior#7
ffigiel wants to merge 3 commits intoelm-community:masterfrom
ffigiel:fix-bezier

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?

{-| 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