Commit 740c6916 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'AvgUnittest' into 'master'

add tests for smart range avg and weighted avg

See merge request !279
parents 9a9cf96a ff609b89
Pipeline #14988 failed with stages
in 97 minutes and 36 seconds
......@@ -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.";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment