Skip to content

Commit

Permalink
Const tweak
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Derbasov <[email protected]>
  • Loading branch information
ntfshard committed Jul 20, 2024
1 parent b0605b8 commit 0ba046a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion graphics/include/gz/common/SubMesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include <gz/math/Vector3.hh>
#include <gz/math/Vector2.hh>
Expand Down
8 changes: 4 additions & 4 deletions graphics/src/SubMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <algorithm>
#include <limits>
#include <map>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -578,7 +577,8 @@ namespace {
// Simple way to find neighbors by grouping all vertices
// by X coordinate with (ordered) map. KD-tree maybe better
// but not sure about construction overhead
struct Neighbors {
struct Neighbors
{
Neighbors(const std::vector<unsigned int> &_indices,
const std::vector<gz::math::Vector3d> &_vertices)
: vertices(_vertices)
Expand All @@ -591,7 +591,7 @@ struct Neighbors {
}

template<typename Visitor>
void Visit(const gz::math::Vector3d &_point, Visitor _v)
void Visit(const gz::math::Vector3d &_point, Visitor _v) const
{
auto it = this->neighbors.find(_point.X());
// find smaller acceptable value
Expand Down Expand Up @@ -645,7 +645,7 @@ void SubMesh::RecalculateNormals()
gz::math::Vector3d n = gz::math::Vector3d::Normal(v1, v2, v3);

for (const auto &point : {v1, v2, v3})
neighbors.Visit(point, [&](unsigned int index)
neighbors.Visit(point, [&](const unsigned int index)
{
this->dataPtr->normals[index] += n;
});
Expand Down
6 changes: 3 additions & 3 deletions graphics/src/SubMesh_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ TEST_F(SubMeshTest, NormalsRecalculation)
auto submesh = std::make_shared<common::SubMesh>();
submesh->SetPrimitiveType(common::SubMesh::TRIANGLES);

constexpr unsigned int elements = 16384;
for (unsigned int i = 0; i < elements; ++i) {
// sub to X less than _epsilon from even elements
constexpr unsigned int triangles = 16384;
for (unsigned int i = 0; i < triangles; ++i) {
// sub to X less than _epsilon from even triangles
// expect that the 2nd vertex should be matched with
// the 1st of next triangle
const auto jitter = i % 2 ? 1e-7 : 0.0;
Expand Down

0 comments on commit 0ba046a

Please sign in to comment.