Skip to content

Commit b7293f5

Browse files
mgaertneratanyboticsCI
authored andcommitted
Merge branch 'fix/grid_map_core/reduce_clang_warnings' into 'master'
[grid map core] Reduce clang warnings GitOrigin-RevId: 0b01ff34cd31833b65f4718fab82467f11332938
1 parent f4ccb5f commit b7293f5

15 files changed

+148
-160
lines changed

grid_map_core/include/grid_map_core/BufferRegion.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class BufferRegion
3535
constexpr static unsigned int nQuadrants = 4;
3636

3737
BufferRegion();
38-
BufferRegion(const Index& startIndex, const Size& size, const BufferRegion::Quadrant& quadrant);
39-
virtual ~BufferRegion();
38+
BufferRegion(Index startIndex, Size size, BufferRegion::Quadrant quadrant);
39+
virtual ~BufferRegion() = default;
4040

4141
const Index& getStartIndex() const;
4242
void setStartIndex(const Index& startIndex);
@@ -48,7 +48,7 @@ class BufferRegion
4848
private:
4949

5050
//! Start index (typically top-left) of the buffer region.
51-
Index staretIndex_;
51+
Index startIndex_;
5252

5353
//! Size of the buffer region.
5454
Size size_;

grid_map_core/include/grid_map_core/CubicInterpolation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using FunctionValueMatrix = Eigen::Matrix4d;
4646
* @param[in] nElem - number of elements in the container
4747
* @return index that is within [0, nElem-1].
4848
*/
49-
unsigned int bindIndexToRange(int idReq, unsigned int nElem);
49+
unsigned int bindIndexToRange(unsigned int idReq, unsigned int nElem);
5050

5151

5252
/*!

grid_map_core/include/grid_map_core/TypeDefs.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
*/
88

99
// Eigen
10-
#include <Eigen/Core>
11-
1210
#pragma once
1311

12+
#include <Eigen/Core>
13+
1414
namespace grid_map {
1515

16-
typedef Eigen::MatrixXf Matrix;
17-
typedef Matrix::Scalar DataType;
18-
typedef Eigen::Vector2d Position;
19-
typedef Eigen::Vector2d Vector;
20-
typedef Eigen::Vector3d Position3;
21-
typedef Eigen::Vector3d Vector3;
22-
typedef Eigen::Array2i Index;
23-
typedef Eigen::Array2i Size;
24-
typedef Eigen::Array2d Length;
25-
typedef uint64_t Time;
16+
using Matrix = Eigen::MatrixXf;
17+
using DataType = Matrix::Scalar;
18+
using Position = Eigen::Vector2d;
19+
using Vector = Eigen::Vector2d;
20+
using Position3 = Eigen::Vector3d;
21+
using Vector3 = Eigen::Vector3d;
22+
using Index = Eigen::Array2i;
23+
using Size = Eigen::Array2i;
24+
using Length = Eigen::Array2d;
25+
using Time = uint64_t;
2626

2727
/*
2828
* Interpolations are ordered in the order
@@ -43,4 +43,5 @@ namespace grid_map {
4343
INTER_CUBIC // standard bicubic interpolation
4444
};
4545

46-
} /* namespace */
46+
} // namespace grid_map
47+

grid_map_core/include/grid_map_core/eigen_plugins/DenseBasePlugin.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
#pragma once
2+
13
Scalar numberOfFinites() const
24
{
3-
if (SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) return Scalar(0);
5+
if (SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) {
6+
return Scalar(0);
7+
}
48
return Scalar((derived().array() == derived().array()).count());
59
}
610

711
Scalar sumOfFinites() const
812
{
9-
if (SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) return Scalar(0);
13+
if (SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) {
14+
return Scalar(0);
15+
}
1016
return Scalar(this->redux(Eigen::internal::scalar_sum_of_finites_op<Scalar>()));
1117
}
1218

grid_map_core/include/grid_map_core/eigen_plugins/Functors.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ struct Clamp
2525
Scalar min_, max_;
2626
};
2727

28-
}
28+
} // namespace grid_map

grid_map_core/include/grid_map_core/eigen_plugins/FunctorsPlugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <math.h>
1+
#include <cmath>
22

