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

Wrong implementation of "SinusoidalCenter" #863

Open
SamFisher940425 opened this issue Nov 29, 2024 · 2 comments
Open

Wrong implementation of "SinusoidalCenter" #863

SamFisher940425 opened this issue Nov 29, 2024 · 2 comments
Labels
bug pending Pending new release; already merged but not released in a version

Comments

@SamFisher940425
Copy link

Describe the bug
There is an error in the function implementation of "SinusoidalCenter" that caused the output to be abnormal when the input was greater than 0.5

To Reproduce
Steps to reproduce the behavior:
In the file "src/internal/animations/NeoEase.h", line 214. In the function "SinusoidalCenter", I think there is an extra parenthesis in the
code "return (-0.5f * (cos(PI * (unitValue-0.5f)) + 1.0f));", I think the correct one is "return (-0.5f * cos(PI * (unitValue - 0.5f)) + 1.0f);"

Expected behavior
I think the correct one is "return (-0.5f * cos(PI * (unitValue - 0.5f)) + 1.0f);", according to the picture "sinusoidal.png"

Development environment (please complete the following information):

  • Library version V2.8.0
@Makuna Makuna added the investigating Currently under investigation for more understanding of the problem. label Nov 29, 2024
@SamFisher940425
Copy link
Author

image
I've created a scatterplot using excel to illustrate the problem, and I hope it helps

@Makuna
Copy link
Owner

Makuna commented Dec 3, 2024

Its currently implemented as

    static float SinusoidalCenter(float unitValue)
    {
        if (unitValue < 0.5f)
        {
            return (0.5f * sin(PI * unitValue));
        }
        else
        {
            return (-0.5f * (cos(PI * (unitValue-0.5f)) + 1.0f));
        }  
    }

In my spread sheet test, it is implemented as

=IF(    N5<0.5,     0.5 * SIN(N5*PI()),       -0.5 * COS((N5-0.5) * PI()) + 1 )

You can see the translation from spread sheet to c++ the extra () causes the issue.

So, it should be

            return (-0.5f * cos(PI * (unitValue-0.5f)) + 1.0f);

@Makuna Makuna added bug and removed investigating Currently under investigation for more understanding of the problem. labels Dec 3, 2024
@Makuna Makuna added the pending Pending new release; already merged but not released in a version label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug pending Pending new release; already merged but not released in a version
Projects
None yet
Development

No branches or pull requests

2 participants