Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 80dda64

Browse files
committed
fix format
1 parent aaf9513 commit 80dda64

File tree

10 files changed

+164
-144
lines changed

10 files changed

+164
-144
lines changed

tests/src/tests/barrier/test_eigen.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
#include <ipc/utils/AutodiffTypes.hpp>
99
#include <iostream>
1010

11-
Eigen::Matrix3i fun1() {
11+
Eigen::Matrix3i fun1()
12+
{
1213
Eigen::Matrix3i A;
13-
A << 1, 2, 3,
14-
4, 5, 6,
15-
7, 8, 9;
14+
A << 1, 2, 3, 4, 5, 6, 7, 8, 9;
1615
return A;
1716
}
1817

19-
std::tuple<int, Eigen::Matrix3i> func2() {
18+
std::tuple<int, Eigen::Matrix3i> func2()
19+
{
2020
Eigen::Matrix3i A;
21-
A << 1, 2, 3,
22-
4, 5, 6,
23-
7, 8, 9;
21+
A << 1, 2, 3, 4, 5, 6, 7, 8, 9;
2422
return std::make_tuple(0., A);
2523
}
2624

@@ -32,7 +30,7 @@ TEST_CASE("assign sub matrix", "[eigen_unit]")
3230

3331
for (int i = 0; i < 3; i++)
3432
for (int j = 0; j < 3; j++)
35-
CHECK(B(i+1, j+1) == 3 * i + j + 1);
33+
CHECK(B(i + 1, j + 1) == 3 * i + j + 1);
3634
}
3735

3836
TEST_CASE("assign sub matrix in tuple", "[eigen_unit]")
@@ -46,14 +44,15 @@ TEST_CASE("assign sub matrix in tuple", "[eigen_unit]")
4644
CHECK(b == 0);
4745
for (int i = 0; i < 3; i++)
4846
for (int j = 0; j < 3; j++)
49-
CHECK(B(i+1, j+1) == 3 * i + j + 1);
47+
CHECK(B(i + 1, j + 1) == 3 * i + j + 1);
5048
}
5149

5250
TEST_CASE("eigen map and ref", "[eigen_unit]")
5351
{
5452
Eigen::Matrix4i B;
5553
B.setZero();
56-
Eigen::Ref<Eigen::Vector<int, 12>> ref = Eigen::Map<Eigen::Vector<int, 12>>(B.data() + 4, 12);
54+
Eigen::Ref<Eigen::Vector<int, 12>> ref =
55+
Eigen::Map<Eigen::Vector<int, 12>>(B.data() + 4, 12);
5756
ref(5) = 1;
5857

5958
std::cout << "B:\n" << B << "\n";
@@ -64,7 +63,7 @@ TEST_CASE("eigen ref and seqN", "[eigen_unit]")
6463
{
6564
Eigen::Matrix4i B;
6665
B.setZero();
67-
B({1,2,3},{1,2,3}) = fun1();
66+
B({ 1, 2, 3 }, { 1, 2, 3 }) = fun1();
6867

6968
std::cout << "B:\n" << B << "\n";
7069
}

tests/src/tests/benchmark_eigen.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,33 +210,22 @@ TEST_CASE("eigen vec dynamic vs static", "[!benchmark][eigen]")
210210

211211
TEST_CASE("eigen mat dynamic vs static", "[!benchmark][eigen]")
212212
{
213-
const Eigen::Matrix<double, -1, -1, 0, -1, 3> V = Eigen::MatrixXd::Random(100, 3);
213+
const Eigen::Matrix<double, -1, -1, 0, -1, 3> V =
214+
Eigen::MatrixXd::Random(100, 3);
214215
const Eigen::Matrix3d X = Eigen::Matrix3d::Random();
215216

216217
int i = 55;
217218

218-
BENCHMARK("Static")
219-
{
220-
return X * V.middleRows(i, 3);
221-
};
219+
BENCHMARK("Static") { return X * V.middleRows(i, 3); };
222220

223-
BENCHMARK("Dynamic")
224-
{
225-
return X * V.block<3, 3>(i, 0);
226-
};
221+
BENCHMARK("Dynamic") { return X * V.block<3, 3>(i, 0); };
227222
}
228223

229224
TEST_CASE("trace vs sqr norm", "[!benchmark][eigen]")
230225
{
231226
const Eigen::Matrix3d V = Eigen::MatrixXd::Random(3, 3);
232227

233-
BENCHMARK("trace")
234-
{
235-
return (V.transpose() * V).trace();
236-
};
228+
BENCHMARK("trace") { return (V.transpose() * V).trace(); };
237229

238-
BENCHMARK("sqr_norm")
239-
{
240-
return V.squaredNorm();
241-
};
230+
BENCHMARK("sqr_norm") { return V.squaredNorm(); };
242231
}

tests/src/tests/config.hpp.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static const std::filesystem::path
1818
#endif
1919

2020
static const std::filesystem::path DATA_DIR("@IPC_TOOLKIT_TESTS_DATA_DIR@");
21-
static const std::filesystem::path GCP_DATA_DIR("@IPC_TOOLKIT_TESTS_GCP_DATA_DIR@");
21+
static const std::filesystem::path
22+
GCP_DATA_DIR("@IPC_TOOLKIT_TESTS_GCP_DATA_DIR@");
2223

2324
} // namespace ipc::tests

