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

[4.4 backport] C#: Expose Transform2D.Determinant() #72

Merged
Merged
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
17 changes: 9 additions & 8 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public readonly Vector2 Scale
{
get
{
real_t detSign = Mathf.Sign(BasisDeterminant());
real_t detSign = Mathf.Sign(Determinant());
return new Vector2(X.Length(), detSign * Y.Length());
}
}
Expand All @@ -59,7 +59,7 @@ public readonly real_t Skew
{
get
{
real_t detSign = Mathf.Sign(BasisDeterminant());
real_t detSign = Mathf.Sign(Determinant());
return Mathf.Acos(X.Normalized().Dot(detSign * Y.Normalized())) - Mathf.Pi * 0.5f;
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ readonly get
/// <returns>The inverse transformation matrix.</returns>
public readonly Transform2D AffineInverse()
{
real_t det = BasisDeterminant();
real_t det = Determinant();

if (det == 0)
throw new InvalidOperationException("Matrix determinant is zero and cannot be inverted.");
Expand All @@ -157,15 +157,16 @@ public readonly Transform2D AffineInverse()

/// <summary>
/// Returns the determinant of the basis matrix. If the basis is
/// uniformly scaled, its determinant is the square of the scale.
/// uniformly scaled, then its determinant equals the square of the
/// scale factor.
///
/// A negative determinant means the Y scale is negative.
/// A zero determinant means the basis isn't invertible,
/// and is usually considered invalid.
/// A negative determinant means the basis was flipped, so one part of
/// the scale is negative. A zero determinant means the basis isn't
/// invertible, and is usually considered invalid.
/// </summary>
/// <returns>The determinant of the basis matrix.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private readonly real_t BasisDeterminant()
public readonly real_t Determinant()
{
return (X.X * Y.Y) - (X.Y * Y.X);
}
Expand Down
Loading