diff --git a/.gitignore b/.gitignore index a4a6a0cee..d3d3bb272 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ gen *.bat config.toml exp.rs + +# Mac specific +.DS_Store diff --git a/godot-core/src/builtin/transform2d.rs b/godot-core/src/builtin/transform2d.rs index 7b20b56b5..47459eeaa 100644 --- a/godot-core/src/builtin/transform2d.rs +++ b/godot-core/src/builtin/transform2d.rs @@ -150,6 +150,18 @@ impl Transform2D { self.glam(|aff| aff.inverse()) } + /// Returns the determinant of the basis matrix. + /// + /// If the basis is uniformly scaled, then its determinant equals the square of the scale factor. + /// + /// 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. + /// + /// _Godot equivalent: `Transform2D.determinant()`_ + pub fn determinant(&self) -> real { + self.basis().determinant() + } + /// Returns the transform's rotation (in radians). /// /// _Godot equivalent: `Transform2D.get_rotation()`_ @@ -443,7 +455,7 @@ impl Basis2D { } /// Returns the determinant of the matrix. - pub(crate) fn determinant(&self) -> real { + pub fn determinant(&self) -> real { self.glam(|mat| mat.determinant()) } diff --git a/itest/rust/src/builtin_tests/geometry/transform2d_test.rs b/itest/rust/src/builtin_tests/geometry/transform2d_test.rs index 13ac9b9a9..4f848e5d4 100644 --- a/itest/rust/src/builtin_tests/geometry/transform2d_test.rs +++ b/itest/rust/src/builtin_tests/geometry/transform2d_test.rs @@ -57,6 +57,19 @@ fn transform2d_equiv() { ); } +#[cfg(since_api = "4.1")] +#[itest] +fn transform2d_determinant() { + let inner = InnerTransform2D::from_outer(&TEST_TRANSFORM); + let outer = TEST_TRANSFORM; + + assert_eq_approx!( + real::from_f64(inner.determinant()), + outer.determinant(), + "function: determinant\n" + ); +} + #[itest] fn transform2d_xform_equiv() { let vec = Vector2::new(1.0, 2.0);