Skip to content

Commit 5b8b06f

Browse files
committed
Added more bugprone-* clang-tidy checks
1 parent 53f7b99 commit 5b8b06f

27 files changed

+171
-167
lines changed

.clang-tidy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
---
22
Checks: >
33
-*,
4+
bugprone-assert-side-effect,
45
bugprone-copy-constructor-init,
6+
bugprone-dangling-handle,
7+
bugprone-forward-declaration-namespace,
8+
bugprone-inaccurate-erase,
59
bugprone-macro-parentheses,
610
bugprone-unhandled-self-assignment,
711
bugprone-unused-raii,

examples/surface/example_nurbs_fitting_closed_curve.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ VisualizeCurve (ON_NurbsCurve &curve, double r, double g, double b, bool show_cp
4343
curve.GetCV (i, cp);
4444

4545
pcl::PointXYZ p;
46-
p.x = float (cp.x);
47-
p.y = float (cp.y);
48-
p.z = float (cp.z);
46+
p.x = static_cast<float>(cp.x);
47+
p.y = static_cast<float>(cp.y);
48+
p.z = static_cast<float>(cp.z);
4949
cps->push_back (p);
5050
}
5151
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler (cps, 255 * r, 255 * g, 255 * b);

examples/surface/example_nurbs_fitting_closed_curve3d.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ VisualizeCurve (ON_NurbsCurve &curve, double r, double g, double b, bool show_cp
4141
curve.GetCV (i, cp);
4242

4343
pcl::PointXYZ p;
44-
p.x = float (cp.x);
45-
p.y = float (cp.y);
46-
p.z = float (cp.z);
44+
p.x = static_cast<float>(cp.x);
45+
p.y = static_cast<float>(cp.y);
46+
p.z = static_cast<float>(cp.z);
4747
cps->push_back (p);
4848
}
4949
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler (cps, 255 * r, 255 * g, 255 * b);

examples/surface/example_nurbs_fitting_curve2d.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ VisualizeCurve (ON_NurbsCurve &curve, double r, double g, double b, bool show_cp
4141
curve.GetCV (i, cp);
4242

4343
pcl::PointXYZ p;
44-
p.x = float (cp.x);
45-
p.y = float (cp.y);
46-
p.z = float (cp.z);
44+
p.x = static_cast<float>(cp.x);
45+
p.y = static_cast<float>(cp.y);
46+
p.z = static_cast<float>(cp.z);
4747
cps->push_back (p);
4848
}
4949
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler (cps, 255 * r, 255 * g, 255 * b);

examples/surface/example_nurbs_fitting_surface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ visualizeCurve (ON_NurbsCurve &curve, ON_NurbsSurface &surface, pcl::visualizati
202202
double pnt[3];
203203
surface.Evaluate (p1.x, p1.y, 0, 3, pnt);
204204
pcl::PointXYZRGB p2;
205-
p2.x = float (pnt[0]);
206-
p2.y = float (pnt[1]);
207-
p2.z = float (pnt[2]);
205+
p2.x = static_cast<float>(pnt[0]);
206+
p2.y = static_cast<float>(pnt[1]);
207+
p2.z = static_cast<float>(pnt[2]);
208208

209209
p2.r = 255;
210210
p2.g = 0;

examples/surface/example_nurbs_viewer_surface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ main (int argc, char *argv[])
4848
return -1;
4949
}
5050

51-
const ON_NurbsSurface& on_surf = *(ON_NurbsSurface*)on_object;
51+
const ON_NurbsSurface& on_surf = *dynamic_cast<const ON_NurbsSurface*>(on_object);
5252

5353
pcl::PolygonMesh mesh;
5454
std::string mesh_id = "mesh_nurbs";
@@ -68,7 +68,7 @@ main (int argc, char *argv[])
6868
return -1;
6969
}
7070

71-
const ON_NurbsCurve& on_curv = *(ON_NurbsCurve*)on_object;
71+
const ON_NurbsCurve& on_curv = *dynamic_cast<const ON_NurbsCurve*>(on_object);
7272

7373
pcl::on_nurbs::Triangulation::convertTrimmedSurface2PolygonMesh (on_surf, on_curv, mesh,
7474
mesh_resolution);

