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

Vector2/4 Lerp behavior changed for .NET 5 #18937

Closed
tannergooding opened this issue Jun 13, 2020 · 1 comment · Fixed by #19416
Closed

Vector2/4 Lerp behavior changed for .NET 5 #18937

tannergooding opened this issue Jun 13, 2020 · 1 comment · Fixed by #19416
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 5 Work items for the .NET 5 release doc-idea Indicates issues that are suggestions for new topics [org][type][category]

Comments

@tannergooding
Copy link
Member

Vector2/3 Lerp behavior changed for .NET 5

Vector2.Lerp(value1, value2, amount) and Vector4.Lerp(value1, value2, amount) were implemented as value1 + (value2 - value1) * amount. However, due to floating-point rounding error this will not always return value2 when amount == 1.0f.

The implementation was updated to use the same algorithm as Vector3.Lerp(value1, value2, amount) which is (value1 * (1.0f - amount)) + (value2 * amount). This algorithm correctly accounts for the rounding error and also allows the algorithm to be freely optimized using FusedMultiplyAdd when available.

Version introduced

.NET 5

Old behavior

For certain inputs, when amount was 1.0f the result would not be precisely value2.

New behavior

When amount is 1.0f, the result will be precisely value2.

Reason for change

The result would not be correctly interpolated as you could never get value2 as a result for certain inputs.

Recommended action

If maintaining the old behavior is desired, the user could implement their own Lerp function that uses the previous algorithm: value1 + (value2 - value1) * amount

Category

Core .NET libraries

Affected APIs

Vector2.Lerp(Vector2, Vector2, Single)
Vector4.Lerp(Vector4, Vector4, Single)


Issue metadata

  • Issue type: breaking-change
@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged breaking-change Indicates a .NET Core breaking change labels Jun 13, 2020
@tannergooding
Copy link
Member Author

tannergooding commented Jun 13, 2020

This is relevant for:

It should be going out in preview 7.

@gewarren gewarren self-assigned this Jun 17, 2020
@gewarren gewarren added doc-idea Indicates issues that are suggestions for new topics [org][type][category] 🏁 Release: .NET 5 Work items for the .NET 5 release and removed ⌚ Not Triaged Not triaged labels Jun 17, 2020
@gewarren gewarren changed the title Vector2/3 Lerp behavior changed for .NET 5 Vector2/4 Lerp behavior changed for .NET 5 Jul 10, 2020
gewarren added a commit to gewarren/docs that referenced this issue Jul 10, 2020
gewarren added a commit that referenced this issue Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 5 Work items for the .NET 5 release doc-idea Indicates issues that are suggestions for new topics [org][type][category]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants