Skip to content

Commit

Permalink
Partially fix tests
Browse files Browse the repository at this point in the history
Some of the tests fail due to an ICE, so it's hard to tell what's wrong
(if there is anything wrong on our side).

A lot of the math tests are failing too, but the values are very close
to the expected values though. Perhaps the EPSILON is lower than it was
before?
  • Loading branch information
Demindiro committed Mar 23, 2021
1 parent 8700eb9 commit 392c6c1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
13 changes: 13 additions & 0 deletions gdnative-core/src/core_types/geom/basis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ mod tests {

let vector = Vector3::new(4.0, 5.0, 6.0);

dbg!(basis.tdotx(vector) - 32.0);
dbg!(basis.tdoty(vector) - 47.0);
dbg!(basis.tdotz(vector) - 62.0);
dbg!(std::f32::EPSILON);
assert!((basis.tdotx(vector) - 32.0).abs() < std::f32::EPSILON);
assert!((basis.tdoty(vector) - 47.0).abs() < std::f32::EPSILON);
assert!((basis.tdotz(vector) - 62.0).abs() < std::f32::EPSILON);
Expand Down Expand Up @@ -666,6 +670,7 @@ mod tests {
fn euler() {
let (_b, bn) = test_inputs();

dbg!(bn.to_euler());
assert!(Vector3::new(0.57079, 0.310283, 0.760213).is_equal_approx(bn.to_euler()));
}

Expand All @@ -678,6 +683,7 @@ mod tests {
Vector3::new(-0.288147, 0.94041, 0.180557),
Vector3::new(-0.95445, -0.297299, 0.025257),
]);
dbg!(expected, &b.orthonormalized());
assert!(expected.is_equal_approx(&b.orthonormalized()));
}

Expand All @@ -690,6 +696,7 @@ mod tests {
Vector3::new(0.012407, -0.040492, -0.007774),
Vector3::new(-0.682131, -0.212475, 0.018051),
]);
dbg!(expected, b.scaled(&Vector3::new(0.677813, -0.043058, 0.714685)));
assert!(expected.is_equal_approx(&b.scaled(&Vector3::new(0.677813, -0.043058, 0.714685))));
}

Expand All @@ -703,13 +710,15 @@ mod tests {
Vector3::new(-0.467094, 0.697765, -0.54309),
Vector3::new(-0.569663, -0.707229, -0.418703),
]);
dbg!(expected, b.rotated(r, 1.0));
assert!(expected.is_equal_approx(&b.rotated(r, 1.0)));
}

#[test]
fn to_quat() {
let (b, _bn) = test_inputs();

dbg!(b.to_quat());
assert!(Quat::new(-0.167156, 0.677813, -0.043058, 0.714685).is_equal_approx(&b.to_quat()));
}

Expand All @@ -734,13 +743,15 @@ mod tests {
Vector3::new(-0.165055, 0.94041, -0.297299),
Vector3::new(0.98324, 0.180557, 0.025257),
]);
dbg!(expected, b.transposed());
assert!(expected.is_equal_approx(&b.transposed()));
}

#[test]
fn xform() {
let (b, _bn) = test_inputs();

dbg!(b.xform(Vector3::new(0.5, 0.7, -0.2)));
assert!(Vector3::new(-0.273471, 0.478102, -0.690386)
.is_equal_approx(b.xform(Vector3::new(0.5, 0.7, -0.2))));
}
Expand All @@ -749,6 +760,7 @@ mod tests {
fn xform_inv() {
let (b, _bn) = test_inputs();

dbg!(b.xform(Vector3::new(0.077431, -0.165055, 0.98324)));
assert!(Vector3::new(-0.884898, -0.460316, 0.071165)
.is_equal_approx(b.xform_inv(Vector3::new(0.077431, -0.165055, 0.98324))));
}
Expand All @@ -762,6 +774,7 @@ mod tests {
Vector3::new(-0.165055, 0.94041, -0.297299),
Vector3::new(0.98324, 0.180557, 0.025257),
]);
dbg!(b.inverted(), expected);
assert!(expected.is_equal_approx(&b.inverted()));
}
}
4 changes: 4 additions & 0 deletions gdnative-core/src/core_types/geom/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ mod test {

let expected_valid = Plane::from_coordinates(0.447214, 0.0, -0.894427, -0.447214);

dbg!(expected_valid);
assert!(Plane::from_points(a, b, c)
.unwrap()
.is_equal_approx(expected_valid));
Expand Down Expand Up @@ -239,6 +240,8 @@ mod test {
let d = Plane::from_coordinates(0.01, 0.02, 0.4, 0.16);
let e = Plane::from_coordinates(0.01, 0.02, 0.4, 0.32);

dbg!(p.intersect_3(b, c));
dbg!(expected);
assert!(p.intersect_3(b, c).unwrap().is_equal_approx(expected));
assert_eq!(p.intersect_3(d, e), None);
}
Expand Down Expand Up @@ -284,6 +287,7 @@ mod test {
fn normalize() {
let (p, _v) = test_inputs();

dbg!(p.normalize());
assert!(p.normalize().is_equal_approx(Plane::from_coordinates(
0.218218, 0.436436, 0.872872, 1.745743
)));
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod access;
mod byte_array;
mod color;
mod color_array;
mod dictionary;
mod float32_array;
mod int32_array;
mod node_path;
Expand All @@ -25,6 +24,7 @@ mod vector3_array;

pub mod error;
pub mod vector3;
pub mod dictionary;

pub use geom::*;

Expand Down
1 change: 0 additions & 1 deletion gdnative-core/src/core_types/quat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use approx::relative_eq;
use glam;

#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
Expand Down
2 changes: 2 additions & 0 deletions gdnative-core/src/core_types/vector3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl Vector3 {
/// Returns the axis of the vector's largest value. See `Axis` enum.
/// If all components are equal, this method returns `Axis::X`.
#[inline]
#[allow(clippy::collapsible-if)]
pub fn max_axis(self) -> Axis {
if self.z > self.y {
if self.z > self.x {
Expand All @@ -203,6 +204,7 @@ impl Vector3 {
/// Returns the axis of the vector's smallest value. See `Axis` enum.
/// If all components are equal, this method returns `Axis::Z`.
#[inline]
#[allow(clippy::collapsible-if)]
pub fn min_axis(self) -> Axis {
if self.x < self.y {
if self.x < self.z {
Expand Down
11 changes: 10 additions & 1 deletion gdnative/tests/ui/derive_fail_methods_missing_new.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ error[E0599]: no function or associated item named `new` found for struct `Foo`
candidate #1: `UserData`
candidate #2: `gdnative::GodotObject`
candidate #3: `PtrWrapper`
candidate #4: `parking_lot_core::thread_parker::ThreadParkerT`
candidate #4: `glam::core::traits::matrix::Matrix2x2`
candidate #5: `glam::core::traits::matrix::Matrix3x3`
candidate #6: `glam::core::traits::matrix::Matrix4x4`
candidate #7: `glam::core::traits::vector::MaskVector2`
candidate #8: `glam::core::traits::vector::MaskVector3`
candidate #9: `glam::core::traits::vector::MaskVector4`
candidate #10: `glam::core::traits::vector::Vector2`
candidate #11: `glam::core::traits::vector::Vector3`
candidate #12: `glam::core::traits::vector::Vector4`
candidate #13: `parking_lot_core::thread_parker::ThreadParkerT`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 392c6c1

Please sign in to comment.