From ff609b890946c476d465bdd50acb4f88454d6b30 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Wed, 26 Aug 2020 10:20:58 +0200 Subject: [PATCH] add tests for smart range avg and weighted avg --- src/Unittests/unittests_smart_ranges.cc | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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."; +} }