diff --git a/src/Unittests/unittests_smart_ranges.cc b/src/Unittests/unittests_smart_ranges.cc index 353e528c..93eaa15d 100644 --- a/src/Unittests/unittests_smart_ranges.cc +++ b/src/Unittests/unittests_smart_ranges.cc @@ -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 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."; +} }