33
template<typename Scalar> struct scalar_sum_of_finites_op {
44
EIGEN_EMPTY_STRUCT_CTOR(scalar_sum_of_finites_op)

grid_map_core/include/grid_map_core/iterators/CircleIterator.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class CircleIterator
3030
* @param center the position of the circle center.
3131
* @param radius the radius of the circle.
3232
*/
33-
CircleIterator(const GridMap& gridMap, const Position& center, const double radius);
33+
CircleIterator(const GridMap& gridMap, const Position& center, double radius);
3434

3535
/*!
3636
* Assignment operator.
3737
* @param iterator the iterator to copy data from.
3838
* @return a reference to *this.
3939
*/
40-
CircleIterator& operator =(const CircleIterator& other);
40+
CircleIterator& operator =(const CircleIterator& other) = default;
4141

4242
/*!
4343
* Compare to another iterator.
@@ -78,7 +78,7 @@ class CircleIterator
7878
* @param[out] startIndex the start index of the submap.
7979
* @param[out] bufferSize the buffer size of the submap.
8080
*/
81-
void findSubmapParameters(const Position& center, const double radius,
81+
void findSubmapParameters(const Position& center, double radius,
8282
Index& startIndex, Size& bufferSize) const;
8383

8484
//! Position of the circle center;
@@ -104,4 +104,5 @@ class CircleIterator
104104
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
105105
};
106106

107-
} /* namespace */
107+
} // namespace grid_map
108+

grid_map_core/include/grid_map_core/iterators/EllipseIterator.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class EllipseIterator
3232
* @param length the length of the main axis.
3333
* @param angle the rotation angle of the ellipse (in [rad]).
3434
*/
35-
EllipseIterator(const GridMap& gridMap, const Position& center, const Length& length, const double rotation = 0.0);
35+
EllipseIterator(const GridMap& gridMap, const Position& center, const Length& length, double rotation = 0.0);
3636

3737
/*!
3838
* Assignment operator.
3939
* @param iterator the iterator to copy data from.
4040
* @return a reference to *this.
4141
*/
42-
EllipseIterator& operator =(const EllipseIterator& other);
42+
EllipseIterator& operator =(const EllipseIterator& other) = default;
4343

4444
/*!
4545
* Compare to another iterator.
@@ -87,7 +87,7 @@ class EllipseIterator
8787
* @param[out] startIndex the start index of the submap.
8888
* @param[out] bufferSize the buffer size of the submap.
8989
*/
90-
void findSubmapParameters(const Position& center, const Length& length, const double rotation,
90+
void findSubmapParameters(const Position& center, const Length& length, double rotation,
9191
Index& startIndex, Size& bufferSize) const;
9292

9393
//! Position of the circle center;
@@ -113,4 +113,5 @@ class EllipseIterator
113113
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
114114
};
115115

116-
} /* namespace */
116+
} // namespace grid_map
117+

grid_map_core/src/BufferRegion.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,26 @@
99

1010
namespace grid_map {
1111

12-
BufferRegion::BufferRegion() :
13-
staretIndex_(Index::Zero()),
12+
BufferRegion::BufferRegion() : startIndex_(Index::Zero()),
1413
size_(Size::Zero()),
1514
quadrant_(BufferRegion::Quadrant::Undefined)
1615
{
1716
}
1817

19-
BufferRegion::BufferRegion(const Index& index, const Size& size, const BufferRegion::Quadrant& quadrant) :
20-
staretIndex_(index),
21-
size_(size),
22-
quadrant_(quadrant)
23-
{
24-
}
25-
26-
BufferRegion::~BufferRegion()
18+
BufferRegion::BufferRegion(Index index, Size size, BufferRegion::Quadrant quadrant) : startIndex_(std::move(index)),
19+
size_(std::move(size)),
20+
quadrant_(std::move(quadrant))
2721
{
2822
}
2923

3024
const Index& BufferRegion::getStartIndex() const
3125
{
32-
return staretIndex_;
26+
return startIndex_;
3327
}
3428

35-
void BufferRegion::setStartIndex(const Index& staretIndex)
29+
void BufferRegion::setStartIndex(const Index& startIndex)
3630
{
37-
staretIndex_ = staretIndex;
31+
startIndex_ = startIndex;
3832
}
3933

4034
const Size& BufferRegion::getSize() const

grid_map_core/src/CubicInterpolation.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@
1313

1414
namespace grid_map {
1515

16-
unsigned int bindIndexToRange(int idReq, unsigned int nElem)
16+
unsigned int bindIndexToRange(unsigned int idReq, unsigned int nElem)
1717
{
18-
if (idReq < 0) {
19-
return 0;
18+
if (idReq >= nElem) {
19+
return (nElem - 1);
2020
}
21-
if (static_cast<unsigned int>(idReq) >= nElem) {
22-
return static_cast<unsigned int>(nElem - 1);
23-
}
24-
return static_cast<unsigned int>(idReq);
21+
return idReq;
2522
}
2623

27-
double getLayerValue(const Matrix &layerMat, int rowReq, int colReq)
24+
double getLayerValue(const Matrix &layerMat, unsigned int rowReq, unsigned int colReq)
2825
{
2926
const auto numCol = layerMat.cols();
3027
const auto numRow = layerMat.rows();
@@ -92,7 +89,7 @@ bool assembleFunctionValueMatrix(const GridMap &gridMap, const std::string &laye
9289
}
9390

9491
const Matrix &layerMatrix = gridMap.get(layer);
95-
auto f = [&layerMatrix](int rowReq, int colReq) {
92+
auto f = [&layerMatrix](unsigned int rowReq, unsigned int colReq) {
9693
double retVal = getLayerValue(layerMatrix, rowReq, colReq);
9794
return retVal;
9895
};
@@ -135,11 +132,7 @@ bool getNormalizedCoordinates(const GridMap &gridMap, const Position &queriedPos
135132

136133
bool getIndicesOfMiddleKnot(const GridMap &gridMap, const Position &queriedPosition, Index *index)
137134
{
138-
139-
if (!gridMap.getIndex(queriedPosition, *index)) {
140-
return false;
141-
}
142-
return true;
135+
return gridMap.getIndex(queriedPosition, *index);
143136
}
144137

145138
} /* namespace bicubic_conv */
@@ -264,11 +257,7 @@ bool getUnitSquareCornerIndices(const GridMap &gridMap, const Position &queriedP
264257

265258
bool getClosestPointIndices(const GridMap &gridMap, const Position &queriedPosition, Index *index)
266259
{
267-
268-
if (!gridMap.getIndex(queriedPosition, *index)) {
269-
return false;
270-
}
271-
return true;
260+
return gridMap.getIndex(queriedPosition, *index);
272261
}
273262

274263
bool computeNormalizedCoordinates(const GridMap &gridMap, const Index &originIndex,
@@ -298,8 +287,8 @@ bool getFunctionValues(const Matrix &layerData, const IndicesMatrix &indices, Da
298287

299288
void bindIndicesToRange(const GridMap &gridMap, IndicesMatrix *indices)
300289
{
301-
const int numCol = gridMap.getSize().y();
302-
const int numRow = gridMap.getSize().x();
290+
const unsigned int numCol = gridMap.getSize().y();
291+
const unsigned int numRow = gridMap.getSize().x();
303292

304293
//top left
305294
{
@@ -346,10 +335,11 @@ bool getFirstOrderDerivatives(const Matrix &layerData, const IndicesMatrix &indi
346335
double firstOrderDerivativeAt(const Matrix &layerData, const Index &index, Dim2D dim,
347336
double resolution)
348337
{
349-
const int numCol = layerData.cols();
350-
const int numRow = layerData.rows();
338+
const auto numCol{static_cast<unsigned int>(layerData.cols())};
339+
const auto numRow{static_cast<unsigned int>(layerData.rows())};
351340

352-
double left, right;
341+
double left;
342+
double right;
353343
switch (dim) {
354344
case Dim2D::X: {
355345
left = layerData(bindIndexToRange(index.x() + 1, numRow), index.y());
@@ -380,9 +370,8 @@ double mixedSecondOrderDerivativeAt(const Matrix &layerData, const Index &index,
380370
* the order doesn't matter. Derivative values are the same.
381371
* Taken from https://www.mathematik.uni-dortmund.de/~kuzmin/cfdintro/lecture4.pdf
382372
*/
383-
384-
const int numCol = layerData.cols();
385-
const int numRow = layerData.rows();
373+
const auto numCol{static_cast<unsigned int>(layerData.cols())};
374+
const auto numRow{static_cast<unsigned int>(layerData.rows())};
386375

387376
const double f11 = layerData(bindIndexToRange(index.x() - 1, numRow),
388377
bindIndexToRange(index.y() - 1, numCol));

0 commit comments

Comments
 (0)