diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..1ccce196a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,54 @@ +Checks: > + -*, + + # Standard C++ Guidelines (Modernization, Idioms) + modernize-*, + performance-*, + readability-*, + + # Bug Detection and Safety + bugprone-*, + + # Specific high-value checks (even if not in a group above) + google-runtime-int, + cppcoreguidelines-pro-type-member-init, + + # Exclusions/Suppressions (Checks often considered too aggressive or subjective) + -bugprone-throwing-static-initialization, + -cppcoreguidelines-owning-memory, + -modernize-use-trailing-return-type, + -readability-avoid-const-params-in-decls, + -readability-avoid-nested-conditional-operator, + -readability-container-contains, + -readability-else-after-return, + -readability-function-cognitive-complexity, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-isolate-declaration, + -readability-magic-numbers, + -readability-math-missing-parentheses, + -readability-redundant-access-specifiers + +WarningsAsErrors: '*' +HeaderFilterRegex: '.*(ipc/).*' +UseColor: true +FormatStyle: file +ExtraArgs: + - '-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk' +CheckOptions: + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.ConstantParameterCase: lower_case + readability-identifier-naming.ConstantParameterIgnoredRegexp: '^(_.*)$' + readability-identifier-naming.FunctionCase: lower_case + readability-identifier-naming.FunctionIgnoredRegexp: '^(AbslHashValue|.*[123][Ddf].*)$' + readability-identifier-naming.GlobalConstantCase: UPPER_CASE + readability-identifier-naming.MemberCase: lower_case + readability-identifier-naming.MemberIgnoredRegexp: '^([A-Z])$' + readability-identifier-naming.MethodCase: lower_case + readability-identifier-naming.MethodIgnoredRegexp: '^(.*[123][Ddf].*)$' + readability-identifier-naming.ParameterIgnoredRegexp: '^(_.*)$' + readability-identifier-naming.StructCase: CamelCase + readability-identifier-naming.VariableCase: aNy_CasE + readability-identifier-naming.VariableIgnoredRegexp: '^(_.*)$' + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.EnumConstantCase: UPPER_CASE \ No newline at end of file diff --git a/.github/workflows/clang-tidy-check.yml b/.github/workflows/clang-tidy-check.yml new file mode 100644 index 000000000..245d6641a --- /dev/null +++ b/.github/workflows/clang-tidy-check.yml @@ -0,0 +1,42 @@ +name: Clang-Tidy Check + +on: + push: + branches: [main] + pull_request: + paths: + - '.github/workflows/clang-tidy-check.yml' + - '.clang-tidy' + - 'src/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + clang-tidy: + name: Run Clang-Tidy + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y clang-tidy cmake build-essential + + - name: Get number of CPU cores + uses: SimenB/github-actions-cpu-cores@v2.0.0 + id: cpu-cores + + - name: Configure CMake + run: | + mkdir -p build + cd build + cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. + + - name: Run Clang-Tidy + run: | + run-clang-tidy -quiet -j ${{ steps.cpu-cores.outputs.count }} -p build $(find src -name '*.cpp') \ No newline at end of file diff --git a/python/src/broad_phase/spatial_hash.cpp b/python/src/broad_phase/spatial_hash.cpp index b0230ea41..35bcf080a 100644 --- a/python/src/broad_phase/spatial_hash.cpp +++ b/python/src/broad_phase/spatial_hash.cpp @@ -69,7 +69,7 @@ void define_spatial_hash(py::module_& m) "voxel_count", &SpatialHash::voxel_count, "The number of voxels in each dimension.") .def_readwrite( - "one_div_voxelSize", &SpatialHash::one_div_voxelSize, + "one_div_voxel_size", &SpatialHash::one_div_voxel_size, "1.0 / voxel_size") .def_readwrite( "voxel_count_0x1", &SpatialHash::voxel_count_0x1, diff --git a/python/src/candidates/candidates.cpp b/python/src/candidates/candidates.cpp index ba83bd0bc..1ba7a87af 100644 --- a/python/src/candidates/candidates.cpp +++ b/python/src/candidates/candidates.cpp @@ -12,7 +12,8 @@ void define_candidates(py::module_& m) "build", py::overload_cast< const CollisionMesh&, Eigen::ConstRef, - const double, std::shared_ptr>(&Candidates::build), + const double, const std::shared_ptr&>( + &Candidates::build), R"ipc_Qu8mg5v7( Initialize the set of discrete collision detection candidates. @@ -29,7 +30,7 @@ void define_candidates(py::module_& m) py::overload_cast< const CollisionMesh&, Eigen::ConstRef, Eigen::ConstRef, const double, - std::shared_ptr>(&Candidates::build), + const std::shared_ptr&>(&Candidates::build), R"ipc_Qu8mg5v7( Initialize the set of continuous collision detection candidates. diff --git a/python/src/collisions/normal/normal_collisions.cpp b/python/src/collisions/normal/normal_collisions.cpp index ddfc0b99d..fceddcc15 100644 --- a/python/src/collisions/normal/normal_collisions.cpp +++ b/python/src/collisions/normal/normal_collisions.cpp @@ -12,7 +12,7 @@ void define_normal_collisions(py::module_& m) "build", py::overload_cast< const CollisionMesh&, Eigen::ConstRef, - const double, const double, std::shared_ptr>( + const double, const double, const std::shared_ptr&>( &NormalCollisions::build), R"ipc_Qu8mg5v7( Initialize the set of collisions used to compute the barrier potential. diff --git a/src/ipc/broad_phase/aabb.hpp b/src/ipc/broad_phase/aabb.hpp index b906757cb..19ca1ec41 100644 --- a/src/ipc/broad_phase/aabb.hpp +++ b/src/ipc/broad_phase/aabb.hpp @@ -65,7 +65,7 @@ class AABB { /// @brief Maximum corner of the AABB. ArrayMax3d max; /// @brief Vertex IDs attached to the AABB. - std::array vertex_ids; + std::array vertex_ids = { { -1, -1, -1 } }; }; /// @brief Build one AABB per vertex position (row of V). diff --git a/src/ipc/broad_phase/broad_phase.cpp b/src/ipc/broad_phase/broad_phase.cpp index 95e5674b0..c9605c3f7 100644 --- a/src/ipc/broad_phase/broad_phase.cpp +++ b/src/ipc/broad_phase/broad_phase.cpp @@ -46,7 +46,7 @@ void BroadPhase::build( Eigen::ConstRef edges, Eigen::ConstRef faces) { - assert(vertex_boxes.size() > 0); + assert(!vertex_boxes.empty()); assert(edges.size() == 0 || edges.cols() == 2); assert(faces.size() == 0 || faces.cols() == 3); build_edge_boxes(vertex_boxes, edges, edge_boxes); diff --git a/src/ipc/broad_phase/broad_phase.hpp b/src/ipc/broad_phase/broad_phase.hpp index d45518f96..b3f3f967c 100644 --- a/src/ipc/broad_phase/broad_phase.hpp +++ b/src/ipc/broad_phase/broad_phase.hpp @@ -114,7 +114,11 @@ class BroadPhase { virtual bool can_edge_face_collide(size_t ei, size_t fi) const; virtual bool can_faces_collide(size_t fai, size_t fbi) const; - static bool default_can_vertices_collide(size_t, size_t) { return true; } + static bool + default_can_vertices_collide(size_t /*unused*/, size_t /*unused*/) + { + return true; + } std::vector vertex_boxes; std::vector edge_boxes; diff --git a/src/ipc/broad_phase/brute_force.cpp b/src/ipc/broad_phase/brute_force.cpp index e6bed7560..d48e9271e 100644 --- a/src/ipc/broad_phase/brute_force.cpp +++ b/src/ipc/broad_phase/brute_force.cpp @@ -22,7 +22,7 @@ void BruteForce::detect_candidates( tbb::enumerable_thread_specific> storage; tbb::parallel_for( - tbb::blocked_range2d(0ul, boxes0.size(), 0ul, boxes1.size()), + tbb::blocked_range2d(0UL, boxes0.size(), 0UL, boxes1.size()), [&](const tbb::blocked_range2d& r) { auto& local_candidates = storage.local(); diff --git a/src/ipc/broad_phase/bvh.cpp b/src/ipc/broad_phase/bvh.cpp index 668333726..e69b496d4 100644 --- a/src/ipc/broad_phase/bvh.cpp +++ b/src/ipc/broad_phase/bvh.cpp @@ -33,7 +33,7 @@ void BVH::build( void BVH::init_bvh(const std::vector& boxes, SimpleBVH::BVH& bvh) { - if (boxes.size() == 0) { + if (boxes.empty()) { return; } @@ -101,7 +101,7 @@ void BVH::detect_candidates( void BVH::detect_vertex_vertex_candidates( std::vector& candidates) const { - if (vertex_boxes.size() == 0) { + if (vertex_boxes.empty()) { return; } @@ -113,7 +113,7 @@ void BVH::detect_vertex_vertex_candidates( void BVH::detect_edge_vertex_candidates( std::vector& candidates) const { - if (edge_boxes.size() == 0 || vertex_boxes.size() == 0) { + if (edge_boxes.empty() || vertex_boxes.empty()) { return; } @@ -127,7 +127,7 @@ void BVH::detect_edge_vertex_candidates( void BVH::detect_edge_edge_candidates( std::vector& candidates) const { - if (edge_boxes.size() == 0) { + if (edge_boxes.empty()) { return; } @@ -140,7 +140,7 @@ void BVH::detect_edge_edge_candidates( void BVH::detect_face_vertex_candidates( std::vector& candidates) const { - if (face_boxes.size() == 0 || vertex_boxes.size() == 0) { + if (face_boxes.empty() || vertex_boxes.empty()) { return; } @@ -153,7 +153,7 @@ void BVH::detect_face_vertex_candidates( void BVH::detect_edge_face_candidates( std::vector& candidates) const { - if (edge_boxes.size() == 0 || face_boxes.size() == 0) { + if (edge_boxes.empty() || face_boxes.empty()) { return; } @@ -166,7 +166,7 @@ void BVH::detect_edge_face_candidates( void BVH::detect_face_face_candidates( std::vector& candidates) const { - if (face_boxes.size() == 0) { + if (face_boxes.empty()) { return; } diff --git a/src/ipc/broad_phase/hash_grid.cpp b/src/ipc/broad_phase/hash_grid.cpp index fbf7f11bb..a9130bf9d 100644 --- a/src/ipc/broad_phase/hash_grid.cpp +++ b/src/ipc/broad_phase/hash_grid.cpp @@ -69,7 +69,7 @@ void HashGrid::insert_boxes( tbb::enumerable_thread_specific> storage; tbb::parallel_for( - tbb::blocked_range(0l, long(boxes.size())), + tbb::blocked_range(0L, long(boxes.size())), [&](const tbb::blocked_range& range) { auto& local_items = storage.local(); for (long i = range.begin(); i != range.end(); i++) { @@ -158,7 +158,7 @@ void HashGrid::detect_candidates( #endif tbb::parallel_for( - tbb::blocked_range2d(0l, num_items - 1, 0l, num_items), + tbb::blocked_range2d(0L, num_items - 1, 0L, num_items), [&](const tbb::blocked_range2d& r) { auto& local_candidates = storage.local(); @@ -237,7 +237,7 @@ void HashGrid::detect_candidates( #endif tbb::parallel_for( - tbb::blocked_range2d(0l, items.size() - 1, 0l, items.size()), + tbb::blocked_range2d(0L, items.size() - 1, 0L, items.size()), [&](const tbb::blocked_range2d& r) { auto& local_candidates = storage.local(); diff --git a/src/ipc/broad_phase/hash_grid.hpp b/src/ipc/broad_phase/hash_grid.hpp index eb3c168bb..f189efe9a 100644 --- a/src/ipc/broad_phase/hash_grid.hpp +++ b/src/ipc/broad_phase/hash_grid.hpp @@ -102,7 +102,7 @@ class HashGrid : public BroadPhase { const AABB& aabb, const long id, std::vector& items) const; /// @brief Create the hash of a cell location. - inline long hash(int x, int y, int z) const + long hash(int x, int y, int z) const { assert(x >= 0 && y >= 0 && z >= 0); assert( @@ -143,7 +143,7 @@ class HashGrid : public BroadPhase { std::vector& candidates) const; protected: - double m_cell_size; + double m_cell_size = -1; ArrayMax3i m_grid_size; ArrayMax3d m_domain_min; ArrayMax3d m_domain_max; diff --git a/src/ipc/broad_phase/spatial_hash.cpp b/src/ipc/broad_phase/spatial_hash.cpp index 25154fc16..6efe32019 100644 --- a/src/ipc/broad_phase/spatial_hash.cpp +++ b/src/ipc/broad_phase/spatial_hash.cpp @@ -131,13 +131,13 @@ void SpatialHash::build( right_top_corner = right_top_corner.max(box.max); } - one_div_voxelSize = 1.0 / voxel_size; + one_div_voxel_size = 1.0 / voxel_size; const ArrayMax3d range = right_top_corner - left_bottom_corner; - voxel_count = (range * one_div_voxelSize).ceil().template cast(); + voxel_count = (range * one_div_voxel_size).ceil().template cast(); if (voxel_count.minCoeff() <= 0) { // cast overflow due to huge search direction - one_div_voxelSize = 1.0 / (range.maxCoeff() * 1.01); + one_div_voxel_size = 1.0 / (range.maxCoeff() * 1.01); voxel_count.setOnes(); } voxel_count_0x1 = voxel_count[0] * voxel_count[1]; @@ -342,7 +342,7 @@ void SpatialHash::detect_candidates( void SpatialHash::detect_vertex_vertex_candidates( std::vector& candidates) const { - if (vertex_boxes.size() == 0) { + if (vertex_boxes.empty()) { return; } @@ -355,7 +355,7 @@ void SpatialHash::detect_vertex_vertex_candidates( void SpatialHash::detect_edge_vertex_candidates( std::vector& candidates) const { - if (edge_boxes.size() == 0 || vertex_boxes.size() == 0) { + if (edge_boxes.empty() || vertex_boxes.empty()) { return; } @@ -369,7 +369,7 @@ void SpatialHash::detect_edge_vertex_candidates( void SpatialHash::detect_edge_edge_candidates( std::vector& candidates) const { - if (edge_boxes.size() == 0) { + if (edge_boxes.empty()) { return; } @@ -381,7 +381,7 @@ void SpatialHash::detect_edge_edge_candidates( void SpatialHash::detect_face_vertex_candidates( std::vector& candidates) const { - if (face_boxes.size() == 0 || vertex_boxes.size() == 0) { + if (face_boxes.empty() || vertex_boxes.empty()) { return; } @@ -396,7 +396,7 @@ void SpatialHash::detect_face_vertex_candidates( void SpatialHash::detect_edge_face_candidates( std::vector& candidates) const { - if (edge_boxes.size() == 0 || face_boxes.size() == 0) { + if (edge_boxes.empty() || face_boxes.empty()) { return; } @@ -410,7 +410,7 @@ void SpatialHash::detect_edge_face_candidates( void SpatialHash::detect_face_face_candidates( std::vector& candidates) const { - if (face_boxes.size() == 0) { + if (face_boxes.empty()) { return; } @@ -430,7 +430,7 @@ int SpatialHash::locate_voxel_index(Eigen::ConstRef p) const ArrayMax3i SpatialHash::locate_voxel_axis_index(Eigen::ConstRef p) const { - return ((p.array() - left_bottom_corner) * one_div_voxelSize) + return ((p.array() - left_bottom_corner) * one_div_voxel_size) .floor() .template cast(); } diff --git a/src/ipc/broad_phase/spatial_hash.hpp b/src/ipc/broad_phase/spatial_hash.hpp index 933ec39f8..d558160fb 100644 --- a/src/ipc/broad_phase/spatial_hash.hpp +++ b/src/ipc/broad_phase/spatial_hash.hpp @@ -110,29 +110,26 @@ class SpatialHash : public BroadPhase { } /// @brief Check if primitive index refers to a vertex. - inline bool is_vertex_index(int idx) const { return idx < edge_start_ind; } + bool is_vertex_index(int idx) const { return idx < edge_start_ind; } /// @brief Check if primitive index refers to an edge. - inline bool is_edge_index(int idx) const + bool is_edge_index(int idx) const { return idx >= edge_start_ind && idx < tri_start_ind; } /// @brief Check if primitive index refers to a triangle. - inline bool is_triangle_index(int idx) const - { - return idx >= tri_start_ind; - } + bool is_triangle_index(int idx) const { return idx >= tri_start_ind; } /// @brief Convert a primitive index to an edge index. - inline int to_edge_index(int idx) const + int to_edge_index(int idx) const { assert(is_edge_index(idx)); return idx - edge_start_ind; } /// @brief Convert a primitive index to a triangle index. - inline int to_triangle_index(int idx) const + int to_triangle_index(int idx) const { assert(is_triangle_index(idx)); return idx - tri_start_ind; @@ -179,15 +176,15 @@ class SpatialHash : public BroadPhase { ArrayMax3i voxel_count; /// @brief 1.0 / voxel_size - double one_div_voxelSize; + double one_div_voxel_size = -1; /// @brief The number of voxels in the first two dimensions. - int voxel_count_0x1; + int voxel_count_0x1 = -1; // // The index of the first edge in voxel_occupancies - int edge_start_ind; + int edge_start_ind = -1; // // The index of the first triangle in voxel_occupancies - int tri_start_ind; + int tri_start_ind = -1; /// @brief Map from voxel index to the primitive indices it contains. unordered_map> voxel_to_primitives; @@ -207,20 +204,20 @@ class SpatialHash : public BroadPhase { Eigen::ConstRef faces, double voxel_size); - void query_point_for_points(int vi, unordered_set& vert_inds) const; + void query_point_for_points(int vi, unordered_set& vert_ids) const; - void query_point_for_edges(int vi, unordered_set& edge_inds) const; + void query_point_for_edges(int vi, unordered_set& edge_ids) const; - void query_point_for_triangles(int vi, unordered_set& tri_inds) const; + void query_point_for_triangles(int vi, unordered_set& tri_ids) const; - // will only put edges with larger than ei index into edge_inds - void query_edge_for_edges(int eai, unordered_set& edge_inds) const; + // will only put edges with larger than ei index into edge_ids + void query_edge_for_edges(int eai, unordered_set& edge_ids) const; - void query_edge_for_triangles(int ei, unordered_set& tri_inds) const; + void query_edge_for_triangles(int ei, unordered_set& tri_ids) const; - // will only put triangles with larger than ti index into tri_inds + // will only put triangles with larger than ti index into tri_ids void - query_triangle_for_triangles(int ti, unordered_set& tri_inds) const; + query_triangle_for_triangles(int fai, unordered_set& tri_ids) const; int locate_voxel_index(Eigen::ConstRef p) const; @@ -238,7 +235,7 @@ class SpatialHash : public BroadPhase { int voxel_axis_index_to_voxel_index(int ix, int iy, int iz) const; - int dim; + int dim = -1; private: /// @brief Detect candidate collisions between type A and type B. diff --git a/src/ipc/broad_phase/voxel_size_heuristic.cpp b/src/ipc/broad_phase/voxel_size_heuristic.cpp index 3f6455e1c..e507be76d 100644 --- a/src/ipc/broad_phase/voxel_size_heuristic.cpp +++ b/src/ipc/broad_phase/voxel_size_heuristic.cpp @@ -79,7 +79,7 @@ double suggest_good_voxel_size( double suggest_good_voxel_size(const std::vector& boxes) { - assert(boxes.size() > 0); + assert(!boxes.empty()); Eigen::VectorXd box_sizes(boxes.size()); for (size_t i = 0; i < boxes.size(); ++i) { diff --git a/src/ipc/candidates/candidates.cpp b/src/ipc/candidates/candidates.cpp index bdaffce9a..548542395 100644 --- a/src/ipc/candidates/candidates.cpp +++ b/src/ipc/candidates/candidates.cpp @@ -36,7 +36,7 @@ void Candidates::build( const CollisionMesh& mesh, Eigen::ConstRef vertices, const double inflation_radius, - const std::shared_ptr broad_phase) + const std::shared_ptr& broad_phase) { assert(broad_phase != nullptr); @@ -108,7 +108,7 @@ void Candidates::build( Eigen::ConstRef vertices_t0, Eigen::ConstRef vertices_t1, const double inflation_radius, - const std::shared_ptr broad_phase) + const std::shared_ptr& broad_phase) { assert(broad_phase != nullptr); @@ -250,9 +250,7 @@ double Candidates::compute_collision_free_stepsize( if (are_colliding) { std::unique_lock lock(earliest_toi_mutex); - if (toi < earliest_toi) { - earliest_toi = toi; - } + earliest_toi = std::min(earliest_toi, toi); } } }); @@ -303,7 +301,7 @@ double Candidates::compute_cfl_stepsize( Eigen::ConstRef vertices_t1, const double dhat, const double min_distance, - const std::shared_ptr broad_phase, + const std::shared_ptr& broad_phase, const NarrowPhaseCCD& narrow_phase_ccd) const { assert(vertices_t0.rows() == mesh.num_vertices()); diff --git a/src/ipc/candidates/candidates.hpp b/src/ipc/candidates/candidates.hpp index 5c947fecf..a0539e3a9 100644 --- a/src/ipc/candidates/candidates.hpp +++ b/src/ipc/candidates/candidates.hpp @@ -26,7 +26,7 @@ class Candidates { const CollisionMesh& mesh, Eigen::ConstRef vertices, const double inflation_radius = 0, - const std::shared_ptr broad_phase = + const std::shared_ptr& broad_phase = make_default_broad_phase()); /// @brief Initialize the set of continuous collision detection candidates. @@ -41,7 +41,7 @@ class Candidates { Eigen::ConstRef vertices_t0, Eigen::ConstRef vertices_t1, const double inflation_radius = 0, - const std::shared_ptr broad_phase = + const std::shared_ptr& broad_phase = make_default_broad_phase()); /// @brief Get the number of collision candidates. @@ -120,7 +120,7 @@ class Candidates { Eigen::ConstRef vertices_t1, const double dhat, const double min_distance = 0.0, - const std::shared_ptr broad_phase = + const std::shared_ptr& broad_phase = make_default_broad_phase(), const NarrowPhaseCCD& narrow_phase_ccd = DEFAULT_NARROW_PHASE_CCD) const; diff --git a/src/ipc/candidates/collision_stencil.cpp b/src/ipc/candidates/collision_stencil.cpp index f4b8fa440..53582d7fd 100644 --- a/src/ipc/candidates/collision_stencil.cpp +++ b/src/ipc/candidates/collision_stencil.cpp @@ -35,7 +35,6 @@ MatrixMax CollisionStencil::compute_normal_jacobian( MatrixMax dn = compute_unnormalized_normal_jacobian(positions); -#if true // Derivative of normalization (n̂ = n / ‖n‖) const double n_norm = n.norm(); n /= n_norm; // n̂ @@ -44,7 +43,6 @@ MatrixMax CollisionStencil::compute_normal_jacobian( (MatrixMax3d::Identity(dim, dim) - n * n.transpose()) / n_norm; dn = A * dn; -#endif if (flip_if_negative && (positions.head(dim) - positions.tail(dim)).dot(n) < 0) { diff --git a/src/ipc/ccd/additive_ccd.cpp b/src/ipc/ccd/additive_ccd.cpp index cc9abe911..645298209 100644 --- a/src/ipc/ccd/additive_ccd.cpp +++ b/src/ipc/ccd/additive_ccd.cpp @@ -71,7 +71,8 @@ AdditiveCCD::AdditiveCCD( bool AdditiveCCD::additive_ccd( VectorMax12d x, // mutable copy Eigen::ConstRef dx, - const std::function)> distance_squared, + const std::function)>& + distance_squared, const double max_disp_mag, double& toi, const double min_distance, diff --git a/src/ipc/ccd/additive_ccd.hpp b/src/ipc/ccd/additive_ccd.hpp index 72708e386..b82f0d82b 100644 --- a/src/ipc/ccd/additive_ccd.hpp +++ b/src/ipc/ccd/additive_ccd.hpp @@ -18,7 +18,7 @@ namespace ipc { class AdditiveCCD : public NarrowPhaseCCD { public: /// The default maximum number of iterations used with Tight-Inclusion CCD. - static constexpr long DEFAULT_MAX_ITERATIONS = 10'000'000l; + static constexpr long DEFAULT_MAX_ITERATIONS = 10'000'000L; /// Unlimitted number of iterations. static constexpr long UNLIMITTED_ITERATIONS = -1; /// The default conservative rescaling value used to avoid taking steps @@ -143,7 +143,7 @@ class AdditiveCCD : public NarrowPhaseCCD { bool additive_ccd( VectorMax12d x, // mutable copy Eigen::ConstRef dx, - const std::function)> + const std::function)>& distance_squared, const double max_disp_mag, double& toi, diff --git a/src/ipc/ccd/nonlinear_ccd.cpp b/src/ipc/ccd/nonlinear_ccd.cpp index 5f2305c7d..d7862355a 100644 --- a/src/ipc/ccd/nonlinear_ccd.cpp +++ b/src/ipc/ccd/nonlinear_ccd.cpp @@ -15,9 +15,9 @@ namespace ipc { #ifdef USE_FIXED_PIECES -static constexpr size_t FIXED_NUM_PIECES = 100l; +static constexpr size_t FIXED_NUM_PIECES = 100L; #else -static constexpr size_t MAX_NUM_SUBDIVISIONS = 1000l; +static constexpr size_t MAX_NUM_SUBDIVISIONS = 1000L; #endif // ============================================================================ @@ -233,7 +233,7 @@ bool edge_edge_nonlinear_ccd( const NonlinearTrajectory& eb1, double& toi, const double tmax, - const double min_sep_distance, + const double min_distance, const double tolerance, const long max_iterations, const double conservative_rescaling) @@ -265,7 +265,7 @@ bool edge_edge_nonlinear_ccd( output_tolerance, // delta_actual no_zero_toi); // no zero toi }, - toi, tmax, min_sep_distance, conservative_rescaling); + toi, tmax, min_distance, conservative_rescaling); } bool point_triangle_nonlinear_ccd( diff --git a/src/ipc/ccd/nonlinear_ccd.hpp b/src/ipc/ccd/nonlinear_ccd.hpp index 3bc4a2eb2..abd68ad9f 100644 --- a/src/ipc/ccd/nonlinear_ccd.hpp +++ b/src/ipc/ccd/nonlinear_ccd.hpp @@ -164,7 +164,7 @@ bool conservative_piecewise_linear_ccd( double& /*toi*/)>& linear_ccd, double& toi, const double tmax = 1.0, - const double min_distance = 0, + const double min_sep_distance = 0, const double conservative_rescaling = TightInclusionCCD::DEFAULT_CONSERVATIVE_RESCALING); diff --git a/src/ipc/ccd/tight_inclusion_ccd.hpp b/src/ipc/ccd/tight_inclusion_ccd.hpp index 244141460..ceeffb547 100644 --- a/src/ipc/ccd/tight_inclusion_ccd.hpp +++ b/src/ipc/ccd/tight_inclusion_ccd.hpp @@ -10,7 +10,7 @@ class TightInclusionCCD : public NarrowPhaseCCD { /// The default tolerance used with Tight-Inclusion CCD. static constexpr double DEFAULT_TOLERANCE = 1e-6; /// The default maximum number of iterations used with Tight-Inclusion CCD. - static constexpr long DEFAULT_MAX_ITERATIONS = 10'000'000l; + static constexpr long DEFAULT_MAX_ITERATIONS = 10'000'000L; /// The default conservative rescaling value used to avoid taking steps /// exactly to impact. static constexpr double DEFAULT_CONSERVATIVE_RESCALING = 0.8; diff --git a/src/ipc/collision_mesh.cpp b/src/ipc/collision_mesh.cpp index 1a6a28792..870e9329c 100644 --- a/src/ipc/collision_mesh.cpp +++ b/src/ipc/collision_mesh.cpp @@ -5,6 +5,8 @@ #include #include +#include + namespace ipc { CollisionMesh::CollisionMesh( @@ -258,9 +260,8 @@ void CollisionMesh::init_areas() double edge_len = (e1 - e0).norm(); for (int j = 0; j < m_edges.cols(); j++) { - if (vertex_edge_areas[m_edges(i, j)] < 0) { - vertex_edge_areas[m_edges(i, j)] = 0; - } + vertex_edge_areas[m_edges(i, j)] = + std::max(vertex_edge_areas[m_edges(i, j)], 0.0); vertex_edge_areas[m_edges(i, j)] += 0.5 * edge_len; } } @@ -277,14 +278,12 @@ void CollisionMesh::init_areas() double face_area = 0.5 * (f1 - f0).cross(f2 - f0).norm(); for (int j = 0; j < m_faces.cols(); ++j) { - if (vertex_face_areas[m_faces(i, j)] < 0) { - vertex_face_areas[m_faces(i, j)] = 0; - } + vertex_face_areas[m_faces(i, j)] = + std::max(vertex_face_areas[m_faces(i, j)], 0.0); vertex_face_areas[m_faces(i, j)] += face_area / 3.0; - if (m_edge_areas[m_faces_to_edges(i, j)] < 0) { - m_edge_areas[m_faces_to_edges(i, j)] = 0; - } + m_edge_areas[m_faces_to_edges(i, j)] = + std::max(m_edge_areas[m_faces_to_edges(i, j)], 0.0); m_edge_areas[m_faces_to_edges(i, j)] += face_area / 3.0; } } diff --git a/src/ipc/collision_mesh.hpp b/src/ipc/collision_mesh.hpp index ececc6e2b..1298c0714 100644 --- a/src/ipc/collision_mesh.hpp +++ b/src/ipc/collision_mesh.hpp @@ -5,7 +5,7 @@ namespace ipc { -/// @brief A class for encapsolating the transformation/selections needed to go from a volumetric FE mesh to a surface collision mesh. +/// @brief A class for encapsulating the transformation/selections needed to go from a volumetric FE mesh to a surface collision mesh. class CollisionMesh { public: /// @brief Construct a new Collision Mesh object. @@ -365,7 +365,10 @@ class CollisionMesh { private: /// @brief By default all primitives can collide with all other primitives. - static int default_can_collide(size_t, size_t) { return true; } + static bool default_can_collide(size_t /*unused*/, size_t /*unused*/) + { + return true; + } }; } // namespace ipc diff --git a/src/ipc/collisions/normal/normal_collisions.cpp b/src/ipc/collisions/normal/normal_collisions.cpp index c3b8f3c4a..ae83b2752 100644 --- a/src/ipc/collisions/normal/normal_collisions.cpp +++ b/src/ipc/collisions/normal/normal_collisions.cpp @@ -145,7 +145,7 @@ void NormalCollisions::build( Eigen::ConstRef vertices, const double dhat, const double dmin, - const std::shared_ptr broad_phase) + const std::shared_ptr& broad_phase) { assert(vertices.rows() == mesh.num_vertices()); @@ -210,7 +210,7 @@ void NormalCollisions::build( }); if (use_improved_max_approximator()) { - if (candidates.ev_candidates.size() > 0) { + if (!candidates.ev_candidates.empty()) { // Convert edge-vertex to vertex-vertex const std::vector vv_candidates = edge_vertex_to_vertex_vertex_candidates( @@ -225,7 +225,7 @@ void NormalCollisions::build( }); } - if (candidates.ee_candidates.size() > 0) { + if (!candidates.ee_candidates.empty()) { // Convert edge-edge to edge-vertex const auto ev_candidates = edge_edge_to_edge_vertex_candidates( mesh, vertices, candidates.ee_candidates, is_active); @@ -239,7 +239,7 @@ void NormalCollisions::build( }); } - if (candidates.fv_candidates.size() > 0) { + if (!candidates.fv_candidates.empty()) { // Convert face-vertex to edge-vertex const std::vector ev_candidates = face_vertex_to_edge_vertex_candidates( @@ -348,10 +348,7 @@ double NormalCollisions::compute_minimum_distance( for (size_t i = r.begin(); i < r.end(); i++) { const double dist = (*this)[i].compute_distance( (*this)[i].dof(vertices, edges, faces)); - - if (dist < partial_min_dist) { - partial_min_dist = dist; - } + partial_min_dist = std::min(partial_min_dist, dist); } return partial_min_dist; }, diff --git a/src/ipc/collisions/normal/normal_collisions.hpp b/src/ipc/collisions/normal/normal_collisions.hpp index 1e85ca3a9..0acb14dc5 100644 --- a/src/ipc/collisions/normal/normal_collisions.hpp +++ b/src/ipc/collisions/normal/normal_collisions.hpp @@ -34,7 +34,7 @@ class NormalCollisions { Eigen::ConstRef vertices, const double dhat, const double dmin = 0, - const std::shared_ptr broad_phase = + const std::shared_ptr& broad_phase = make_default_broad_phase()); /// @brief Initialize the set of collisions used to compute the barrier potential. diff --git a/src/ipc/collisions/normal/normal_collisions_builder.cpp b/src/ipc/collisions/normal/normal_collisions_builder.cpp index 2ded5e81c..0930506b7 100644 --- a/src/ipc/collisions/normal/normal_collisions_builder.cpp +++ b/src/ipc/collisions/normal/normal_collisions_builder.cpp @@ -72,8 +72,9 @@ void NormalCollisionsBuilder::add_edge_vertex_collisions( const PointEdgeDistanceType dtype = point_edge_distance_type(v, e0, e1); const double distance_sqr = point_edge_distance(v, e0, e1, dtype); - if (!is_active(distance_sqr)) + if (!is_active(distance_sqr)) { continue; + } // ÷ 2 to handle double counting for correct integration const double weight = @@ -145,8 +146,9 @@ void NormalCollisionsBuilder::add_edge_edge_collisions( const double distance_sqr = edge_edge_distance(ea0, ea1, eb0, eb1, actual_dtype); - if (!is_active(distance_sqr)) + if (!is_active(distance_sqr)) { continue; + } const double eps_x = edge_edge_mollifier_threshold( mesh.rest_positions().row(ea0i), mesh.rest_positions().row(ea1i), @@ -245,8 +247,9 @@ void NormalCollisionsBuilder::add_face_vertex_collisions( const double distance_sqr = point_triangle_distance(v, f0, f1, f2, dtype); - if (!is_active(distance_sqr)) + if (!is_active(distance_sqr)) { continue; + } // ÷ 4 to handle double counting and PT + EE for correct integration const double weight = diff --git a/src/ipc/collisions/tangential/tangential_collision.hpp b/src/ipc/collisions/tangential/tangential_collision.hpp index 793eea1c9..dcb71f28a 100644 --- a/src/ipc/collisions/tangential/tangential_collision.hpp +++ b/src/ipc/collisions/tangential/tangential_collision.hpp @@ -83,13 +83,13 @@ class TangentialCollision : virtual public CollisionStencil { public: /// @brief Normal force magnitude - double normal_force_magnitude; + double normal_force_magnitude = 0; /// @brief Ratio between normal and static tangential forces (e.g., friction coefficient) - double mu_s; + double mu_s = 0; /// @brief Ratio between normal and kinetic tangential forces (e.g., friction coefficient) - double mu_k; + double mu_k = 0; /// @brief Weight double weight = 1; diff --git a/src/ipc/collisions/tangential/tangential_collisions.hpp b/src/ipc/collisions/tangential/tangential_collisions.hpp index d4679828d..5ecf7db22 100644 --- a/src/ipc/collisions/tangential/tangential_collisions.hpp +++ b/src/ipc/collisions/tangential/tangential_collisions.hpp @@ -80,8 +80,8 @@ class TangentialCollisions { const NormalCollisions& collisions, const NormalPotential& normal_potential, const double normal_stiffness, - Eigen::ConstRef mu_k, Eigen::ConstRef mu_s, + Eigen::ConstRef mu_k, const std::function& blend_mu = default_blend_mu); diff --git a/src/ipc/distance/distance_type.hpp b/src/ipc/distance/distance_type.hpp index 7a1ddcc3c..3c04c9396 100644 --- a/src/ipc/distance/distance_type.hpp +++ b/src/ipc/distance/distance_type.hpp @@ -5,7 +5,7 @@ namespace ipc { /// @brief Closest pair between a point and edge. -enum class PointEdgeDistanceType { +enum class PointEdgeDistanceType : uint8_t { P_E0, ///< The point is closest to edge vertex zero. P_E1, ///< The point is closest to edge vertex one. P_E, ///< The point is closest to the interior of the edge. @@ -13,7 +13,7 @@ enum class PointEdgeDistanceType { }; /// @brief Closest pair between a point and triangle. -enum class PointTriangleDistanceType { +enum class PointTriangleDistanceType : uint8_t { P_T0, ///< The point is closest to triangle vertex zero. P_T1, ///< The point is closest to triangle vertex one. P_T2, ///< The point is closest to triangle vertex two. @@ -25,7 +25,7 @@ enum class PointTriangleDistanceType { }; /// @brief Closest pair between two edges. -enum class EdgeEdgeDistanceType { +enum class EdgeEdgeDistanceType : uint8_t { /// The edges are closest at vertex 0 of edge A and 0 of edge B. EA0_EB0, /// The edges are closest at vertex 0 of edge A and 1 of edge B. diff --git a/src/ipc/implicits/plane.cpp b/src/ipc/implicits/plane.cpp index b59565027..5dbe8451d 100644 --- a/src/ipc/implicits/plane.cpp +++ b/src/ipc/implicits/plane.cpp @@ -116,9 +116,7 @@ double compute_point_plane_collision_free_stepsize( plane_normal, toi); if (are_colliding) { - if (toi < current_toi) { - current_toi = toi; - } + current_toi = std::min(current_toi, toi); } } } diff --git a/src/ipc/implicits/plane.hpp b/src/ipc/implicits/plane.hpp index 7b659d97e..7b3bed163 100644 --- a/src/ipc/implicits/plane.hpp +++ b/src/ipc/implicits/plane.hpp @@ -8,7 +8,11 @@ namespace ipc { -inline bool default_can_point_plane_collide(size_t, size_t) { return true; } +inline bool +default_can_point_plane_collide(size_t /*unused*/, size_t /*unused*/) +{ + return true; +} /// @brief Construct a set of point-plane distance collisions used to compute /// the barrier potential. diff --git a/src/ipc/ipc.cpp b/src/ipc/ipc.cpp index ebda24fd2..d149b65b9 100644 --- a/src/ipc/ipc.cpp +++ b/src/ipc/ipc.cpp @@ -19,7 +19,7 @@ bool is_step_collision_free( Eigen::ConstRef vertices_t0, Eigen::ConstRef vertices_t1, const double min_distance, - const std::shared_ptr broad_phase, + const std::shared_ptr& broad_phase, const NarrowPhaseCCD& narrow_phase_ccd) { assert(vertices_t0.rows() == mesh.num_vertices()); @@ -43,7 +43,7 @@ double compute_collision_free_stepsize( Eigen::ConstRef vertices_t0, Eigen::ConstRef vertices_t1, const double min_distance, - const std::shared_ptr broad_phase, + const std::shared_ptr& broad_phase, const NarrowPhaseCCD& narrow_phase_ccd) { assert(broad_phase != nullptr); @@ -91,7 +91,7 @@ double compute_collision_free_stepsize( bool has_intersections( const CollisionMesh& mesh, Eigen::ConstRef vertices, - const std::shared_ptr broad_phase) + const std::shared_ptr& broad_phase) { assert(broad_phase != nullptr); assert(vertices.rows() == mesh.num_vertices()); diff --git a/src/ipc/ipc.hpp b/src/ipc/ipc.hpp index 518cf4d21..9bab832de 100644 --- a/src/ipc/ipc.hpp +++ b/src/ipc/ipc.hpp @@ -27,7 +27,7 @@ bool is_step_collision_free( Eigen::ConstRef vertices_t0, Eigen::ConstRef vertices_t1, const double min_distance = 0.0, - const std::shared_ptr broad_phase = make_default_broad_phase(), + const std::shared_ptr& broad_phase = make_default_broad_phase(), const NarrowPhaseCCD& narrow_phase_ccd = DEFAULT_NARROW_PHASE_CCD); /// @brief Computes a maximal step size that is collision free. @@ -44,7 +44,7 @@ double compute_collision_free_stepsize( Eigen::ConstRef vertices_t0, Eigen::ConstRef vertices_t1, const double min_distance = 0.0, - const std::shared_ptr broad_phase = make_default_broad_phase(), + const std::shared_ptr& broad_phase = make_default_broad_phase(), const NarrowPhaseCCD& narrow_phase_ccd = DEFAULT_NARROW_PHASE_CCD); // ============================================================================ @@ -58,6 +58,7 @@ double compute_collision_free_stepsize( bool has_intersections( const CollisionMesh& mesh, Eigen::ConstRef vertices, - const std::shared_ptr broad_phase = make_default_broad_phase()); + const std::shared_ptr& broad_phase = + make_default_broad_phase()); } // namespace ipc diff --git a/src/ipc/potentials/barrier_potential.cpp b/src/ipc/potentials/barrier_potential.cpp index 3af38c0cf..9b52336e5 100644 --- a/src/ipc/potentials/barrier_potential.cpp +++ b/src/ipc/potentials/barrier_potential.cpp @@ -13,14 +13,15 @@ BarrierPotential::BarrierPotential( } BarrierPotential::BarrierPotential( - const std::shared_ptr barrier, + const std::shared_ptr& barrier, const double dhat, const bool use_physical_barrier) - : NormalPotential() + : m_barrier(barrier) + , m_dhat(dhat) + , m_use_physical_barrier(use_physical_barrier) { - set_dhat(dhat); - set_barrier(barrier); - set_use_physical_barrier(use_physical_barrier); + assert(dhat > 0); + assert(barrier != nullptr); } double BarrierPotential::force_magnitude( diff --git a/src/ipc/potentials/barrier_potential.hpp b/src/ipc/potentials/barrier_potential.hpp index f054698e3..1f7d0b606 100644 --- a/src/ipc/potentials/barrier_potential.hpp +++ b/src/ipc/potentials/barrier_potential.hpp @@ -23,7 +23,7 @@ class BarrierPotential : public NormalPotential { /// @param dhat The activation distance of the barrier. /// @param use_physical_barrier Whether to use the physical barrier. BarrierPotential( - const std::shared_ptr barrier, + const std::shared_ptr& barrier, const double dhat, const bool use_physical_barrier = false); @@ -47,7 +47,7 @@ class BarrierPotential : public NormalPotential { /// @brief Set the barrier function used to compute the potential. /// @param barrier The barrier function used to compute the potential. - void set_barrier(const std::shared_ptr barrier) + void set_barrier(const std::shared_ptr& barrier) { assert(barrier != nullptr); m_barrier = barrier; diff --git a/src/ipc/potentials/friction_potential.cpp b/src/ipc/potentials/friction_potential.cpp index 28a4a3f39..30eb8f707 100644 --- a/src/ipc/potentials/friction_potential.cpp +++ b/src/ipc/potentials/friction_potential.cpp @@ -4,9 +4,11 @@ namespace ipc { -FrictionPotential::FrictionPotential(const double eps_v) : Super() +FrictionPotential::FrictionPotential(const double eps_v) + : Super() + , m_eps_v(eps_v) { - set_eps_v(eps_v); + assert(eps_v > 0); } double FrictionPotential::mu_f0( diff --git a/src/ipc/potentials/normal_adhesion_potential.cpp b/src/ipc/potentials/normal_adhesion_potential.cpp index 641703c68..a8c0b8e3d 100644 --- a/src/ipc/potentials/normal_adhesion_potential.cpp +++ b/src/ipc/potentials/normal_adhesion_potential.cpp @@ -17,7 +17,9 @@ NormalAdhesionPotential::NormalAdhesionPotential( } double NormalAdhesionPotential::force_magnitude( - const double, const double dmin, const double) const + const double /*distance_squared*/, + const double dmin, + const double /*barrier_stiffness*/) const { const auto [arg_dhat_p, arg_dhat_a, a2] = normal_adhesion_potential_args(dmin); @@ -25,10 +27,10 @@ double NormalAdhesionPotential::force_magnitude( } VectorMax12d NormalAdhesionPotential::force_magnitude_gradient( - const double, + const double /*distance_squared*/, Eigen::ConstRef distance_squared_gradient, - const double, - const double) const + const double /*dmin*/, + const double /*barrier_stiffness*/) const { // The force magnitude is constant wrt positions, so the gradient is zero. return VectorMax12d::Zero(distance_squared_gradient.size()); diff --git a/src/ipc/potentials/normal_potential.cpp b/src/ipc/potentials/normal_potential.cpp index 3744efb88..4e0c6f46f 100644 --- a/src/ipc/potentials/normal_potential.cpp +++ b/src/ipc/potentials/normal_potential.cpp @@ -167,7 +167,7 @@ void NormalPotential::shape_derivative( "Shape derivative is not computed for collisions!"); } - if (collision.weight_gradient.nonZeros()) { + if (collision.weight_gradient.nonZeros() > 0) { VectorMax12d grad_f = gradient(collision, positions); assert(collision.weight != 0); grad_f.array() /= collision.weight; // remove weight diff --git a/src/ipc/potentials/tangential_adhesion_potential.cpp b/src/ipc/potentials/tangential_adhesion_potential.cpp index 8f70f0536..4f7d402b2 100644 --- a/src/ipc/potentials/tangential_adhesion_potential.cpp +++ b/src/ipc/potentials/tangential_adhesion_potential.cpp @@ -6,8 +6,9 @@ namespace ipc { TangentialAdhesionPotential::TangentialAdhesionPotential(const double eps_a) : Super() + , m_eps_a(eps_a) { - set_eps_a(eps_a); + assert(eps_a > 0); } double TangentialAdhesionPotential::mu_f0( diff --git a/src/ipc/potentials/tangential_potential.cpp b/src/ipc/potentials/tangential_potential.cpp index bda8334d0..17ed25b4a 100644 --- a/src/ipc/potentials/tangential_potential.cpp +++ b/src/ipc/potentials/tangential_potential.cpp @@ -406,7 +406,7 @@ MatrixMax12d TangentialPotential::force_jacobian( } // Vertex-vertex does not have a closest point - if (beta.size()) { + if (beta.size() != 0) { // ∇Γ(β) = ∇ᵦΓ∇β ∈ ℝ^{d×n×n} ≡ ℝ^{nd×n} const MatrixMax jac_beta = collision.compute_closest_point_jacobian(lagged_positions); diff --git a/src/ipc/potentials/tangential_potential.hpp b/src/ipc/potentials/tangential_potential.hpp index b09f7cccb..c0bf69527 100644 --- a/src/ipc/potentials/tangential_potential.hpp +++ b/src/ipc/potentials/tangential_potential.hpp @@ -21,7 +21,7 @@ class TangentialPotential : public Potential { using Super::hessian; /// @brief Variable to differentiate the friction force with respect to. - enum class DiffWRT { + enum class DiffWRT : uint8_t { REST_POSITIONS, ///< Differentiate w.r.t. rest positions LAGGED_DISPLACEMENTS, ///< Differentiate w.r.t. lagged displacements VELOCITIES ///< Differentiate w.r.t. current velocities diff --git a/src/ipc/tangent/closest_point.cpp b/src/ipc/tangent/closest_point.cpp index 16dd278ca..e16dcf4f8 100644 --- a/src/ipc/tangent/closest_point.cpp +++ b/src/ipc/tangent/closest_point.cpp @@ -50,17 +50,17 @@ Eigen::Vector2d edge_edge_closest_point( const Eigen::Vector3d ea = ea1 - ea0; const Eigen::Vector3d eb = eb1 - eb0; - Eigen::Matrix coefMtr; - coefMtr(0, 0) = ea.squaredNorm(); - coefMtr(0, 1) = coefMtr(1, 0) = -eb.dot(ea); - coefMtr(1, 1) = eb.squaredNorm(); + Eigen::Matrix A; + A(0, 0) = ea.squaredNorm(); + A(0, 1) = A(1, 0) = -eb.dot(ea); + A(1, 1) = eb.squaredNorm(); Eigen::Vector2d rhs; rhs[0] = -eb_to_ea.dot(ea); rhs[1] = eb_to_ea.dot(eb); - const Eigen::Vector2d x = coefMtr.ldlt().solve(rhs); - assert((coefMtr * x - rhs).norm() < 1e-10); + const Eigen::Vector2d x = A.ldlt().solve(rhs); + assert((A * x - rhs).norm() < 1e-10); return x; } diff --git a/src/ipc/utils/eigen_ext.hpp b/src/ipc/utils/eigen_ext.hpp index 725323caa..9904357f2 100644 --- a/src/ipc/utils/eigen_ext.hpp +++ b/src/ipc/utils/eigen_ext.hpp @@ -193,7 +193,7 @@ project_to_pd( double eps = 1e-8); /// @brief Enumeration of implemented PSD projection methods -enum class PSDProjectionMethod { +enum class PSDProjectionMethod : uint8_t { NONE, ///< No PSD projection CLAMP, ///< Clamp negative eigenvalues to zero ABS ///< Flip negative eigenvalues to positive diff --git a/src/ipc/utils/eigen_ext.tpp b/src/ipc/utils/eigen_ext.tpp index 2b3b3da89..d4f342fab 100644 --- a/src/ipc/utils/eigen_ext.tpp +++ b/src/ipc/utils/eigen_ext.tpp @@ -67,8 +67,9 @@ project_to_psd( { assert(A.isApprox(A.transpose()) && "A must be symmetric"); - if (method == PSDProjectionMethod::NONE) + if (method == PSDProjectionMethod::NONE) { return A; + } // https://math.stackexchange.com/q/2776803 Eigen::SelfAdjointEigenSolver< diff --git a/src/ipc/utils/interval.hpp b/src/ipc/utils/interval.hpp index 32f1cbc11..d432371c8 100644 --- a/src/ipc/utils/interval.hpp +++ b/src/ipc/utils/interval.hpp @@ -18,28 +18,16 @@ class Interval : public interval { Interval(const interval& i) : interval(i) { } /// @brief Construct an empty Interval - Interval() - { - this->INF = 0; - this->SUP = 0; - } + Interval() : interval({ 0, 0 }) { } /// @brief Construct an Interval from a single value /// @param x The value - explicit Interval(double x) - { - this->INF = x; - this->SUP = x; - } + explicit Interval(double x) : interval({ x, x }) { } /// @brief Construct an Interval from two values /// @param x The infimum value /// @param y The supremum value - Interval(double x, double y) - { - this->INF = x; - this->SUP = y; - } + Interval(double x, double y) : interval({ x, y }) { } static Interval empty() { @@ -89,15 +77,15 @@ using MatrixMax3I = MatrixMax3; /// @brief Compute the squared L2 norm of an n-dimensional interval /// @note This should be used instead of the .squaredNorm() method of Eigen because it avoids negative values in intermediate computations. -/// @param v The n-dimensional interval +/// @param x The n-dimensional interval /// @return The squared L2 norm of the interval -filib::Interval squared_norm(Eigen::ConstRef v); // L2 norm +filib::Interval squared_norm(Eigen::ConstRef x); // L2 norm /// @brief Compute the L2 norm of a n-dimensional interval /// @note This should be used instead of the .norm() method of Eigen because it avoids negative values in intermediate computations. -/// @param v The n-dimensional interval +/// @param x The n-dimensional interval /// @return The L2 norm of the interval -filib::Interval norm(Eigen::ConstRef v); // L2 norm +filib::Interval norm(Eigen::ConstRef x); // L2 norm } // namespace ipc diff --git a/src/ipc/utils/logger.cpp b/src/ipc/utils/logger.cpp index 4bd36d340..331fa945a 100644 --- a/src/ipc/utils/logger.cpp +++ b/src/ipc/utils/logger.cpp @@ -33,9 +33,9 @@ spdlog::logger& logger() } // Use a custom logger -void set_logger(std::shared_ptr x) +void set_logger(std::shared_ptr logger) { - get_shared_logger() = std::move(x); + get_shared_logger() = std::move(logger); } void log_and_throw_error(const std::string& msg) diff --git a/src/ipc/utils/save_obj.cpp b/src/ipc/utils/save_obj.cpp index 3672c35dd..f8d82795d 100644 --- a/src/ipc/utils/save_obj.cpp +++ b/src/ipc/utils/save_obj.cpp @@ -13,10 +13,10 @@ template <> void save_obj( std::ostream& out, Eigen::ConstRef V, - Eigen::ConstRef, - Eigen::ConstRef, + Eigen::ConstRef /*unused*/, + Eigen::ConstRef /*unused*/, const std::vector& vv_candidates, - const int) + const int /*unused*/) { out << "o VV\n"; for (const auto& vv_candidate : vv_candidates) { diff --git a/tests/src/tests/broad_phase/test_broad_phase.cpp b/tests/src/tests/broad_phase/test_broad_phase.cpp index 25ac29132..db7a0bec3 100644 --- a/tests/src/tests/broad_phase/test_broad_phase.cpp +++ b/tests/src/tests/broad_phase/test_broad_phase.cpp @@ -47,7 +47,7 @@ void test_face_face_broad_phase( std::vector bf_ff_candidates; bf.detect_face_face_candidates(bf_ff_candidates); - CHECK(ff_candidates.size() > 0); + CHECK(!ff_candidates.empty()); CHECK(ff_candidates.size() == bf_ff_candidates.size()); } diff --git a/tests/src/tests/collisions/test_normal_collisions.cpp b/tests/src/tests/collisions/test_normal_collisions.cpp index 91e6e45b5..f1e02c262 100644 --- a/tests/src/tests/collisions/test_normal_collisions.cpp +++ b/tests/src/tests/collisions/test_normal_collisions.cpp @@ -45,7 +45,7 @@ TEST_CASE("Codim. vertex-vertex collisions", "[collisions][codim]") Candidates candidates; candidates.build(mesh, vertices, V1, thickness, broad_phase); - CHECK(candidates.size() > 0); + CHECK(!candidates.empty()); CHECK(candidates.vv_candidates.size() == candidates.size()); CHECK(!candidates.is_step_collision_free( diff --git a/tests/src/tests/potential/test_adhesion_potentials.cpp b/tests/src/tests/potential/test_adhesion_potentials.cpp index 552474b94..2f1821226 100644 --- a/tests/src/tests/potential/test_adhesion_potentials.cpp +++ b/tests/src/tests/potential/test_adhesion_potentials.cpp @@ -64,7 +64,7 @@ TEST_CASE("Normal adhesion potential", "[potential][adhesion]") collisions.set_use_improved_max_approximator(use_improved_max_approximator); collisions.build(mesh, vertices, dhat_a); - REQUIRE(collisions.size() > 0); + REQUIRE(!collisions.empty()); REQUIRE( collisions.compute_minimum_distance(mesh, vertices) diff --git a/tests/src/tests/potential/test_barrier_potential.cpp b/tests/src/tests/potential/test_barrier_potential.cpp index dd7f94904..24375f681 100644 --- a/tests/src/tests/potential/test_barrier_potential.cpp +++ b/tests/src/tests/potential/test_barrier_potential.cpp @@ -81,7 +81,7 @@ TEST_CASE( CAPTURE( dhat, broad_phase->name(), all_vertices_on_surface, use_area_weighting, use_improved_max_approximator); - CHECK(collisions.size() > 0); + CHECK(!collisions.empty()); BarrierPotential barrier_potential(dhat, use_physical_barrier); @@ -225,7 +225,7 @@ TEST_CASE( collisions.set_use_improved_max_approximator(use_improved_max_approximator); collisions.build(mesh, vertices, dhat); - CHECK(collisions.size() > 0); + CHECK(!collisions.empty()); BarrierPotential barrier_potential(dhat, use_physical_barrier); @@ -300,7 +300,7 @@ TEST_CASE( collisions.set_use_improved_max_approximator(use_improved_max_approximator); collisions.set_enable_shape_derivatives(true); collisions.build(candidates, mesh, vertices, dhat); - REQUIRE(collisions.ee_collisions.size() > 0); + REQUIRE(!collisions.ee_collisions.empty()); BarrierPotential barrier_potential(dhat, use_physical_barrier); @@ -501,7 +501,7 @@ TEST_CASE( collisions.set_use_improved_max_approximator(use_improved_max_approximator); collisions.build(mesh, vertices, dhat); CAPTURE(mesh_name, dhat); - CHECK(collisions.size() > 0); + CHECK(!collisions.empty()); BarrierPotential barrier_potential(dhat, use_physical_barrier);