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

C#: Make Length and LengthSquared into methods in Quaternion. #71458

Merged
merged 1 commit into from
Jan 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ public readonly Basis Transposed()
/// <param name="quaternion">The quaternion to create the basis from.</param>
public Basis(Quaternion quaternion)
{
real_t s = 2.0f / quaternion.LengthSquared;
real_t s = 2.0f / quaternion.LengthSquared();

real_t xs = quaternion.x * s;
real_t ys = quaternion.y * s;
Expand Down
46 changes: 23 additions & 23 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,6 @@ readonly get
}
}

/// <summary>
/// Returns the length (magnitude) of the quaternion.
/// </summary>
/// <seealso cref="LengthSquared"/>
/// <value>Equivalent to <c>Mathf.Sqrt(LengthSquared)</c>.</value>
public readonly real_t Length
{
get { return Mathf.Sqrt(LengthSquared); }
}

/// <summary>
/// Returns the squared length (squared magnitude) of the quaternion.
/// This method runs faster than <see cref="Length"/>, so prefer it if
/// you need to compare quaternions or need the squared length for some formula.
/// </summary>
/// <value>Equivalent to <c>Dot(this)</c>.</value>
public readonly real_t LengthSquared
{
get { return Dot(this); }
}

/// <summary>
/// Returns the angle between this quaternion and <paramref name="to"/>.
/// This is the magnitude of the angle you would need to rotate
Expand Down Expand Up @@ -355,7 +334,7 @@ public readonly bool IsFinite()
/// <returns>A <see langword="bool"/> for whether the quaternion is normalized or not.</returns>
public readonly bool IsNormalized()
{
return Mathf.Abs(LengthSquared - 1) <= Mathf.Epsilon;
return Mathf.Abs(LengthSquared() - 1) <= Mathf.Epsilon;
}

public readonly Quaternion Log()
Expand All @@ -364,13 +343,34 @@ public readonly Quaternion Log()
return new Quaternion(v.x, v.y, v.z, 0);
}

/// <summary>
/// Returns the length (magnitude) of the quaternion.
/// </summary>
/// <seealso cref="LengthSquared"/>
/// <value>Equivalent to <c>Mathf.Sqrt(LengthSquared)</c>.</value>
public readonly real_t Length()
{
return Mathf.Sqrt(LengthSquared());
}

/// <summary>
/// Returns the squared length (squared magnitude) of the quaternion.
/// This method runs faster than <see cref="Length"/>, so prefer it if
/// you need to compare quaternions or need the squared length for some formula.
/// </summary>
/// <value>Equivalent to <c>Dot(this)</c>.</value>
public readonly real_t LengthSquared()
{
return Dot(this);
}

/// <summary>
/// Returns a copy of the quaternion, normalized to unit length.
/// </summary>
/// <returns>The normalized quaternion.</returns>
public readonly Quaternion Normalized()
{
return this / Length;
return this / Length();
}

/// <summary>
Expand Down