MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / TEST

Function TEST

source/MRTest/MRMeshMeshDistanceTest.cpp:11–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9{
10
11TEST( MRMesh, findSignedDistanceTest )
12{
13 auto a = makeCube( Vector3f::diagonal( 2.0f ), Vector3f::diagonal( -1.0f ) );
14 auto b = makeCube( Vector3f::diagonal( 1.0f ), Vector3f::diagonal( -0.5f ) );
15
16 auto dist = findSignedDistance( a, b );
17 EXPECT_TRUE( dist.signedDist < 0.0f );
18 EXPECT_TRUE( dist.status == MeshMeshCollisionStatus::BInside );
19
20 AffineXf3f xf;
21 xf.b.z = 0.6f;
22 dist = findSignedDistance( a, b, &xf );
23 EXPECT_TRUE( dist.signedDist < 0.0f );
24 EXPECT_TRUE( dist.status == MeshMeshCollisionStatus::Colliding );
25
26 xf.b.z = 1.4f;
27 dist = findSignedDistance( a, b, &xf );
28 EXPECT_TRUE( dist.signedDist < 0.0f );
29 EXPECT_TRUE( dist.status == MeshMeshCollisionStatus::Colliding );
30
31 xf.b.z = 1.5f;
32 dist = findSignedDistance( a, b, &xf );
33 EXPECT_TRUE( dist.signedDist == 0.0f );
34 EXPECT_TRUE( dist.status == MeshMeshCollisionStatus::Touching );
35
36
37 xf.b.z = 1.6f;
38 dist = findSignedDistance( a, b, &xf );
39 EXPECT_TRUE( dist.signedDist > 0.0f );
40 EXPECT_TRUE( dist.status == MeshMeshCollisionStatus::BothOutside );
41
42 // upDistLimitSq smaller than the real distSq: must short-circuit to BothOutside
43 // with signedDist == sqrt(upDistLimitSq), not run collision checks on the sentinel result
44 const float upDistLimitSq = 0.001f; // xf.b.z = 1.6f gives real distSq = 0.01
45 dist = findSignedDistance( a, b, &xf, upDistLimitSq );
46 EXPECT_TRUE( dist.status == MeshMeshCollisionStatus::NotColliding );
47 EXPECT_FALSE( dist.a );
48 EXPECT_FALSE( dist.b );
49 EXPECT_NEAR( dist.signedDist, std::sqrt( upDistLimitSq ), 1e-6f );
50}
51
52TEST( MRMesh, findSignedDistanceValidPointsOnCollision )
53{

Callers

nothing calls this directly

Calls 3

makeCubeFunction · 0.85
diagonalFunction · 0.85
findSignedDistanceFunction · 0.50

Tested by

no test coverage detected