Skip to content

Commit 8573e6f

Browse files
UghuuuBromeon
andcommitted
Add determinant to Transform2D
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 Update .gitignore Co-Authored-By: Jan Haller <[email protected]>
1 parent cd31a83 commit 8573e6f

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ gen
2323
*.bat
2424
config.toml
2525
exp.rs
26+
27+
# Mac specific
28+
.DS_Store

godot-core/src/builtin/transform2d.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ impl Transform2D {
150150
self.glam(|aff| aff.inverse())
151151
}
152152

153+
/// Returns the determinant of the basis matrix.
154+
///
155+
/// If the basis is uniformly scaled, then its determinant equals the square of the scale factor.
156+
///
157+
/// A negative determinant means the basis was flipped, so one part of the scale is negative.
158+
/// A zero determinant means the basis isn't invertible, and is usually considered invalid.
159+
///
160+
/// _Godot equivalent: `Transform2D.determinant()`_
161+
pub fn determinant(&self) -> real {
162+
self.basis().determinant()
163+
}
164+
153165
/// Returns the transform's rotation (in radians).
154166
///
155167
/// _Godot equivalent: `Transform2D.get_rotation()`_
@@ -443,7 +455,7 @@ impl Basis2D {
443455
}
444456

445457
/// Returns the determinant of the matrix.
446-
pub(crate) fn determinant(&self) -> real {
458+
pub fn determinant(&self) -> real {
447459
self.glam(|mat| mat.determinant())
448460
}
449461

itest/rust/src/builtin_tests/geometry/transform2d_test.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ fn transform2d_equiv() {
5757
);
5858
}
5959

60+
#[cfg(since_api = "4.1")]
61+
#[itest]
62+
fn transform2d_determinant() {
63+
let inner = InnerTransform2D::from_outer(&TEST_TRANSFORM);
64+
let outer = TEST_TRANSFORM;
65+
66+
assert_eq_approx!(
67+
real::from_f64(inner.determinant()),
68+
outer.determinant(),
69+
"function: determinant\n"
70+
);
71+
}
72+
6073
#[itest]
6174
fn transform2d_xform_equiv() {
6275
let vec = Vector2::new(1.0, 2.0);

0 commit comments

Comments
 (0)