Skip to content

Commit fc15b8e

Browse files
authored
Add Clang Tidy Check (#193)
- Add clang-tidy file and check - Removed unnecessary inline specifiers for member functions in spatial_hash.hpp. - Initialized member variables in spatial_hash.hpp to default values. - Updated assertions to check for emptiness instead of size in various locations. - Changed shared pointer parameters to use const references for efficiency. - Simplified conditional checks and improved readability in multiple files. - Replaced manual checks for negative values with std::max in collision_mesh.cpp. - Enhanced clarity in comments and function signatures across several files. - Updated distance type enums to use uint8_t for better memory efficiency. - Improved consistency in function parameter naming and usage. - Cleaned up unused parameters and improved function documentation.
1 parent 764f6d0 commit fc15b8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+263
-168
lines changed

.clang-tidy

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Checks: >
2+
-*,
3+
4+
# Standard C++ Guidelines (Modernization, Idioms)
5+
modernize-*,
6+
performance-*,
7+
readability-*,
8+
9+
# Bug Detection and Safety
10+
bugprone-*,
11+
12+
# Specific high-value checks (even if not in a group above)
13+
google-runtime-int,
14+
cppcoreguidelines-pro-type-member-init,
15+
16+
# Exclusions/Suppressions (Checks often considered too aggressive or subjective)
17+
-bugprone-throwing-static-initialization,
18+
-cppcoreguidelines-owning-memory,
19+
-modernize-use-trailing-return-type,
20+
-readability-avoid-const-params-in-decls,
21+
-readability-avoid-nested-conditional-operator,
22+
-readability-container-contains,
23+
-readability-else-after-return,
24+
-readability-function-cognitive-complexity,
25+
-readability-identifier-length,
26+
-readability-implicit-bool-conversion,
27+
-readability-isolate-declaration,
28+
-readability-magic-numbers,
29+
-readability-math-missing-parentheses,
30+
-readability-redundant-access-specifiers
31+
32+
WarningsAsErrors: '*'
33+
HeaderFilterRegex: '.*(ipc/).*'
34+
UseColor: true
35+
FormatStyle: file
36+
ExtraArgs:
37+
- '-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'
38+
CheckOptions:
39+
readability-identifier-naming.ClassCase: CamelCase
40+
readability-identifier-naming.ConstantParameterCase: lower_case
41+
readability-identifier-naming.ConstantParameterIgnoredRegexp: '^(_.*)$'
42+
readability-identifier-naming.FunctionCase: lower_case
43+
readability-identifier-naming.FunctionIgnoredRegexp: '^(AbslHashValue|.*[123][Ddf].*)$'
44+
readability-identifier-naming.GlobalConstantCase: UPPER_CASE
45+
readability-identifier-naming.MemberCase: lower_case
46+
readability-identifier-naming.MemberIgnoredRegexp: '^([A-Z])$'
47+
readability-identifier-naming.MethodCase: lower_case
48+
readability-identifier-naming.MethodIgnoredRegexp: '^(.*[123][Ddf].*)$'
49+
readability-identifier-naming.ParameterIgnoredRegexp: '^(_.*)$'
50+
readability-identifier-naming.StructCase: CamelCase
51+
readability-identifier-naming.VariableCase: aNy_CasE
52+
readability-identifier-naming.VariableIgnoredRegexp: '^(_.*)$'
53+
readability-identifier-naming.EnumCase: CamelCase
54+
readability-identifier-naming.EnumConstantCase: UPPER_CASE
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Clang-Tidy Check
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
paths:
8+
- '.github/workflows/clang-tidy-check.yml'
9+
- '.clang-tidy'
10+
- 'src/**'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
15+
16+
jobs:
17+
clang-tidy:
18+
name: Run Clang-Tidy
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Install dependencies
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y clang-tidy cmake build-essential
29+
30+
- name: Get number of CPU cores
31+
uses: SimenB/[email protected]
32+
id: cpu-cores
33+
34+
- name: Configure CMake
35+
run: |
36+
mkdir -p build
37+
cd build
38+
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
39+
40+
- name: Run Clang-Tidy
41+
run: |
42+
run-clang-tidy -quiet -j ${{ steps.cpu-cores.outputs.count }} -p build $(find src -name '*.cpp')

python/src/broad_phase/spatial_hash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void define_spatial_hash(py::module_& m)
6969
"voxel_count", &SpatialHash::voxel_count,
7070
"The number of voxels in each dimension.")
7171
.def_readwrite(
72-
"one_div_voxelSize", &SpatialHash::one_div_voxelSize,
72+
"one_div_voxel_size", &SpatialHash::one_div_voxel_size,
7373
"1.0 / voxel_size")
7474
.def_readwrite(
7575
"voxel_count_0x1", &SpatialHash::voxel_count_0x1,

python/src/candidates/candidates.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void define_candidates(py::module_& m)
1212
"build",
1313
py::overload_cast<
1414
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
15-
const double, std::shared_ptr<BroadPhase>>(&Candidates::build),
15+
const double, const std::shared_ptr<BroadPhase>&>(
16+
&Candidates::build),
1617
R"ipc_Qu8mg5v7(
1718
Initialize the set of discrete collision detection candidates.
1819
@@ -29,7 +30,7 @@ void define_candidates(py::module_& m)
2930
py::overload_cast<
3031
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
3132
Eigen::ConstRef<Eigen::MatrixXd>, const double,
32-
std::shared_ptr<BroadPhase>>(&Candidates::build),
33+
const std::shared_ptr<BroadPhase>&>(&Candidates::build),
3334
R"ipc_Qu8mg5v7(
3435
Initialize the set of continuous collision detection candidates.
3536

python/src/collisions/normal/normal_collisions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void define_normal_collisions(py::module_& m)
1212
"build",
1313
py::overload_cast<
1414
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
15-
const double, const double, std::shared_ptr<BroadPhase>>(
15+
const double, const double, const std::shared_ptr<BroadPhase>&>(
1616
&NormalCollisions::build),
1717
R"ipc_Qu8mg5v7(
1818
Initialize the set of collisions used to compute the barrier potential.

src/ipc/broad_phase/aabb.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AABB {
6565
/// @brief Maximum corner of the AABB.
6666
ArrayMax3d max;
6767
/// @brief Vertex IDs attached to the AABB.
68-
std::array<index_t, 3> vertex_ids;
68+
std::array<index_t, 3> vertex_ids = { { -1, -1, -1 } };
6969
};
7070

7171
/// @brief Build one AABB per vertex position (row of V).

src/ipc/broad_phase/broad_phase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void BroadPhase::build(
4646
Eigen::ConstRef<Eigen::MatrixXi> edges,
4747
Eigen::ConstRef<Eigen::MatrixXi> faces)
4848
{
49-
assert(vertex_boxes.size() > 0);
49+
assert(!vertex_boxes.empty());
5050
assert(edges.size() == 0 || edges.cols() == 2);
5151
assert(faces.size() == 0 || faces.cols() == 3);
5252
build_edge_boxes(vertex_boxes, edges, edge_boxes);

src/ipc/broad_phase/broad_phase.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ class BroadPhase {
114114
virtual bool can_edge_face_collide(size_t ei, size_t fi) const;
115115
virtual bool can_faces_collide(size_t fai, size_t fbi) const;
116116

117-
static bool default_can_vertices_collide(size_t, size_t) { return true; }
117+
static bool
118+
default_can_vertices_collide(size_t /*unused*/, size_t /*unused*/)
119+
{
120+
return true;
121+
}
118122

119123
std::vector<AABB> vertex_boxes;
120124
std::vector<AABB> edge_boxes;

src/ipc/broad_phase/brute_force.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void BruteForce::detect_candidates(
2222
tbb::enumerable_thread_specific<std::vector<Candidate>> storage;
2323

2424
tbb::parallel_for(
25-
tbb::blocked_range2d<size_t>(0ul, boxes0.size(), 0ul, boxes1.size()),
25+
tbb::blocked_range2d<size_t>(0UL, boxes0.size(), 0UL, boxes1.size()),
2626
[&](const tbb::blocked_range2d<size_t>& r) {
2727
auto& local_candidates = storage.local();
2828

src/ipc/broad_phase/bvh.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void BVH::build(
3333

3434
void BVH::init_bvh(const std::vector<AABB>& boxes, SimpleBVH::BVH& bvh)
3535
{
36-
if (boxes.size() == 0) {
36+
if (boxes.empty()) {
3737
return;
3838
}
3939

@@ -101,7 +101,7 @@ void BVH::detect_candidates(
101101
void BVH::detect_vertex_vertex_candidates(
102102
std::vector<VertexVertexCandidate>& candidates) const
103103
{
104-
if (vertex_boxes.size() == 0) {
104+
if (vertex_boxes.empty()) {
105105
return;
106106
}
107107

@@ -113,7 +113,7 @@ void BVH::detect_vertex_vertex_candidates(
113113
void BVH::detect_edge_vertex_candidates(
114114
std::vector<EdgeVertexCandidate>& candidates) const
115115
{
116-
if (edge_boxes.size() == 0 || vertex_boxes.size() == 0) {
116+
if (edge_boxes.empty() || vertex_boxes.empty()) {
117117
return;
118118
}
119119

@@ -127,7 +127,7 @@ void BVH::detect_edge_vertex_candidates(
127127
void BVH::detect_edge_edge_candidates(
128128
std::vector<EdgeEdgeCandidate>& candidates) const
129129
{
130-
if (edge_boxes.size() == 0) {
130+
if (edge_boxes.empty()) {
131131
return;
132132
}
133133

@@ -140,7 +140,7 @@ void BVH::detect_edge_edge_candidates(
140140
void BVH::detect_face_vertex_candidates(
141141
std::vector<FaceVertexCandidate>& candidates) const
142142
{
143-
if (face_boxes.size() == 0 || vertex_boxes.size() == 0) {
143+
if (face_boxes.empty() || vertex_boxes.empty()) {
144144
return;
145145
}
146146

@@ -153,7 +153,7 @@ void BVH::detect_face_vertex_candidates(
153153
void BVH::detect_edge_face_candidates(
154154
std::vector<EdgeFaceCandidate>& candidates) const
155155
{
156-
if (edge_boxes.size() == 0 || face_boxes.size() == 0) {
156+
if (edge_boxes.empty() || face_boxes.empty()) {
157157
return;
158158
}
159159

@@ -166,7 +166,7 @@ void BVH::detect_edge_face_candidates(
166166
void BVH::detect_face_face_candidates(
167167
std::vector<FaceFaceCandidate>& candidates) const
168168
{
169-
if (face_boxes.size() == 0) {
169+
if (face_boxes.empty()) {
170170
return;
171171
}
172172

0 commit comments

Comments
 (0)