use approx_det::assert_relative_eq;
use wasm_bindgen_test::*;
use super::common::get_input_wide;
use crate::collision_tasks::tests::common::{
convex4manifold_wide2convex4contact_manifold, Convex4ContactManifold, ConvexHullInput, Mvec3,
TestInput,
};
use crate::shapes::{Triangle, TriangleWide};
use crate::{
ConvexHull, ConvexHullId, ConvexHullWide, PairWideTest, ShapeContainer, ShapeWideTester,
};
wasm_bindgen_test_configure!(run_in_browser);
type InputType = TestInput<Triangle, ConvexHullId>;
type InputTypeData = TestInput<Triangle, ConvexHullInput>;
#[test]
#[wasm_bindgen_test]
#[cfg(feature = "serde")]
fn test_cuboid_convex_hull_collide() {
let _ = env_logger::builder().is_test(true).try_init();
let reset = <ShapeWideTester as PairWideTest<TriangleWide, ConvexHullWide>>::should_reset_manifold_before_test();
assert!(reset);
let file_input =
include_bytes!("resource/triangle_convex_hull/cuboid_convex_hull_collide.json");
let input0: InputTypeData =
serde_json::from_slice(file_input).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input0.b.vertices[..]);
let mut container = ShapeContainer::default();
let id = container.add(convex_hull);
let input0 = InputType {
a: input0.a,
b: id,
speculative_margin: input0.speculative_margin,
offset_b: input0.offset_b,
orientation_a: input0.orientation_a,
orientation_b: input0.orientation_b,
};
let output0 = Convex4ContactManifold {
Normal: Mvec3 {
x: -0.19611612,
y: -0.9805807,
z: 0.0,
},
OffsetA0: Mvec3 {
x: 0.5048,
y: 0.0990,
z: 0.7572,
},
OffsetA1: Mvec3 {
x: 1.0,
y: 0.0,
z: 0.24599,
},
OffsetA2: Mvec3 {
x: 1.0,
y: 0.0,
z: 1.246,
},
OffsetA3: Mvec3 {
x: 0.50480,
y: 0.0990,
z: 0.24599,
},
Depth0: 0.30496058,
Depth1: 0.20396078,
Depth2: 0.20396078,
Depth3: 0.30496055,
Contact0Exists: true,
Contact1Exists: true,
Contact2Exists: true,
Contact3Exists: true,
FeatureId0: 4,
FeatureId1: 3,
FeatureId2: 2,
FeatureId3: 6,
};
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
TriangleWide,
ConvexHullWide,
array,
pair_count,
outputs,
convex4manifold_wide2convex4contact_manifold,
Some(&container)
);
}
#[test]
#[wasm_bindgen_test]
#[cfg(feature = "serde")]
fn test_cuboid_convex_hull_on_collide_backface_cull() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!(
"resource/triangle_convex_hull/cuboid_convex_hull_on_collide_backface_cull.json"
);
let input0: InputTypeData =
serde_json::from_slice(file_input).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input0.b.vertices[..]);
let mut container = ShapeContainer::default();
let id = container.add(convex_hull);
let input0 = InputType {
a: input0.a,
b: id,
speculative_margin: input0.speculative_margin,
offset_b: input0.offset_b,
orientation_a: input0.orientation_a,
orientation_b: input0.orientation_b,
};
let output0 = Convex4ContactManifold::default();
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
TriangleWide,
ConvexHullWide,
array,
pair_count,
outputs,
convex4manifold_wide2convex4contact_manifold,
Some(&container)
);
}
#[test]
#[wasm_bindgen_test]
#[cfg(feature = "serde")]
fn test_cuboid_convex_hull_collide_2() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input =
include_bytes!("resource/triangle_convex_hull/cuboid_convex_hull_collide_2.json");
let input0: InputTypeData =
serde_json::from_slice(file_input).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input0.b.vertices[..]);
let mut container = ShapeContainer::default();
let id = container.add(convex_hull);
let input0 = InputType {
a: input0.a,
b: id,
speculative_margin: input0.speculative_margin,
offset_b: input0.offset_b,
orientation_a: input0.orientation_a,
orientation_b: input0.orientation_b,
};
let output0 = Convex4ContactManifold {
Normal: Mvec3 {
x: -0.37068,
y: -0.92670,
z: 0.06178,
},
OffsetA0: Mvec3 {
x: 0.8888,
y: 0.1984,
z: 0.8091,
},
OffsetA1: Mvec3 {
x: 0.32637,
y: 0.37482,
z: 0.08072,
},
OffsetA2: Mvec3 {
x: 0.19171,
y: 0.44248,
z: 0.28757,
},
OffsetA3: Mvec3 {
x: 0.71620,
y: 0.28513,
z: 1.07431,
},
Depth0: 0.6085,
Depth1: 0.2593,
Depth2: 0.07894,
Depth3: 0.37725,
Contact0Exists: true,
Contact1Exists: true,
Contact2Exists: true,
Contact3Exists: true,
FeatureId0: 6,
FeatureId1: 6,
FeatureId2: 4,
FeatureId3: 5,
};
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
TriangleWide,
ConvexHullWide,
array,
pair_count,
outputs,
convex4manifold_wide2convex4contact_manifold,
Some(&container)
);
}
#[test]
#[wasm_bindgen_test]
#[cfg(feature = "serde")]
fn test_cuboid_convex_hull_collide_tootbird() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input =
include_bytes!("resource/triangle_convex_hull/cuboid_convex_hull_collide_tootbird.json");
let input0: InputTypeData =
serde_json::from_slice(file_input).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input0.b.vertices[..]);
let mut container = ShapeContainer::default();
let id = container.add(convex_hull);
let input0 = InputType {
a: input0.a,
b: id,
speculative_margin: input0.speculative_margin,
offset_b: input0.offset_b,
orientation_a: input0.orientation_a,
orientation_b: input0.orientation_b,
};
let output0 = Convex4ContactManifold {
Normal: Mvec3 {
x: -0.78504,
y: -0.6180,
z: 0.04120,
},
OffsetA0: Mvec3 {
x: 0.62132,
y: 0.25737,
z: 0.08855,
},
OffsetA1: Mvec3 {
x: 0.9999,
y: 0.17662,
z: 1.14944,
},
OffsetA2: Mvec3 {
x: 0.9999,
y: 0.13060,
z: 0.45912,
},
OffsetA3: Mvec3 {
x: 0.8529,
y: 0.24412,
z: 1.27937,
},
Depth0: 0.19881,
Depth1: 0.26802,
Depth2: 0.40247,
Depth3: 0.13558,
Contact0Exists: true,
Contact1Exists: true,
Contact2Exists: true,
Contact3Exists: true,
FeatureId0: 6,
FeatureId1: 2,
FeatureId2: 3,
FeatureId3: 5,
};
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
TriangleWide,
ConvexHullWide,
array,
pair_count,
outputs,
convex4manifold_wide2convex4contact_manifold,
Some(&container)
);
}
#[test]
#[wasm_bindgen_test]
#[cfg(feature = "serde")]
fn test_invalid_lanes() {
let _ = env_logger::builder().is_test(true).try_init();
let reset = <ShapeWideTester as PairWideTest<TriangleWide, ConvexHullWide>>::should_reset_manifold_before_test();
assert!(reset);
let file_input = include_bytes!("resource/triangle_convex_hull/inactive_lanes.json");
let input0: InputTypeData =
serde_json::from_slice(file_input).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input0.b.vertices[..]);
let mut container = ShapeContainer::default();
let id = container.add(convex_hull);
let input0 = InputType {
a: input0.a,
b: id,
speculative_margin: input0.speculative_margin,
offset_b: input0.offset_b,
orientation_a: input0.orientation_a,
orientation_b: input0.orientation_b,
};
let output0 = Convex4ContactManifold::default();
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
TriangleWide,
ConvexHullWide,
array,
pair_count,
outputs,
convex4manifold_wide2convex4contact_manifold,
Some(&container)
);
}
#[test]
#[wasm_bindgen_test]
#[cfg(feature = "serde")]
fn test_invalid_lanes_2() {
let _ = env_logger::builder().is_test(true).try_init();
let reset = <ShapeWideTester as PairWideTest<TriangleWide, ConvexHullWide>>::should_reset_manifold_before_test();
assert!(reset);
let file_input_0 = include_bytes!("resource/triangle_convex_hull/inactive_lanes.json");
let input0: InputTypeData =
serde_json::from_slice(file_input_0).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input0.b.vertices[..]);
let mut container = ShapeContainer::default();
let id_0 = container.add(convex_hull);
let input0 = InputType {
a: input0.a,
b: id_0,
speculative_margin: input0.speculative_margin,
offset_b: input0.offset_b,
orientation_a: input0.orientation_a,
orientation_b: input0.orientation_b,
};
let output0 = Convex4ContactManifold {
Normal: Mvec3 {
x: 0.0,
y: -1.0,
z: 0.0,
},
..Default::default()
};
let file_input_1 =
include_bytes!("resource/triangle_convex_hull/cuboid_convex_hull_collide.json");
let input1: InputTypeData =
serde_json::from_slice(file_input_1).expect("file should be proper JSON");
let convex_hull = ConvexHull::new_unchecked(&input1.b.vertices[..]);
let id_1 = container.add(convex_hull);
let input1 = InputType {
a: input1.a,
b: id_1,
speculative_margin: input1.speculative_margin,
offset_b: input1.offset_b,
orientation_a: input1.orientation_a,
orientation_b: input1.orientation_b,
};
let output1 = Convex4ContactManifold {
Normal: Mvec3 {
x: -0.19611612,
y: -0.9805807,
z: 0.0,
},
OffsetA0: Mvec3 {
x: 0.5048,
y: 0.0990,
z: 0.7572,
},
OffsetA1: Mvec3 {
x: 1.0,
y: 0.0,
z: 0.24599,
},
OffsetA2: Mvec3 {
x: 1.0,
y: 0.0,
z: 1.246,
},
OffsetA3: Mvec3 {
x: 0.50480,
y: 0.0990,
z: 0.24599,
},
Depth0: 0.30496058,
Depth1: 0.20396078,
Depth2: 0.20396078,
Depth3: 0.30496055,
Contact0Exists: true,
Contact1Exists: true,
Contact2Exists: true,
Contact3Exists: true,
FeatureId0: 4,
FeatureId1: 3,
FeatureId2: 2,
FeatureId3: 6,
};
let array = [input0, input1];
let outputs = [output0, output1];
let pair_count = array.len();
TestWide!(
TriangleWide,
ConvexHullWide,
array,
pair_count,
outputs,
convex4manifold_wide2convex4contact_manifold,
Some(&container)
);
}
#[cfg(not(feature = "qhull"))]
mod shift {
use glam::{UnitQuat, Vec3};
use crate::collision_tasks::tests::common::{
build_displaced_convexhull_test, CollisionTestShape,
};
use crate::Triangle;
#[test]
fn test_triangle_convex_shift() {
let shape_a = Triangle::new([0., 0., 0.], [1., 1., 0.], [-2., 2., 0.]);
let convexhull_cuboid_length = Vec3::new(3., 4., 5.);
let convexhull_displacement_vec = Vec3::new(1e2, 1e3, 1e4);
let desired_offset_b = Vec3::new(0., 0., 2.1);
let rotation_a = UnitQuat::from_euler_default(-1., -2., -3.);
let rotation_b = UnitQuat::from_euler_default(1., 2., 3.);
build_displaced_convexhull_test(
&CollisionTestShape::Triangle(shape_a),
convexhull_cuboid_length,
convexhull_displacement_vec,
desired_offset_b,
rotation_a,
rotation_b,
);
}
}