Skip to content

Commit

Permalink
Merge pull request #71458 from raulsntos/dotnet/quaternion
Browse files Browse the repository at this point in the history
C#: Make `Length` and `LengthSquared` into methods in `Quaternion`.
  • Loading branch information
akien-mga committed Jan 16, 2023
2 parents 88c81bf + 28a8caa commit ba55172
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
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 @@ -787,7 +787,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

0 comments on commit ba55172

Please sign in to comment.