Skip to content

Commit

Permalink
Clean up osc::Mesh method naming slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Aug 8, 2024
1 parent a4028b5 commit 24b988b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/oscar/Graphics/GraphicsImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4645,7 +4645,7 @@ class osc::Mesh::Impl final {
}
}

void for_each_indexed_vert(const std::function<void(Vec3)>& callback) const
void for_each_indexed_vertex(const std::function<void(Vec3)>& callback) const
{
const auto positions = vertex_buffer_.iter<Vec3>(VertexAttribute::Position).begin();
for (auto index : indices()) {
Expand Down Expand Up @@ -4700,7 +4700,7 @@ class osc::Mesh::Impl final {
{
std::vector<Vec3> 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;
}

Expand Down Expand Up @@ -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<void(Vec3)>& callback) const
void osc::Mesh::for_each_indexed_vertex(const std::function<void(Vec3)>& callback) const
{
impl_->for_each_indexed_vert(callback);
impl_->for_each_indexed_vertex(callback);
}

void osc::Mesh::for_each_indexed_triangle(const std::function<void(Triangle)>& callback) const
Expand Down
9 changes: 5 additions & 4 deletions src/oscar/Graphics/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace osc
{
set_indices(MeshIndicesView{il});
}
void for_each_indexed_vert(const std::function<void(Vec3)>&) const;
void for_each_indexed_vertex(const std::function<void(Vec3)>&) const;
void for_each_indexed_triangle(const std::function<void(Triangle)>&) const;
Triangle get_triangle_at(size_t first_index_offset) const;
std::vector<Vec3> indexed_vertices() const;
Expand All @@ -132,11 +132,12 @@ namespace osc
void push_submesh_descriptor(const SubMeshDescriptor&);
const SubMeshDescriptor& submesh_descriptor_at(size_t) const;
template<std::ranges::input_range Range>
void set_submesh_descriptors(const Range& range)
requires std::constructible_from<SubMeshDescriptor, std::ranges::range_value_t<Range>>
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();
Expand Down
2 changes: 1 addition & 1 deletion src/oscar/Graphics/MeshFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions tests/testoscar/Graphics/TestMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>({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<uint16_t>({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);
}

Expand Down

0 comments on commit 24b988b

Please sign in to comment.