Skip to content

Commit 3c09e6a

Browse files
committed
Uncommented tests, fixed Transform::interpolate_with
`Transform::interpolate_with` was erroneously implemented as its Godot 4 version. The error went through because the TODO comment wasn't checked. This reverts it to the Godot 3 behavior of performing `slerp`, which is what users of GDNative is likely expecting.
1 parent db8ad1b commit 3c09e6a

File tree

4 files changed

+65
-66
lines changed

4 files changed

+65
-66
lines changed

gdnative-core/src/core_types/dictionary.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,15 @@ godot_test!(test_dictionary {
585585
assert_eq!(expected_keys, iter_keys);
586586
});
587587

588-
// TODO: clear dictionaries without affecting clones
589-
//godot_test!(test_dictionary_clone_clear {
590-
// let foo = Variant::from_str("foo");
591-
// let bar = Variant::from_str("bar");
592-
// let mut dict = Dictionary::new();
593-
//
594-
// dict.set(&foo, &bar);
595-
// let dict_clone = dict.clone();
596-
// dict.clear();
597-
//
598-
// assert!(dict.is_empty());
599-
// assert!(!dict_clone.is_empty());
600-
//});
588+
godot_test!(test_dictionary_clone_clear {
589+
let foo = Variant::new("foo");
590+
let bar = Variant::new("bar");
591+
let dict = Dictionary::new();
592+
593+
dict.insert(&foo, &bar);
594+
let dict_clone = dict.duplicate();
595+
dict.clear();
596+
597+
assert!(dict.is_empty());
598+
assert!(!dict_clone.is_empty());
599+
});

gdnative-core/src/core_types/geom/transform.rs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,18 @@ impl Transform {
247247
self.basis.is_equal_approx(&other.basis) && self.origin.is_equal_approx(other.origin)
248248
}
249249

250-
/// Interpolates the transform to other Transform by
251-
/// weight amount (on the range of 0.0 to 1.0).
250+
/// Interpolates the transform to other Transform by weight amount (on the range of 0.0 to 1.0).
252251
/// Assuming the two transforms are located on a sphere surface.
253252
#[inline]
253+
#[deprecated = "This is the Godot 4 rename of `interpolate_with`. It will be removed in favor of the original Godot 3 naming in a future version."]
254254
pub fn sphere_interpolate_with(&self, other: &Transform, weight: f32) -> Self {
255+
self.interpolate_with(other, weight)
256+
}
257+
258+
/// Interpolates the transform to other Transform by weight amount (on the range of 0.0 to 1.0).
259+
/// Assuming the two transforms are located on a sphere surface.
260+
#[inline]
261+
pub fn interpolate_with(&self, other: &Transform, weight: f32) -> Self {
255262
let src_scale = self.basis.scale();
256263
let src_rot = self.basis.to_quat();
257264
let src_loc = self.origin;
@@ -268,16 +275,6 @@ impl Transform {
268275
}
269276
}
270277

