use approx_det::assert_relative_eq;
use wasm_bindgen_test::*;
use crate::collision_tasks::tests::common::{
convex1contact_manifold_wide_to_convex1contact_manifold, get_input_wide,
Convex1ContactManifold, Mvec3, TestInput,
};
use crate::collision_tasks::ShapeWideTester;
use crate::shapes::{CylinderWide, SphereWide};
use crate::traits::PairWideTest;
use crate::{Cylinder, Sphere};
wasm_bindgen_test_configure!(run_in_browser);
type InputType = TestInput<Sphere, Cylinder>;
const ADJUST_DEPTH_FACTOR: f32 = 1.0;
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_000_tester_same_center() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/000_same_center.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
normal: Mvec3 {
x: 0.0,
y: -1.0,
z: 0.0,
},
depth: 1.0,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_001_cylinder_inside_sphere() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/001_cylinder_inside_sphere.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.029_289_3_f32,
y: 0.0,
z: 0.029_289_3_f32,
},
normal: Mvec3 {
x: -std::f32::consts::FRAC_1_SQRT_2,
y: 0.0,
z: -std::f32::consts::FRAC_1_SQRT_2,
},
depth: 0.458_578_6_f32,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_002_sphere_inside_cylinder() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/002_sphere_inside_cylinder.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
normal: Mvec3 {
x: -std::f32::consts::FRAC_1_SQRT_2,
y: 0.0,
z: -std::f32::consts::FRAC_1_SQRT_2,
},
depth: 1.1858578,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_003_nocollide() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/003_nocollide.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 9.646_446_f32,
y: 9.5,
z: 9.646_446_f32,
},
normal: Mvec3 {
x: -0.580_271_8_f32,
y: -0.571_462_4_f32,
z: -0.580_271_8_f32,
},
depth: -16.124_014_f32,
feature_id: 0,
contact_exists: false,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_004_sphere_tangent_at_cylinder_side() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input =
include_bytes!("resource/sphere_cylinder/004_sphere_tangent_at_cylinder_side.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.500_000_f32,
y: 0.0,
z: 0.0,
},
normal: Mvec3 {
x: -1.0,
y: 0.0,
z: 0.0,
},
depth: -5.960_464_5e-8,
feature_id: 0,
contact_exists: false,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_005_sphere_tangent_at_cylinder_cap() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input =
include_bytes!("resource/sphere_cylinder/005_sphere_tangent_at_cylinder_cap.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.5,
z: 0.0,
},
normal: Mvec3 {
x: 0.0,
y: -1.0,
z: 0.0,
},
depth: 0.0,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_006_sphere_tangent_at_cylinder_cap_circle() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input =
include_bytes!("resource/sphere_cylinder/006_sphere_tangent_at_cylinder_cap_circle.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.5,
z: 0.0,
},
normal: Mvec3 {
x: 0.0,
y: -1.0,
z: 0.0,
},
depth: 0.0,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_007_penetrate_at_cylinder_cap() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/007_penetrate_at_cylinder_cap.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.3,
z: 0.0,
},
normal: Mvec3 {
x: 0.0,
y: -1.0,
z: 0.0,
},
depth: 0.199_999_9_f32,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_008_penetrate_at_cylinder_side() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/008_penetrate_at_cylinder_side.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.204_281_4_f32,
y: 0.0,
z: -0.022_697_9_f32,
},
normal: Mvec3 {
x: -0.993_883_7_f32,
y: 0.0,
z: 0.110_431_5_f32,
},
depth: 0.294_461_5_f32,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_009_penetrate_at_cylinder_cap_circle() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input =
include_bytes!("resource/sphere_cylinder/009_penetrate_at_cylinder_cap_circle.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
normal: Mvec3 {
x: 0.0,
y: -1.0,
z: 0.0,
},
depth: 0.6,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}
#[test]
#[wasm_bindgen_test]
fn test_sphere_cylinder_010_random_collide() {
let _ = env_logger::builder().is_test(true).try_init();
let file_input = include_bytes!("resource/sphere_cylinder/010_random_collide.json");
let input0: InputType = serde_json::from_slice(file_input).expect("file should be proper JSON");
let mut output0 = Convex1ContactManifold {
offset_a: Mvec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
normal: Mvec3 {
x: -0.574_976_2_f32,
y: 0.793_070_6_f32,
z: 0.201_100_1_f32,
},
depth: 0.743_085_3_f32,
feature_id: 0,
contact_exists: true,
};
output0.adjust_offset_a_to_shape_surface(ADJUST_DEPTH_FACTOR);
let array = [input0];
let outputs = [output0];
let pair_count = array.len();
TestWide!(
SphereWide,
CylinderWide,
array,
pair_count,
outputs,
convex1contact_manifold_wide_to_convex1contact_manifold
);
}