Merge branch 'AvgUnittest' into 'master'

add tests for smart range avg and weighted avg

See merge request OpenMesh/OpenMesh!279
This commit is contained in:
Jan Möbius
2020-08-26 11:34:40 +02:00

View File

@@ -386,6 +386,39 @@ TEST_F(OpenMeshSmartRanges, Filtered)
} }
/* Test avg
*/
TEST_F(OpenMeshSmartRanges, Avg)
{
Mesh::Point cog(0,0,0);
for (auto vh : mesh_.vertices())
cog += mesh_.point(vh);
cog /= mesh_.n_vertices();
auto points = OpenMesh::getPointsProperty(mesh_);
auto cog2 = mesh_.vertices().avg(points);
EXPECT_LT(norm(cog - cog2), 0.00001) << "Computed center of gravities are significantly different.";
}
/* Test weighted avg
*/
TEST_F(OpenMeshSmartRanges, WeightedAvg)
{
Mesh::Point cog(0,0,0);
for (auto fh : mesh_.faces())
cog += mesh_.calc_face_centroid(fh);
cog /= mesh_.n_faces();
OpenMesh::FProp<float> area(mesh_);
for (auto fh : mesh_.faces())
area[fh] = mesh_.calc_face_area(fh);
auto cog2 = mesh_.faces().avg([&](OpenMesh::FaceHandle fh) { return mesh_.calc_face_centroid(fh); }, area);
EXPECT_LT(norm(cog - cog2), 0.00001) << "Computed area weighted center of gravities are significantly different.";
}
} }