271-
/// Interpolates the transform to other Transform by
272-
/// weight amount (on the range of 0.0 to 1.0).
273-
#[inline]
274-
pub fn interpolate_with(&self, other: &Transform, weight: f32) -> Self {
275-
Transform {
276-
basis: self.basis.lerp(&other.basis, weight),
277-
origin: self.origin.linear_interpolate(other.origin, weight),
278-
}
279-
}
280-
281278
#[doc(hidden)]
282279
#[inline]
283280
pub fn sys(&self) -> *const sys::godot_transform {
@@ -314,6 +311,30 @@ impl MulAssign<Transform> for Transform {
314311
mod tests {
315312
use super::*;
316313

314+
/// Equivalent GDScript, in case Godot values need to be updated:
315+
///
316+
/// ```gdscript
317+
/// func test_inputs():
318+
/// var basis = Basis(Vector3(37.51756, 20.39467, 49.96816))
319+
/// var t = Transform(
320+
/// basis.x,
321+
/// basis.y,
322+
/// basis.z,
323+
/// Vector3(0.0, 0.0, 0.0))
324+
/// t = t.translated(Vector3(0.5, -1.0, 0.25))
325+
/// t = t.scaled(Vector3(0.25, 0.5, 2.0))
326+
///
327+
/// basis = Basis(Vector3(12.23, 50.46, 93.94))
328+
/// var t2 = Transform(
329+
/// basis.x,
330+
/// basis.y,
331+
/// basis.z,
332+
/// Vector3(0.0, 0.0, 0.0))
333+
/// t2 = t2.translated(Vector3(1.5, -2.0, 1.25))
334+
/// t2 = t2.scaled(Vector3(0.5, 0.58, 1.0))
335+
///
336+
/// return [t, t2]
337+
/// ```
317338
fn test_inputs() -> (Transform, Transform) {
318339
let basis = Basis::from_euler(Vector3::new(37.51756, 20.39467, 49.96816));
319340
let mut t = Transform::from_basis_origin(
@@ -376,22 +397,19 @@ mod tests {
376397
assert!(expected.is_equal_approx(&t))
377398
}
378399

379-
/*
380400
#[test]
381401
fn inverse_is_sane() {
382402
let t = test_inputs().0.inverse();
383403
let expected = Transform::from_basis_origin(
384-
// Fix values
385-
Vector3::new(0.309725, -0.66022015, 3.9329607),
386-
Vector3::new(-0.57629496, 1.8808193, 0.3611141),
387-
Vector3::new(-0.47722515, -0.14864945, 0.012628445),
388-
Vector3::new(-0.7398631, 0.0425314, 0.03682696),
404+
Vector3::new(0.019358, -0.041264, 0.24581),
405+
Vector3::new(-0.144074, 0.470205, 0.090279),
406+
Vector3::new(-1.908901, -0.594598, 0.050514),
407+
Vector3::new(-0.739863, 0.042531, 0.036827),
389408
);
390409

391410
println!("TF: {t:?}");
392411
assert!(expected.is_equal_approx(&t))
393412
}
394-
*/
395413

396414
#[test]
397415
fn orthonormalization_is_sane() {
@@ -409,31 +427,12 @@ mod tests {
409427
}
410428

411429
#[test]
412-
fn linear_interpolation_is_sane() {
430+
fn spherical_interpolation_is_sane() {
413431
// Godot reports:
414432
// t = 0.019358, -0.041264, 0.24581, -0.144074, 0.470205, 0.090279, -1.908901, -0.594598, 0.050514 - 0.112395, -0.519672, -0.347224
415433
// t2 = 0.477182, 0.118214, 0.09123, -0.165859, 0.521769, 0.191437, -0.086105, -0.367178, 0.926157 - 0.593383, -1.05303, 1.762894
416-
// TODO: Get new godot result. https://github.com/godotengine/godot/commit/61759da5b35e44003ab3ffe3d4024dd611d17eff changed how Transform3D.linear_interpolate works
417-
// For now assuming this is sane - examined the new implementation manually.
418434
let (t, t2) = test_inputs();
419435
let result = t.interpolate_with(&t2, 0.5);
420-
let expected = Transform::from_basis_origin(
421-
Vector3::new(0.24826992, -0.15496635, -0.997503),
422-
Vector3::new(0.038474888, 0.49598676, -0.4808879),
423-
Vector3::new(0.16852, 0.14085774, 0.48833522),
424-
Vector3::new(0.352889, -0.786351, 0.707835),
425-
);
426-
assert!(expected.is_equal_approx(&result))
427-
}
428-
429-
#[test]
430-
fn sphere_linear_interpolation_is_sane() {
431-
// Godot reports:
432-
// t = 0.019358, -0.041264, 0.24581, -0.144074, 0.470205, 0.090279, -1.908901, -0.594598, 0.050514 - 0.112395, -0.519672, -0.347224
433-
// t2 = 0.477182, 0.118214, 0.09123, -0.165859, 0.521769, 0.191437, -0.086105, -0.367178, 0.926157 - 0.593383, -1.05303, 1.762894
434-
// result = 0.727909, -0.029075, 0.486138, -0.338385, 0.6514, 0.156468, -0.910002, -0.265481, 0.330678 - 0.352889, -0.786351, 0.707835
435-
let (t, t2) = test_inputs();
436-
let result = t.sphere_interpolate_with(&t2, 0.5);
437436
let expected = Transform::from_basis_origin(
438437
Vector3::new(0.7279087, -0.19632529, -0.45626357),
439438
Vector3::new(-0.05011323, 0.65140045, -0.22942543),

gdnative-core/src/core_types/variant_array.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,16 @@ godot_test!(
631631
}
632632
);
633633

634-
// TODO: clear arrays without affecting clones
635-
//godot_test!(test_array_clone_clear {
636-
// let foo = Variant::new("foo");
637-
// let mut array = VariantArray::new();
638-
//
639-
// array.push(&foo);
640-
// let array_clone = array.clone();
641-
// array.clear();
642-
//
643-
// assert!(array.is_empty());
644-
// assert!(!array_clone.is_empty());
645-
//});
634+
godot_test!(
635+
test_array_clone_clear {
636+
let foo = Variant::new("foo");
637+
let array = VariantArray::new();
638+
639+
array.push(&foo);
640+
let array_clone = array.duplicate();
641+
array.clear();
642+
643+
assert!(array.is_empty());
644+
assert!(!array_clone.is_empty());
645+
}
646+
);

test/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ pub extern "C" fn run_tests(
3030
status &= gdnative::core_types::test_string_name_ord();
3131

3232
status &= gdnative::core_types::test_dictionary();
33-
// status &= gdnative::test_dictionary_clone_clear();
33+
status &= gdnative::core_types::test_dictionary_clone_clear();
3434
status &= gdnative::core_types::test_color();
3535
status &= gdnative::core_types::test_array();
3636
status &= gdnative::core_types::test_array_debug();
37-
// status &= gdnative::test_array_clone_clear();
37+
status &= gdnative::core_types::test_array_clone_clear();
3838

3939
status &= gdnative::core_types::test_variant_nil();
4040
status &= gdnative::core_types::test_variant_i64();

0 commit comments

Comments
 (0)