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 bezier curve unit tests ocassionally failing #6240

Merged
merged 8 commits into from
Jul 10, 2024

Conversation

latekvo
Copy link
Contributor

@latekvo latekvo commented Jul 9, 2024

Summary

Reanimated unit test workflow occasionally got triggered due to math rounding errors.
example failed workflow: link

Test plan

Run the following code which uses values known to cause high-rounding-error bezier curve.

const a = 0.9996061654962731;
const b = 0.39049518409730366;
const c = 0.0006689560738639688;
const d = 0.046608138920604114;

const curve = Bezier(a, b, c, d);

Create mathematical reflection of curve1:

const curveReflected = Bezier(b, a, d, c);

Cancel out both functions to get their identity + their error rate:

const almostIdentity = (x: number) => curve(curveReflected(x));

Measure error rate at 0.27 and 0.31 points of the almostIdentity as these are known to have the over-limit values on this particular curve.

const errorOne = Math.abs(0.27 - almostIdentity(0.27));
const errorTwo = Math.abs(0.31 - almostIdentity(0.31));

console.log(errorOne);
console.log(errorTwo);

Notice how these two values are higher than the previous limit of 0.01.

Which value is better?

Upon further testing of over 600000 cases, the highest value i encountered was 0.017.
It is likely it's impossible for this value to be higher than 0.02 due to Bezier implementation, thus I'm changing the precision limit to 0.02

@latekvo latekvo requested a review from piaskowyk July 9, 2024 11:16
@latekvo latekvo marked this pull request as ready for review July 9, 2024 11:16
@latekvo latekvo added this pull request to the merge queue Jul 10, 2024
Merged via the queue into main with commit 35cb3ce Jul 10, 2024
5 checks passed
@latekvo latekvo deleted the @latekvo/fix-bezier-tests-failing branch July 10, 2024 07:39
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.

2 participants