examples/surface/test_nurbs_fitting_surface.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ CreateCylinderPoints (pcl::PointCloud<Point>::Ptr cloud, pcl::on_nurbs::vector_v
1212
{
1313
for (unsigned i = 0; i < npoints; i++)
1414
{
15-
double da = alpha * double (rand ()) / RAND_MAX;
16-
double dh = h * (double (rand ()) / RAND_MAX - 0.5);
15+
double da = alpha * static_cast<double>(rand ()) / RAND_MAX;
16+
double dh = h * (static_cast<double>(rand ()) / RAND_MAX - 0.5);
1717

1818
Point p;
19-
p.x = float (r * std::cos (da));
20-
p.y = float (r * sin (da));
21-
p.z = float (dh);
19+
p.x = static_cast<float>(r * std::cos (da));
20+
p.y = static_cast<float>(r * sin (da));
21+
p.z = static_cast<float>(dh);
2222

23-
data.push_back (Eigen::Vector3d (p.x, p.y, p.z));
23+
data.emplace_back(p.x, p.y, p.z);
2424
cloud->push_back (p);
2525
}
2626
}

surface/src/on_nurbs/closing_boundary.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ ClosingBoundary::sampleUniform (ON_NurbsSurface *nurbs, vector_vec3d &point_list
243243
{
244244
params (0) = minU + (maxU - minU) * ds * i;
245245
nurbs->Evaluate (params (0), params (1), 0, 3, points);
246-
point_list.push_back (Eigen::Vector3d (points[0], points[1], points[2]));
246+
point_list.emplace_back(points[0], points[1], points[2]);
247247
}
248248
}
249249
}
@@ -262,10 +262,10 @@ ClosingBoundary::sampleRandom (ON_NurbsSurface *nurbs, vector_vec3d &point_list,
262262

263263
for (unsigned i = 0; i < samples; i++)
264264
{
265-
params (0) = minU + (maxU - minU) * (double (rand ()) / RAND_MAX);
266-
params (1) = minV + (maxV - minV) * (double (rand ()) / RAND_MAX);
265+
params (0) = minU + (maxU - minU) * (static_cast<double>(rand ()) / RAND_MAX);
266+
params (1) = minV + (maxV - minV) * (static_cast<double>(rand ()) / RAND_MAX);
267267
nurbs->Evaluate (params (0), params (1), 0, 3, points);
268-
point_list.push_back (Eigen::Vector3d (points[0], points[1], points[2]));
268+
point_list.emplace_back(points[0], points[1], points[2]);
269269
}
270270
}
271271

@@ -290,7 +290,7 @@ ClosingBoundary::sampleFromBoundary (ON_NurbsSurface *nurbs, vector_vec3d &point
290290
{
291291
params (1) = minV + (maxV - minV) * ds * i;
292292
nurbs->Evaluate (params (0), params (1), 0, 3, points);
293-
point_list.push_back (Eigen::Vector3d (points[0], points[1], points[2]));
293+
point_list.emplace_back(points[0], points[1], points[2]);
294294
param_list.push_back (params);
295295
}
296296

@@ -300,7 +300,7 @@ ClosingBoundary::sampleFromBoundary (ON_NurbsSurface *nurbs, vector_vec3d &point
300300
{
301301
params (1) = minV + (maxV - minV) * ds * i;
302302
nurbs->Evaluate (params (0), params (1), 0, 3, points);
303-
point_list.push_back (Eigen::Vector3d (points[0], points[1], points[2]));
303+
point_list.emplace_back(points[0], points[1], points[2]);
304304
param_list.push_back (params);
305305
}
306306

@@ -310,7 +310,7 @@ ClosingBoundary::sampleFromBoundary (ON_NurbsSurface *nurbs, vector_vec3d &point
310310
{
311311
params (0) = minU + (maxU - minU) * ds * i;
312312
nurbs->Evaluate (params (0), params (1), 0, 3, points);
313-
point_list.push_back (Eigen::Vector3d (points[0], points[1], points[2]));
313+
point_list.emplace_back(points[0], points[1], points[2]);
314314
param_list.push_back (params);
315315
}
316316

@@ -320,7 +320,7 @@ ClosingBoundary::sampleFromBoundary (ON_NurbsSurface *nurbs, vector_vec3d &point
320320
{
321321
params (0) = minU + (maxU - minU) * ds * i;
322322
nurbs->Evaluate (params (0), params (1), 0, 3, points);
323-
point_list.push_back (Eigen::Vector3d (points[0], points[1], points[2]));
323+
point_list.emplace_back(points[0], points[1], points[2]);
324324
param_list.push_back (params);
325325
}
326326
}

surface/src/on_nurbs/fitting_curve_2d.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int
7474
FittingCurve2d::findElement (double xi, const std::vector<double> &elements)
7575
{
7676
if (xi >= elements.back ())
77-
return (int (elements.size ()) - 2);
77+
return (static_cast<int>(elements.size ()) - 2);
7878

7979
for (std::size_t i = 0; i < elements.size () - 1; i++)
8080
{
@@ -120,7 +120,7 @@ FittingCurve2d::assemble (const Parameter &parameter)
120120
{
121121
int ncp = m_nurbs.m_cv_count;
122122
int nCageReg = m_nurbs.m_cv_count - 2;
123-
int nInt = int (m_data->interior.size ());
123+
int nInt = static_cast<int>(m_data->interior.size ());
124124

125125
double wInt = 1.0;
126126
if (!m_data->interior_weight.empty ())
@@ -290,7 +290,7 @@ FittingCurve2d::initNurbsPCA (int order, NurbsDataCurve2d *data, int ncps)
290290
if (ncps < order)
291291
ncps = order;
292292

293-
unsigned s = static_cast<unsigned> (data->interior.size ());
293+
auto s = static_cast<unsigned> (data->interior.size ());
294294
data->interior_param.clear ();
295295

296296
NurbsTools::pca (data->interior, mean, eigenvectors, eigenvalues);
@@ -399,7 +399,7 @@ FittingCurve2d::getElementVector (const ON_NurbsCurve &nurbs)
399399
void
400400
FittingCurve2d::assembleInterior (double wInt, double rScale, unsigned &row)
401401
{
402-
int nInt = int (m_data->interior.size ());
402+
int nInt = static_cast<int>(m_data->interior.size ());
403403
m_data->interior_error.clear ();
404404
m_data->interior_normals.clear ();
405405
m_data->interior_line_start.clear ();
@@ -413,7 +413,7 @@ FittingCurve2d::assembleInterior (double wInt, double rScale, unsigned &row)
413413
double param;
414414
Eigen::Vector2d pt, t;
415415
double error;
416-
if (p < int (m_data->interior_param.size ()))
416+
if (p < static_cast<int>(m_data->interior_param.size ()))
417417
{
418418
param = findClosestElementMidPoint (m_nurbs, pcp, m_data->interior_param[p]);
419419
param = inverseMapping (m_nurbs, pcp, param, error, pt, t, rScale, in_max_steps, in_accuracy, m_quiet);
@@ -428,7 +428,7 @@ FittingCurve2d::assembleInterior (double wInt, double rScale, unsigned &row)
428428

429429
m_data->interior_error.push_back (error);
430430

431-
if (p < int (m_data->interior_weight.size ()))
431+
if (p < static_cast<int>(m_data->interior_weight.size ()))
432432
wInt = m_data->interior_weight[p];
433433

434434
m_data->interior_line_start.push_back (pcp);

surface/src/on_nurbs/fitting_curve_2d_apdm.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int
7575
FittingCurve2dAPDM::findElement (double xi, const std::vector<double> &elements)
7676
{
7777
if (xi >= elements.back ())
78-
return (int (elements.size ()) - 2);
78+
return (static_cast<int>(elements.size ()) - 2);
7979

8080
for (std::size_t i = 0; i < elements.size () - 1; i++)
8181
{
@@ -148,8 +148,8 @@ FittingCurve2dAPDM::assemble (const Parameter &parameter)
148148
int cp_red = m_nurbs.m_order - 2;
149149
int ncp = m_nurbs.m_cv_count - 2 * cp_red;
150150
int nCageReg = m_nurbs.m_cv_count - 2 * cp_red;
151-
int nInt = int (m_data->interior.size ());
152-
int nClosestP = int (elements.size ()) * cp_res;
151+
int nInt = static_cast<int>(m_data->interior.size ());
152+
int nClosestP = static_cast<int>(elements.size ()) * cp_res;
153153

154154
double wInt = 1.0;
155155
if (!m_data->interior_weight.empty ())
@@ -330,8 +330,8 @@ FittingCurve2dAPDM::removeCPsOnLine (const ON_NurbsCurve &nurbs, double min_curv
330330
}
331331

332332
int order = nurbs.Order ();
333-
ON_NurbsCurve nurbs_opt = ON_NurbsCurve (2, false, order, int (cps.size ()) + 2 * cp_red);
334-
nurbs_opt.MakePeriodicUniformKnotVector (1.0 / (double (cps.size ())));
333+
ON_NurbsCurve nurbs_opt = ON_NurbsCurve (2, false, order, static_cast<int>(cps.size ()) + 2 * cp_red);
334+
nurbs_opt.MakePeriodicUniformKnotVector (1.0 / (static_cast<double>(cps.size ())));
335335
nurbs_opt.m_knot[cp_red] = 0.0;
336336
nurbs_opt.m_knot[nurbs_opt.m_knot_capacity - cp_red - 1] = 1.0;
337337

@@ -428,7 +428,7 @@ FittingCurve2dAPDM::addCageRegularisation (double weight, unsigned &row, const s
428428
{
429429
int i = j % ncp;
430430

431-
if (i >= int (m_data->closest_points_error.size () - 1))
431+
if (i >= static_cast<int>(m_data->closest_points_error.size () - 1))
432432
{
433433
printf ("[FittingCurve2dAPDM::addCageRegularisation] Warning, index for closest_points_error out of bounds\n");
434434
m_solver.f (row, 0, 0.0);
@@ -512,15 +512,15 @@ FittingCurve2dAPDM::initCPsNurbsCurve2D (int order, const vector_vec2d &cps)
512512
return nurbs;
513513
}
514514

515-
int ncps = int (cps.size ()) + 2 * cp_red; // +2*cp_red for smoothness and +1 for closing
515+
int ncps = static_cast<int>(cps.size ()) + 2 * cp_red; // +2*cp_red for smoothness and +1 for closing
516516
nurbs = ON_NurbsCurve (2, false, order, ncps);
517517
nurbs.MakePeriodicUniformKnotVector (1.0 / (ncps - order + 1));
518518

519519
for (std::size_t j = 0; j < cps.size (); j++)
520520
nurbs.SetCV (cp_red + j, ON_3dPoint (cps[j] (0), cps[j] (1), 0.0));
521521

522522
// close nurbs
523-
nurbs.SetCV (cp_red + int (cps.size ()), ON_3dPoint (cps[0] (0), cps[0] (1), 0.0));
523+
nurbs.SetCV (cp_red + static_cast<int>(cps.size ()), ON_3dPoint (cps[0] (0), cps[0] (1), 0.0));
524524

525525
// make smooth at closing point
526526
for (int j = 0; j < cp_red; j++)
@@ -544,7 +544,7 @@ FittingCurve2dAPDM::initNurbsCurve2D (int order, const vector_vec2d &data, int n
544544

545545
Eigen::Vector2d mean = NurbsTools::computeMean (data);
546546

547-
unsigned s = unsigned (data.size ());
547+
auto s = static_cast<unsigned>(data.size ());
548548

549549
double r (0.0);
550550
for (unsigned i = 0; i < s; i++)
@@ -641,7 +641,7 @@ FittingCurve2dAPDM::getElementVector (const ON_NurbsCurve &nurbs)
641641
void
642642
FittingCurve2dAPDM::assembleInterior (double wInt, double sigma2, double rScale, unsigned &row)
643643
{
644-
int nInt = int (m_data->interior.size ());
644+
int nInt = static_cast<int>(m_data->interior.size ());
645645
bool wFunction (true);
646646
double ds = 1.0 / (2.0 * sigma2);
647647
m_data->interior_error.clear ();
@@ -657,7 +657,7 @@ FittingCurve2dAPDM::assembleInterior (double wInt, double sigma2, double rScale,
657657
double param;
658658
Eigen::Vector2d pt, t;
659659
double error;
660-
if (p < int (m_data->interior_param.size ()))
660+
if (p < static_cast<int>(m_data->interior_param.size ()))
661661
{
662662
param = findClosestElementMidPoint (m_nurbs, pcp, m_data->interior_param[p]);
663663
param = inverseMapping (m_nurbs, pcp, param, error, pt, t, rScale, in_max_steps, in_accuracy, m_quiet);
@@ -677,10 +677,10 @@ FittingCurve2dAPDM::assembleInterior (double wInt, double sigma2, double rScale,
677677
Eigen::Vector3d b (t (0), t (1), 0.0);
678678
Eigen::Vector3d z = a.cross (b);
679679

680-
if (p < int (m_data->interior_weight.size ()))
680+
if (p < static_cast<int>(m_data->interior_weight.size ()))
681681
wInt = m_data->interior_weight[p];
682682

683-
if (p < int (m_data->interior_weight_function.size ()))
683+
if (p < static_cast<int>(m_data->interior_weight_function.size ()))
684684
wFunction = m_data->interior_weight_function[p];
685685

686686
double w (wInt);

0 commit comments

Comments
 (0)