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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 30 additions & 23 deletions sources/core/Stride.Core.Mathematics/Int3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,6 @@ public Int3(int[] values)
Z = values[2];
}

/// <summary>
/// Creates a new instance of the <see cref="Int3"/> struct by rounding the X, Y, and Z components of a <see cref="Vector3"/> struct to the nearest integer.
/// </summary>
public Int3 RoundToInt3(Vector3 value)
{
X = (int)Math.Round(value.X);
Y = (int)Math.Round(value.Y);
Z = (int)Math.Round(value.Z);
}

/// <summary>
/// Gets or sets the component at the specified index.
/// </summary>
Expand Down Expand Up @@ -196,16 +186,16 @@ public Int3 RoundToInt3(Vector3 value)
/// </remarks>
public int Length()
{
return (int)Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
return (int)MathF.Sqrt((X * X) + (Y * Y) + (Z * Z));
}

/// <summary>
/// Calculates the unrounded length of the vector.
/// Calculates the untruncated length of the vector.
/// </summary>
/// <returns>The length of the vector unrounded.</returns>
/// <returns>The length of the vector untruncated.</returns>
public float LengthUntruncated()
{
return Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
return (float)MathF.Sqrt((X * X) + (Y * Y) + (Z * Z));
}

/// <summary>
Expand Down Expand Up @@ -551,7 +541,32 @@ public static Int3 Min(Int3 left, Int3 right)
Min(ref left, ref right, out result);
return result;
}


/// <summary>
/// Returns a vector containing the rounded values of the specified vector.
/// </summary>
/// <param name="value">The source vector.</param>
/// <param name="result">When the method completes, contains an new vector composed of the rounded values of the specified vector.</param>
/// <param name="rounding">The rounding strategy to use.</param>
public static void Round(in Vector3 value, out Int3 result, MidpointRounding rounding = default)
{
result.X = (int)MathF.Round(value.X, rounding);
result.Y = (int)MathF.Round(value.Y, rounding);
result.Z = (int)MathF.Round(value.Z, rounding);
}

/// <summary>
/// Returns a vector containing the rounded values of the specified vector.
/// </summary>
/// <param name="value">The source vector.</param>
/// <param name="rounding">The rounding strategy to use.</param>
/// <returns>A vector containing the rounded values of the source vector.</returns>
public static Int3 Round(in Vector3 value, MidpointRounding rounding = default)
{
Round(in value, out var result, rounding);
return result;
}

/// <summary>
/// Adds two vectors.
/// </summary>
Expand Down Expand Up @@ -790,14 +805,6 @@ public void Deconstruct(out int x, out int y, out int z)
y = Y;
z = Z;
}

/// <summary>
/// Preforms an implicit conversion from <see cref="Stride.Core.Mathematics.Int3"/> to <see cref="Stride.Core.Mathematics.Vector3"/>.
/// </summary>
public static implicit operator Vector3(Int3 value)
{
return new Vector3(value);
}

#if WPFInterop
/// <summary>
Expand Down
10 changes: 0 additions & 10 deletions sources/core/Stride.Core.Mathematics/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,6 @@ public Vector3(float[] values)
Z = values[2];
}

/// <summary>
/// Initializes a new instance of the <see cref="Stride.Core.Mathematics.Vector3"/> struct given a <see cref="Stride.Core.Mathematics.Int3"/>.
/// </summary>
public Vector3(Int3 value)
{
X = value.X;
Y = value.Y;
Z = value.Z;
}

/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
Expand Down