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 #1769 and introduce an optional argument to specify a different r… #1964

Merged
merged 2 commits into from Oct 18, 2023

Conversation

Kryptos-FR
Copy link
Member

…ounding strategy if needed.

PR Details

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Kryptos-FR
Copy link
Member Author

Kryptos-FR commented Oct 18, 2023

I removed the new constructors because we already have conversion operators, so it's not needed. If someone wants to convert a Vector3 to an Int3 (or the opposite) they can just do:

Vector3 vec3 = new Vector3(1.0f, 1.0f, 1.0f);
Int3 int3 = (Int3)vec3;
vec3 = (Vector3)int3;

Comment on lines 551 to 556
public static void Round(ref Vector3 value, out Int3 result, MidpointRounding rounding = default)
{
result.X = (int)Math.Round(value.X, rounding);
result.Y = (int)Math.Round(value.Y, rounding);
result.Z = (int)Math.Round(value.Z, rounding);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace ref Vector3 value with in Vector3 value
MathF has an overload for midpoint rounding see https://learn.microsoft.com/en-us/dotnet/api/system.mathf.round?view=net-7.0

Copy link
Member Author

Choose a reason for hiding this comment

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

Replace ref Vector3 value with in Vector3 value

Those should be wider changes throughout the whole codebase. A lot of methods don't use the in keyword. For me that's outside this PR which is mostly a build fix.

MathF has an overload for midpoint rounding

Should I use MathF for the other places in that file (e.g. Sqrt and Pow)?

Copy link
Collaborator

@Eideren Eideren Oct 18, 2023

Choose a reason for hiding this comment

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

For me that's outside this PR

Fixing it later would be a breaking change, we can't have two methods whose signature only differ in whether they use the ref or in keyword afair.

A lot of methods don't use the in keyword.

I took care of a bunch of them a while ago but not all of them, no. So there's a bit of a mix right now.

Should I use MathF for the other places in that file (e.g. Sqrt and Pow)?

Yes please, as long as you touched those lines in this PR, we'll leave the rest of the file for another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

For Round I will use MathF.

However for Length() and LengthUntruncated() I think we should keep using Math. The rationale is that it is doing a square root of a multiplication of int. An int * int fits in a long and the equivalent floating point type is double. So to avoid overflows, we should only convert the result to float at the end. Although, it is probably already overflowing since we don't convert to long in the first place... 🤔

Ok, that's again a subject for another PR. For consistency I will also use MathF then.

@Eideren Eideren merged commit 3aac7c8 into stride3d:master Oct 18, 2023
10 of 14 checks passed
@Eideren
Copy link
Collaborator

Eideren commented Oct 18, 2023

Thanks !

@Eideren Eideren mentioned this pull request Oct 18, 2023
@Kryptos-FR Kryptos-FR deleted the feature/int3 branch October 18, 2023 21:46
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.

None yet

3 participants