Skip to content

Add determinant to Transform2D #770

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

Merged
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you can add this to your ~/.gitconfig to avoid needing to add this to every project's .gitignore

[core]
	excludesfile = /home/<USER>/.gitignore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then populate ~/.gitignore with the relevant ignores

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't really mind this, as it's so common. If it achieves that not every single macOS contributor has to modify their global .gitconfig, then that's a win in my eyes.

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
Loading