Skip to content

Commit

Permalink
Add determinant to Transform2D
Browse files Browse the repository at this point in the history
Update transform2d.rs

update again, fix error

expose the determinant for Transform2D

Update transform2d_test.rs

lint

Update .gitignore

fix test

update feedback

Update transform2d_test.rs

Co-Authored-By: Jan Haller <[email protected]>
  • Loading branch information
Ughuuu and Bromeon committed Jun 22, 2024
1 parent cd31a83 commit 52e0ddd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ gen
*.bat
config.toml
exp.rs

# Mac specific
.DS_Store
14 changes: 13 additions & 1 deletion godot-core/src/builtin/transform2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()`_
Expand Down Expand Up @@ -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())
}

Expand Down
13 changes: 13 additions & 0 deletions itest/rust/src/builtin_tests/geometry/transform2d_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 52e0ddd

Please sign in to comment.