tests/src/tests/distance/test_edge_edge.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,13 @@ TEST_CASE(
309309
// CHECK(distance.getHessian().squaredNorm() != Catch::Approx(0.0));
310310
}
311311

312-
313-
TEST_CASE(
314-
"Edge normal term", "[distance][edge-edge][gradient]")
312+
TEST_CASE("Edge normal term", "[distance][edge-edge][gradient]")
315313
{
316314
ORIENTATION_TYPES otypes;
317315
otypes.set_size(2);
318316
const double alpha = 0.85;
319317
const double beta = 0.2;
320-
ParameterType param{1e-3, 1, 0, alpha, beta, 2};
318+
ParameterType param { 1e-3, 1, 0, alpha, beta, 2 };
321319

322320
ipc::Vector3d dn, e0, e1, f0, f1;
323321
e0 << 0, 0, 0;
@@ -328,20 +326,31 @@ TEST_CASE(
328326

329327
ipc::Vector15d x;
330328
x << dn, e0, e1, f0, f1;
331-
332-
const auto [val, grad, hess] = smooth_edge3_normal_term_hessian(dn, e0, e1, f0, f1, alpha, beta, otypes);
329+
330+
const auto [val, grad, hess] = smooth_edge3_normal_term_hessian(
331+
dn, e0, e1, f0, f1, alpha, beta, otypes);
333332

334333
Eigen::VectorXd fgrad;
335-
fd::finite_gradient(x, [&](const Eigen::VectorXd &y) {
336-
return smooth_edge3_normal_term(y.head(3), y.segment(3, 3), y.segment(6, 3), y.segment(9, 3), y.segment(12, 3), alpha, beta, otypes);
337-
}, fgrad, fd::AccuracyOrder::FOURTH, 1e-5);
334+
fd::finite_gradient(
335+
x,
336+
[&](const Eigen::VectorXd& y) {
337+
return smooth_edge3_normal_term(
338+
y.head(3), y.segment(3, 3), y.segment(6, 3), y.segment(9, 3),
339+
y.segment(12, 3), alpha, beta, otypes);
340+
},
341+
fgrad, fd::AccuracyOrder::FOURTH, 1e-5);
338342

339343
CHECK((fgrad - grad).norm() / 1e-8 <= grad.norm());
340344

341345
Eigen::MatrixXd fhess;
342-
fd::finite_jacobian(x, [&](const Eigen::VectorXd &y) {
343-
return std::get<1>(smooth_edge3_normal_term_gradient(y.head(3), y.segment(3, 3), y.segment(6, 3), y.segment(9, 3), y.segment(12, 3), alpha, beta, otypes));
344-
}, fhess, fd::AccuracyOrder::SECOND, 1e-7);
346+
fd::finite_jacobian(
347+
x,
348+
[&](const Eigen::VectorXd& y) {
349+
return std::get<1>(smooth_edge3_normal_term_gradient(
350+
y.head(3), y.segment(3, 3), y.segment(6, 3), y.segment(9, 3),
351+
y.segment(12, 3), alpha, beta, otypes));
352+
},
353+
fhess, fd::AccuracyOrder::SECOND, 1e-7);
345354

346355
CHECK((fhess - hess).norm() / 1e-6 <= hess.norm());
347356
}

tests/src/tests/distance/test_line_line.cpp

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ TEST_CASE("Line-line closest point pair", "[distance][line-line]")
2929

3030
double yb = GENERATE(take(5, random(-100.0, 100.0)));
3131
double zb = GENERATE(take(5, random(-0.5, 0.5)));
32-
Eigen::Vector3d eb0(0, yb, - 1 - zb), eb1(0, yb, 1);
32+
Eigen::Vector3d eb0(0, yb, -1 - zb), eb1(0, yb, 1);
3333

3434
double expected_distance = line_line_distance(ea0, ea1, eb0, eb1);
3535

36-
Eigen::Matrix<double, 3, 2> closest_points
37-
= line_line_closest_point_pairs<double>(ea0, ea1, eb0, eb1);
38-
double distance = (closest_points.col(0) - closest_points.col(1)).squaredNorm();
39-
36+
Eigen::Matrix<double, 3, 2> closest_points =
37+
line_line_closest_point_pairs<double>(ea0, ea1, eb0, eb1);
38+
double distance =
39+
(closest_points.col(0) - closest_points.col(1)).squaredNorm();
40+
4041
CHECK(distance == Catch::Approx(expected_distance));
4142
}
4243

