From 24b988b1ceca97e3af3401c732938dfba85a1ebd Mon Sep 17 00:00:00 2001 From: Adam Kewley Date: Thu, 8 Aug 2024 15:58:43 +0200 Subject: [PATCH] Clean up osc::Mesh method naming slightly --- src/oscar/Graphics/GraphicsImplementation.cpp | 8 ++++---- src/oscar/Graphics/Mesh.h | 9 +++++---- src/oscar/Graphics/MeshFunctions.cpp | 2 +- tests/testoscar/Graphics/TestMesh.cpp | 16 ++++++++-------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/oscar/Graphics/GraphicsImplementation.cpp b/src/oscar/Graphics/GraphicsImplementation.cpp index 89babb940b..af0b9b57f0 100644 --- a/src/oscar/Graphics/GraphicsImplementation.cpp +++ b/src/oscar/Graphics/GraphicsImplementation.cpp @@ -4645,7 +4645,7 @@ class osc::Mesh::Impl final { } } - void for_each_indexed_vert(const std::function& callback) const + void for_each_indexed_vertex(const std::function& callback) const { const auto positions = vertex_buffer_.iter(VertexAttribute::Position).begin(); for (auto index : indices()) { @@ -4700,7 +4700,7 @@ class osc::Mesh::Impl final { { std::vector rv; rv.reserve(num_indices()); - for_each_indexed_vert([&rv](Vec3 v) { rv.push_back(v); }); + for_each_indexed_vertex([&rv](Vec3 v) { rv.push_back(v); }); return rv; } @@ -5242,9 +5242,9 @@ void osc::Mesh::set_indices(MeshIndicesView indices, MeshUpdateFlags flags) impl_.upd()->set_indices(indices, flags); } -void osc::Mesh::for_each_indexed_vert(const std::function& callback) const +void osc::Mesh::for_each_indexed_vertex(const std::function& callback) const { - impl_->for_each_indexed_vert(callback); + impl_->for_each_indexed_vertex(callback); } void osc::Mesh::for_each_indexed_triangle(const std::function& callback) const diff --git a/src/oscar/Graphics/Mesh.h b/src/oscar/Graphics/Mesh.h index 7c29062e85..64b72ee1da 100644 --- a/src/oscar/Graphics/Mesh.h +++ b/src/oscar/Graphics/Mesh.h @@ -107,7 +107,7 @@ namespace osc { set_indices(MeshIndicesView{il}); } - void for_each_indexed_vert(const std::function&) const; + void for_each_indexed_vertex(const std::function&) const; void for_each_indexed_triangle(const std::function&) const; Triangle get_triangle_at(size_t first_index_offset) const; std::vector indexed_vertices() const; @@ -132,11 +132,12 @@ namespace osc void push_submesh_descriptor(const SubMeshDescriptor&); const SubMeshDescriptor& submesh_descriptor_at(size_t) const; template - void set_submesh_descriptors(const Range& range) + requires std::constructible_from> + void set_submesh_descriptors(const Range& submesh_descriptors) { clear_submesh_descriptors(); - for (const auto& desc : range) { - push_submesh_descriptor(desc); + for (const auto& submesh_descriptor : submesh_descriptors) { + push_submesh_descriptor(submesh_descriptor); } } void clear_submesh_descriptors(); diff --git a/src/oscar/Graphics/MeshFunctions.cpp b/src/oscar/Graphics/MeshFunctions.cpp index 0604f0de75..dbc9bec4db 100644 --- a/src/oscar/Graphics/MeshFunctions.cpp +++ b/src/oscar/Graphics/MeshFunctions.cpp @@ -26,7 +26,7 @@ Vec3 osc::average_centroid_of(const Mesh& mesh) { Vec3d accumulator{}; size_t i = 0; - mesh.for_each_indexed_vert([&accumulator, &i](Vec3 v) + mesh.for_each_indexed_vertex([&accumulator, &i](Vec3 v) { accumulator += v; ++i; diff --git a/tests/testoscar/Graphics/TestMesh.cpp b/tests/testoscar/Graphics/TestMesh.cpp index 1f97a30d26..ab7d6421e5 100644 --- a/tests/testoscar/Graphics/TestMesh.cpp +++ b/tests/testoscar/Graphics/TestMesh.cpp @@ -855,40 +855,40 @@ TEST(Mesh, set_indices_with_DontRecalculateBounds_does_not_recalculate_bounds) ASSERT_EQ(m.bounds(), AABB{}) << "bounds shouldn't update: we explicitly asked for the engine to skip it"; } -TEST(Mesh, for_each_indexed_vert_is_not_called_when_given_empty_Mesh) +TEST(Mesh, for_each_indexed_vertex_is_not_called_when_given_empty_Mesh) { size_t ncalls = 0; - Mesh{}.for_each_indexed_vert([&ncalls](auto&&) { ++ncalls; }); + Mesh{}.for_each_indexed_vertex([&ncalls](auto&&) { ++ncalls; }); ASSERT_EQ(ncalls, 0); } -TEST(Mesh, for_each_indexed_vert_is_not_called_when_only_vertices_with_no_indices_supplied) +TEST(Mesh, for_each_indexed_vertex_is_not_called_when_only_vertices_with_no_indices_supplied) { Mesh m; m.set_vertices({Vec3{}, Vec3{}, Vec3{}}); size_t ncalls = 0; - m.for_each_indexed_vert([&ncalls](auto&&) { ++ncalls; }); + m.for_each_indexed_vertex([&ncalls](auto&&) { ++ncalls; }); ASSERT_EQ(ncalls, 0); } -TEST(Mesh, for_each_indexed_vert_called_as_expected_when_supplied_correctly_indexed_mesh) +TEST(Mesh, for_each_indexed_vertex_called_as_expected_when_supplied_correctly_indexed_mesh) { Mesh m; m.set_vertices({Vec3{}, Vec3{}, Vec3{}}); m.set_indices(std::to_array({0, 1, 2})); size_t ncalls = 0; - m.for_each_indexed_vert([&ncalls](auto&&) { ++ncalls; }); + m.for_each_indexed_vertex([&ncalls](auto&&) { ++ncalls; }); ASSERT_EQ(ncalls, 3); } -TEST(Mesh, for_each_indexed_vert_called_even_when_mesh_is_non_triangular) +TEST(Mesh, for_each_indexed_vertex_called_even_when_mesh_is_non_triangular) { Mesh m; m.set_topology(MeshTopology::Lines); m.set_vertices({Vec3{}, Vec3{}, Vec3{}, Vec3{}}); m.set_indices(std::to_array({0, 1, 2, 3})); size_t ncalls = 0; - m.for_each_indexed_vert([&ncalls](auto&&) { ++ncalls; }); + m.for_each_indexed_vertex([&ncalls](auto&&) { ++ncalls; }); ASSERT_EQ(ncalls, 4); }