Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions .github/workflows/clang-tidy-check.yml
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 1 addition & 1 deletion python/src/broad_phase/spatial_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions python/src/candidates/candidates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void define_candidates(py::module_& m)
"build",
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
const double, std::shared_ptr<BroadPhase>>(&Candidates::build),
const double, const std::shared_ptr<BroadPhase>&>(
&Candidates::build),
R"ipc_Qu8mg5v7(
Initialize the set of discrete collision detection candidates.

Expand All @@ -29,7 +30,7 @@ void define_candidates(py::module_& m)
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
Eigen::ConstRef<Eigen::MatrixXd>, const double,
std::shared_ptr<BroadPhase>>(&Candidates::build),
const std::shared_ptr<BroadPhase>&>(&Candidates::build),
R"ipc_Qu8mg5v7(
Initialize the set of continuous collision detection candidates.

Expand Down
2 changes: 1 addition & 1 deletion python/src/collisions/normal/normal_collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void define_normal_collisions(py::module_& m)
"build",
py::overload_cast<
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
const double, const double, std::shared_ptr<BroadPhase>>(
const double, const double, const std::shared_ptr<BroadPhase>&>(
&NormalCollisions::build),
R"ipc_Qu8mg5v7(
Initialize the set of collisions used to compute the barrier potential.
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/broad_phase/aabb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AABB {
/// @brief Maximum corner of the AABB.
ArrayMax3d max;
/// @brief Vertex IDs attached to the AABB.
std::array<index_t, 3> vertex_ids;
std::array<index_t, 3> vertex_ids = { { -1, -1, -1 } };
};

/// @brief Build one AABB per vertex position (row of V).
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/broad_phase/broad_phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void BroadPhase::build(
Eigen::ConstRef<Eigen::MatrixXi> edges,
Eigen::ConstRef<Eigen::MatrixXi> 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);
Expand Down
6 changes: 5 additions & 1 deletion src/ipc/broad_phase/broad_phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AABB> vertex_boxes;
std::vector<AABB> edge_boxes;
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/broad_phase/brute_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void BruteForce::detect_candidates(
tbb::enumerable_thread_specific<std::vector<Candidate>> storage;

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

Expand Down
14 changes: 7 additions & 7 deletions src/ipc/broad_phase/bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void BVH::build(

void BVH::init_bvh(const std::vector<AABB>& boxes, SimpleBVH::BVH& bvh)
{
if (boxes.size() == 0) {
if (boxes.empty()) {
return;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ void BVH::detect_candidates(
void BVH::detect_vertex_vertex_candidates(
std::vector<VertexVertexCandidate>& candidates) const
{
if (vertex_boxes.size() == 0) {
if (vertex_boxes.empty()) {
return;
}

Expand All @@ -113,7 +113,7 @@ void BVH::detect_vertex_vertex_candidates(
void BVH::detect_edge_vertex_candidates(
std::vector<EdgeVertexCandidate>& candidates) const
{
if (edge_boxes.size() == 0 || vertex_boxes.size() == 0) {
if (edge_boxes.empty() || vertex_boxes.empty()) {
return;
}

Expand All @@ -127,7 +127,7 @@ void BVH::detect_edge_vertex_candidates(
void BVH::detect_edge_edge_candidates(
std::vector<EdgeEdgeCandidate>& candidates) const
{
if (edge_boxes.size() == 0) {
if (edge_boxes.empty()) {
return;
}

Expand All @@ -140,7 +140,7 @@ void BVH::detect_edge_edge_candidates(
void BVH::detect_face_vertex_candidates(
std::vector<FaceVertexCandidate>& candidates) const
{
if (face_boxes.size() == 0 || vertex_boxes.size() == 0) {
if (face_boxes.empty() || vertex_boxes.empty()) {
return;
}

Expand All @@ -153,7 +153,7 @@ void BVH::detect_face_vertex_candidates(
void BVH::detect_edge_face_candidates(
std::vector<EdgeFaceCandidate>& candidates) const
{
if (edge_boxes.size() == 0 || face_boxes.size() == 0) {
if (edge_boxes.empty() || face_boxes.empty()) {
return;
}

Expand All @@ -166,7 +166,7 @@ void BVH::detect_edge_face_candidates(
void BVH::detect_face_face_candidates(
std::vector<FaceFaceCandidate>& candidates) const
{
if (face_boxes.size() == 0) {
if (face_boxes.empty()) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/ipc/broad_phase/hash_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void HashGrid::insert_boxes(
tbb::enumerable_thread_specific<std::vector<HashItem>> storage;

tbb::parallel_for(
tbb::blocked_range<long>(0l, long(boxes.size())),
tbb::blocked_range<long>(0L, long(boxes.size())),
[&](const tbb::blocked_range<long>& range) {
auto& local_items = storage.local();
for (long i = range.begin(); i != range.end(); i++) {
Expand Down Expand Up @@ -158,7 +158,7 @@ void HashGrid::detect_candidates(
#endif

tbb::parallel_for(
tbb::blocked_range2d<long>(0l, num_items - 1, 0l, num_items),
tbb::blocked_range2d<long>(0L, num_items - 1, 0L, num_items),
[&](const tbb::blocked_range2d<long>& r) {
auto& local_candidates = storage.local();

Expand Down Expand Up @@ -237,7 +237,7 @@ void HashGrid::detect_candidates(
#endif

tbb::parallel_for(
tbb::blocked_range2d<long>(0l, items.size() - 1, 0l, items.size()),
tbb::blocked_range2d<long>(0L, items.size() - 1, 0L, items.size()),
[&](const tbb::blocked_range2d<long>& r) {
auto& local_candidates = storage.local();

Expand Down
4 changes: 2 additions & 2 deletions src/ipc/broad_phase/hash_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class HashGrid : public BroadPhase {
const AABB& aabb, const long id, std::vector<HashItem>& 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(
Expand Down Expand Up @@ -143,7 +143,7 @@ class HashGrid : public BroadPhase {
std::vector<Candidate>& candidates) const;

protected:
double m_cell_size;
double m_cell_size = -1;
ArrayMax3i m_grid_size;
ArrayMax3d m_domain_min;
ArrayMax3d m_domain_max;
Expand Down
20 changes: 10 additions & 10 deletions src/ipc/broad_phase/spatial_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>();
voxel_count = (range * one_div_voxel_size).ceil().template cast<int>();
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];
Expand Down Expand Up @@ -342,7 +342,7 @@ void SpatialHash::detect_candidates(
void SpatialHash::detect_vertex_vertex_candidates(
std::vector<VertexVertexCandidate>& candidates) const
{
if (vertex_boxes.size() == 0) {
if (vertex_boxes.empty()) {
return;
}

Expand All @@ -355,7 +355,7 @@ void SpatialHash::detect_vertex_vertex_candidates(
void SpatialHash::detect_edge_vertex_candidates(
std::vector<EdgeVertexCandidate>& candidates) const
{
if (edge_boxes.size() == 0 || vertex_boxes.size() == 0) {
if (edge_boxes.empty() || vertex_boxes.empty()) {
return;
}

Expand All @@ -369,7 +369,7 @@ void SpatialHash::detect_edge_vertex_candidates(
void SpatialHash::detect_edge_edge_candidates(
std::vector<EdgeEdgeCandidate>& candidates) const
{
if (edge_boxes.size() == 0) {
if (edge_boxes.empty()) {
return;
}

Expand All @@ -381,7 +381,7 @@ void SpatialHash::detect_edge_edge_candidates(
void SpatialHash::detect_face_vertex_candidates(
std::vector<FaceVertexCandidate>& candidates) const
{
if (face_boxes.size() == 0 || vertex_boxes.size() == 0) {
if (face_boxes.empty() || vertex_boxes.empty()) {
return;
}

Expand All @@ -396,7 +396,7 @@ void SpatialHash::detect_face_vertex_candidates(
void SpatialHash::detect_edge_face_candidates(
std::vector<EdgeFaceCandidate>& candidates) const
{
if (edge_boxes.size() == 0 || face_boxes.size() == 0) {
if (edge_boxes.empty() || face_boxes.empty()) {
return;
}

Expand All @@ -410,7 +410,7 @@ void SpatialHash::detect_edge_face_candidates(
void SpatialHash::detect_face_face_candidates(
std::vector<FaceFaceCandidate>& candidates) const
{
if (face_boxes.size() == 0) {
if (face_boxes.empty()) {
return;
}

Expand All @@ -430,7 +430,7 @@ int SpatialHash::locate_voxel_index(Eigen::ConstRef<VectorMax3d> p) const
ArrayMax3i
SpatialHash::locate_voxel_axis_index(Eigen::ConstRef<VectorMax3d> p) const
{
return ((p.array() - left_bottom_corner) * one_div_voxelSize)
return ((p.array() - left_bottom_corner) * one_div_voxel_size)
.floor()
.template cast<int>();
}
Expand Down
Loading