@@ -94,7 +95,8 @@ TEST_CASE("Line-line distance hessian", "[distance][line-line][hessian]")
9495
CHECK(fd::compare_hessian(hess, expected_hess, 1e-2));
9596
}
9697

97-
TEST_CASE("Line-line closest direction hessian", "[distance][line-line][hessian]")
98+
TEST_CASE(
99+
"Line-line closest direction hessian", "[distance][line-line][hessian]")
98100
{
99101
double ya = GENERATE(take(2, random(-10.0, 10.0)));
100102
Eigen::Vector3d ea0(-1, ya, 0), ea1(1, ya, 0);
@@ -104,16 +106,21 @@ TEST_CASE("Line-line closest direction hessian", "[distance][line-line][hessian]
104106

105107
using T = ADHessian<12>;
106108
DiffScalarBase::setVariableCount(12);
107-
const auto x = slice_positions<T, 4, 3>((Vector12d() << ea0, ea1, eb0, eb1).finished());
108-
BENCHMARK("AutoDiff Hessian") {
109-
line_line_closest_point_direction<T>(x.row(0), x.row(1), x.row(2), x.row(3));
109+
const auto x = slice_positions<T, 4, 3>(
110+
(Vector12d() << ea0, ea1, eb0, eb1).finished());
111+
BENCHMARK("AutoDiff Hessian")
112+
{
113+
line_line_closest_point_direction<T>(
114+
x.row(0), x.row(1), x.row(2), x.row(3));
110115
};
111-
BENCHMARK("Hessian") {
116+
BENCHMARK("Hessian")
117+
{
112118
line_line_closest_point_direction_hessian(ea0, ea1, eb0, eb1);
113119
};
114120
}
115121

116-
TEST_CASE("Line-line closest point pairs gradient", "[distance][line-line][gradient]")
122+
TEST_CASE(
123+
"Line-line closest point pairs gradient", "[distance][line-line][gradient]")
117124
{
118125
double ya = GENERATE(take(10, random(-10.0, 10.0)));
119126
Eigen::Vector3d ea0(-1, ya, 0), ea1(1, ya, 0);
@@ -123,24 +130,29 @@ TEST_CASE("Line-line closest point pairs gradient", "[distance][line-line][gradi
123130

124131
using T = ADGrad<12>;
125132
DiffScalarBase::setVariableCount(12);
126-
const auto x = slice_positions<T, 4, 3>((Vector12d() << ea0, ea1, eb0, eb1).finished());
127-
auto yAD = line_line_closest_point_pairs<T>(x.row(0), x.row(1), x.row(2), x.row(3));
133+
const auto x = slice_positions<T, 4, 3>(
134+
(Vector12d() << ea0, ea1, eb0, eb1).finished());
135+
auto yAD = line_line_closest_point_pairs<T>(
136+
x.row(0), x.row(1), x.row(2), x.row(3));
128137
auto [y, grad] = line_line_closest_point_pairs_gradient(ea0, ea1, eb0, eb1);
129-
for (int i = 0; i < yAD.size(); i++)
130-
{
138+
for (int i = 0; i < yAD.size(); i++) {
131139
REQUIRE((yAD(i).getValue() - y(i)) < 1e-8);
132-
REQUIRE((yAD(i).getGradient() - grad.row(i).transpose()).norm() < 1e-6 * grad.row(i).norm());
140+
REQUIRE(
141+
(yAD(i).getGradient() - grad.row(i).transpose()).norm()
142+
< 1e-6 * grad.row(i).norm());
133143
}
134144

135145
// BENCHMARK("AutoDiff Gradient") {
136-
// line_line_closest_point_pairs<T>(x.row(0), x.row(1), x.row(2), x.row(3));
146+
// line_line_closest_point_pairs<T>(x.row(0), x.row(1), x.row(2),
147+
// x.row(3));
137148
// };
138149
// BENCHMARK("Gradient") {
139150
// line_line_closest_point_pairs_gradient(ea0, ea1, eb0, eb1);
140151
// };
141152
}
142153

143-
TEST_CASE("Line-line closest point pairs hessian", "[distance][line-line][hessian]")
154+
TEST_CASE(
155+
"Line-line closest point pairs hessian", "[distance][line-line][hessian]")
144156
{
145157
double ya = GENERATE(take(10, random(-10.0, 10.0)));
146158
Eigen::Vector3d ea0(-1, ya, 0.05), ea1(1, ya, 0);
@@ -150,18 +162,23 @@ TEST_CASE("Line-line closest point pairs hessian", "[distance][line-line][hessia
150162

151163
using T = ADHessian<12>;
152164
DiffScalarBase::setVariableCount(12);
153-
const auto x = slice_positions<T, 4, 3>((Vector12d() << ea0, ea1, eb0, eb1).finished());
154-
auto yAD = line_line_closest_point_pairs<T>(x.row(0), x.row(1), x.row(2), x.row(3));
155-
auto [y, grad, hess] = line_line_closest_point_pairs_hessian(ea0, ea1, eb0, eb1);
156-
for (int i = 0; i < yAD.size(); i++)
157-
{
165+
const auto x = slice_positions<T, 4, 3>(
166+
(Vector12d() << ea0, ea1, eb0, eb1).finished());
167+
auto yAD = line_line_closest_point_pairs<T>(
168+
x.row(0), x.row(1), x.row(2), x.row(3));
169+
auto [y, grad, hess] =
170+
line_line_closest_point_pairs_hessian(ea0, ea1, eb0, eb1);
171+
for (int i = 0; i < yAD.size(); i++) {
158172
REQUIRE((yAD(i).getValue() - y(i)) < 1e-8);
159-
REQUIRE((yAD(i).getGradient() - grad.row(i).transpose()).norm() < 1e-8 * grad.row(i).norm());
173+
REQUIRE(
174+
(yAD(i).getGradient() - grad.row(i).transpose()).norm()
175+
< 1e-8 * grad.row(i).norm());
160176
REQUIRE((yAD(i).getHessian() - hess[i]).norm() < 1e-8 * hess[i].norm());
161177
}
162178

163179
// BENCHMARK("AutoDiff Hessian") {
164-
// line_line_closest_point_pairs<T>(x.row(0), x.row(1), x.row(2), x.row(3));
180+
// line_line_closest_point_pairs<T>(x.row(0), x.row(1), x.row(2),
181+
// x.row(3));
165182
// };
166183
// BENCHMARK("Hessian") {
167184
// line_line_closest_point_pairs_hessian(ea0, ea1, eb0, eb1);

tests/src/tests/distance/test_point_line.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ TEST_CASE(
158158
CHECK(fd::compare_hessian(hess, fhess, 1e-2));
159159
}
160160

161-
TEST_CASE("Point-line closest point pairs hessian", "[distance][point-line][hessian]")
161+
TEST_CASE(
162+
"Point-line closest point pairs hessian", "[distance][point-line][hessian]")
162163
{
163164
double ya = GENERATE(take(2, random(-10.0, 10.0)));
164165
Eigen::Vector3d p(1, ya, 0);
@@ -168,20 +169,28 @@ TEST_CASE("Point-line closest point pairs hessian", "[distance][point-line][hess
168169

169170
using T = ADHessian<9>;
170171
DiffScalarBase::setVariableCount(9);
171-
const auto x = slice_positions<T, 3, 3>((Vector9d() << p, eb0, eb1).finished());
172-
auto yAD = PointEdgeDistance<T, 3>::point_line_closest_point_direction(x.row(0), x.row(1), x.row(2));
173-
auto [y, grad, hess] = PointEdgeDistanceDerivatives<3>::point_line_closest_point_direction_hessian(p, eb0, eb1);
174-
for (int i = 0; i < yAD.size(); i++)
175-
{
172+
const auto x =
173+
slice_positions<T, 3, 3>((Vector9d() << p, eb0, eb1).finished());
174+
auto yAD = PointEdgeDistance<T, 3>::point_line_closest_point_direction(
175+
x.row(0), x.row(1), x.row(2));
176+
auto [y, grad, hess] = PointEdgeDistanceDerivatives<
177+
3>::point_line_closest_point_direction_hessian(p, eb0, eb1);
178+
for (int i = 0; i < yAD.size(); i++) {
176179
REQUIRE((yAD(i).getValue() - y(i)) < 1e-8);
177-
REQUIRE((yAD(i).getGradient() - grad.row(i).transpose()).norm() < 1e-8 * grad.row(i).norm());
180+
REQUIRE(
181+
(yAD(i).getGradient() - grad.row(i).transpose()).norm()
182+
< 1e-8 * grad.row(i).norm());
178183
REQUIRE((yAD(i).getHessian() - hess[i]).norm() < 1e-8 * hess[i].norm());
179184
}
180185

181-
BENCHMARK("AutoDiff Hessian") {
182-
PointEdgeDistance<T, 3>::point_line_closest_point_direction(x.row(0), x.row(1), x.row(2));
186+
BENCHMARK("AutoDiff Hessian")
187+
{
188+
PointEdgeDistance<T, 3>::point_line_closest_point_direction(
189+
x.row(0), x.row(1), x.row(2));
183190
};
184-
BENCHMARK("Hessian") {
185-
PointEdgeDistanceDerivatives<3>::point_line_closest_point_direction_hessian(p, eb0, eb1);
191+
BENCHMARK("Hessian")
192+
{
193+
PointEdgeDistanceDerivatives<
194+
3>::point_line_closest_point_direction_hessian(p, eb0, eb1);
186195
};
187196
}

tests/src/tests/distance/test_point_triangle.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ TEST_CASE("Point-triangle distance hessian", "[distance][point-triangle][hess]")
268268
CHECK(fd::compare_hessian(hess, fhess, 1e-2));
269269
}
270270

271-
TEST_CASE("Point-triangle closest direction gradient", "[distance][point-triangle][grad]")
271+
TEST_CASE(
272+
"Point-triangle closest direction gradient",
273+
"[distance][point-triangle][grad]")
272274
{
273275
double py = GENERATE(-10, -1, -1e-5, 0, 1e-5, 1, 10);
274276
Eigen::Vector3d p(0, py, 0);
@@ -338,29 +340,31 @@ TEST_CASE("Point-triangle closest direction gradient", "[distance][point-triangl
338340
Vector12d x;
339341
x << p, t0, t1, t2;
340342

341-
const auto [vec, grad, hess] = point_triangle_closest_point_direction_hessian(p, t0, t1, t2, dtype);
343+
const auto [vec, grad, hess] =
344+
point_triangle_closest_point_direction_hessian(p, t0, t1, t2, dtype);
342345

343346
// Compute the gradient using finite differences
344347
Eigen::MatrixXd fjac;
345348
fd::finite_jacobian(
346349
x,
347350
[dtype](const Eigen::VectorXd& _x) {
348351
return point_triangle_closest_point_direction<double>(
349-
_x.segment<3>(0), _x.segment<3>(3), _x.segment<3>(6), _x.segment<3>(9), dtype);
352+
_x.segment<3>(0), _x.segment<3>(3), _x.segment<3>(6),
353+
_x.segment<3>(9), dtype);
350354
},
351355
fjac);
352-
356+
353357
std::array<Eigen::MatrixXd, 3> grad_fjac;
354-
for (int i = 0; i < 3; i++)
355-
{
358+
for (int i = 0; i < 3; i++) {
356359
fd::finite_hessian(
357360
x,
358361
[dtype, i](const Eigen::VectorXd& _x) {
359362
return point_triangle_closest_point_direction<double>(
360-
_x.segment<3>(0), _x.segment<3>(3), _x.segment<3>(6), _x.segment<3>(9), dtype)(i);
363+
_x.segment<3>(0), _x.segment<3>(3), _x.segment<3>(6),
364+
_x.segment<3>(9), dtype)(i);
361365
},
362366
grad_fjac[i]);
363-
367+
364368
CHECK(fd::compare_jacobian(grad_fjac[i], hess[i], 1e-5));
365369
}
366370

0 commit comments

Comments
 (0)