Skip to content

Commit edbe60f

Browse files
authored
Test on findClosestWeightedMeshPoint (#4529)
1 parent f413e97 commit edbe60f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

source/MRMesh/MRClosestWeightedPoint.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ std::optional<ClosestTriPoint> findClosestWeightedTriPoint( const Vector3d& locd
8383
ws[i] = pointWeight( vs[i] );
8484
}
8585

86+
// considering unsigned distances, each triangle has two planes where euclidean distance equals interpolated point weight
8687
const auto maybePlane = ( dot( locd - ps[0], dirDblArea( ps ) ) >= 0 ) ?
8788
tangentPlaneToSpheres( ps[0], ps[1], ps[2], ws[0], ws[1], ws[2] ) :
8889
tangentPlaneToSpheres( ps[1], ps[0], ps[2], ws[1], ws[0], ws[2] );

source/MRTest/MRPointCloudVariadicOffsetTests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <MRMesh/MRClosestWeightedPoint.h>
22
#include <MRMesh/MRPointCloud.h>
3+
#include <MRMesh/MRMesh.h>
34
#include <MRMesh/MRGTest.h>
45

56
namespace MR
@@ -45,4 +46,35 @@ TEST( MRMesh, findClosestWeightedPoint )
4546
}
4647
}
4748

49+
TEST( MRMesh, findClosestWeightedMeshPoint )
50+
{
51+
Triangulation t{
52+
{ 0_v, 1_v, 2_v }
53+
};
54+
VertCoords vs{
55+
{-1, -1, 0 }, //0_v
56+
{-1, 1, 0 }, //1_v
57+
{ 1, 0, 0 }, //2_v
58+
};
59+
auto mesh = Mesh::fromTriangles( std::move( vs ), t );
60+
61+
DistanceFromWeightedPointsComputeParams params;
62+
auto distance = [&]( Vector3f loc )
63+
{
64+
auto pd = findClosestWeightedMeshPoint( loc, mesh, params );
65+
assert( !pd.mtp.onEdge( mesh.topology ) );
66+
return pd.dist;
67+
};
68+
69+
params.pointWeight = [&]( VertId ) { return 1; };
70+
params.maxWeight = 1;
71+
for ( float z = -2; z <= 2; z += 0.1f )
72+
EXPECT_NEAR( distance( Vector3f( 0, 0, z ) ), -1 + std::abs( z ), 1e-7f );
73+
74+
params.pointWeight = [&]( VertId ) { return -1; };
75+
params.maxWeight = -1;
76+
for ( float z = -2; z <= 2; z += 0.1f )
77+
EXPECT_NEAR( distance( Vector3f( 0, 0, z ) ), 1 + std::abs( z ), 1e-7f );
78+
}
79+
4880
} //namespace MR

0 commit comments

Comments
 (0)