Skip to content

Commit 6ddff74

Browse files
Emilk Roy Sempertegui AveigaCI
authored andcommitted
Merge branch 'fix/grid_map_core_remove_compiler_warnings' into 'master'
[grid_map_core] Remove compiler warnings GitOrigin-RevId: 593af35e98d1d24b28f8aaedbc18d96e99f861cf
1 parent 1cbbf46 commit 6ddff74

File tree

8 files changed

+33
-51
lines changed

8 files changed

+33
-51
lines changed

grid_map_core/include/grid_map_core/GridMapMath.hpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
namespace grid_map {
1919

20+
union Color
21+
{
22+
unsigned long longColor;
23+
float floatColor;
24+
};
25+
2026
/*!
2127
* Gets the position of a cell specified by its index in the map frame.
2228
* @param[out] position the position of the center of the cell in the map frame.
@@ -289,25 +295,6 @@ size_t getLinearIndexFromIndex(const Index& index, const Size& bufferSize, const
289295
*/
290296
Index getIndexFromLinearIndex(const size_t linearIndex, const Size& bufferSize, const bool rowMajor = false);
291297

292-
/*!
293-
* Generates a list of indices for a region in the map.
294-
* @param regionIndex the region top-left index.
295-
* @param regionSize the region size.
296-
* @param indices the list of indices of the region.
297-
*/
298-
void getIndicesForRegion(const Index& regionIndex, const Size& regionSize,
299-
std::vector<Index> indices);
300-
301-
/*!
302-
* Generates a list of indices for multiple regions in the map.
303-
* This method makes sure every index is only once contained in the list.
304-
* @param regionIndeces the regions' top-left index.
305-
* @param regionSizes the regions' sizes.
306-
* @param indices the list of indices of the regions.
307-
*/
308-
void getIndicesForRegions(const std::vector<Index>& regionIndeces, const Size& regionSizes,
309-
std::vector<Index> indices);
310-
311298
/*!
312299
* Transforms an int color value (concatenated RGB values) to an int color vector (RGB from 0-255).
313300
* @param [in] colorValue the concatenated RGB color value.

grid_map_core/include/grid_map_core/iterators/GridMapIterator.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class GridMapIterator
3434
*/
3535
GridMapIterator(const GridMapIterator* other);
3636

37+
/*!
38+
* Copy constructor.
39+
* @param other the object to copy.
40+
*/
41+
GridMapIterator(const GridMapIterator &other) = default;
42+
3743
/*!
3844
* Assignment operator.
3945
* @param iterator the iterator to copy data from.

grid_map_core/src/CubicInterpolation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ unsigned int bindIndexToRange(int idReq, unsigned int nElem)
1818
if (idReq < 0) {
1919
return 0;
2020
}
21-
if (idReq >= nElem) {
21+
if (static_cast<unsigned int>(idReq) >= nElem) {
2222
return static_cast<unsigned int>(nElem - 1);
2323
}
2424
return static_cast<unsigned int>(idReq);

grid_map_core/src/GridMap.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ float GridMap::atPosition(const std::string& layer, const Position& position, In
177177
interpolationMethod = InterpolationMethods::INTER_LINEAR;
178178
skipNextSwitchCase = true;
179179
}
180+
[[fallthrough]];
180181
}
181182
case InterpolationMethods::INTER_CUBIC: {
182183
if (!skipNextSwitchCase) {
@@ -187,13 +188,16 @@ float GridMap::atPosition(const std::string& layer, const Position& position, In
187188
interpolationMethod = InterpolationMethods::INTER_LINEAR;
188189
}
189190
}
191+
[[fallthrough]];
190192
}
191193
case InterpolationMethods::INTER_LINEAR: {
192194
float value;
193195
if (atPositionLinearInterpolated(layer, position, value))
194196
return value;
195-
else
197+
else {
196198
interpolationMethod = InterpolationMethods::INTER_NEAREST;
199+
}
200+
[[fallthrough]];
197201
}
198202
case InterpolationMethods::INTER_NEAREST: {
199203
Index index;
@@ -289,7 +293,7 @@ GridMap GridMap::getSubmap(const Position& position, const Length& length, bool&
289293
return getSubmap(position, length, index, isSuccess);
290294
}
291295

292-
GridMap GridMap::getSubmap(const Position& position, const Length& length, Index& indexInSubmap, bool& isSuccess) const {
296+
GridMap GridMap::getSubmap(const Position& position, const Length& length, Index& /*indexInSubmap*/, bool& isSuccess) const {
293297
// Submap the generate.
294298
GridMap submap(layers_);
295299
submap.setBasicLayers(basicLayers_);
@@ -696,7 +700,7 @@ void GridMap::convertToDefaultStartIndex() {
696700
}
697701

698702
Position GridMap::getClosestPositionInMap(const Position& position) const {
699-
if (getSize().x() < 1u || getSize().y() < 1u) {
703+
if (getSize().x() < 1 || getSize().y() < 1) {
700704
return position_;
701705
}
702706

grid_map_core/src/GridMapMath.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -517,21 +517,6 @@ Index getIndexFromLinearIndex(const size_t linearIndex, const Size& bufferSize,
517517
return Index((int)linearIndex / bufferSize(1), (int)linearIndex % bufferSize(1));
518518
}
519519

520-
void getIndicesForRegion(const Index& regionIndex, const Size& regionSize,
521-
std::vector<Index> indices)
522-
{
523-
// for (int i = line.index_; col < line.endIndex(); col++) {
524-
// for (int i = 0; i < getSize()(0); i++) {
525-
//
526-
// }
527-
// }
528-
}
529-
530-
void getIndicesForRegions(const std::vector<Index>& regionIndeces, const Size& regionSizes,
531-
std::vector<Index> indices)
532-
{
533-
}
534-
535520
bool colorValueToVector(const unsigned long& colorValue, Eigen::Vector3i& colorVector)
536521
{
537522
colorVector(0) = (colorValue >> 16) & 0x0000ff;
@@ -564,9 +549,9 @@ bool colorVectorToValue(const Eigen::Vector3i& colorVector, unsigned long& color
564549

565550
void colorVectorToValue(const Eigen::Vector3i& colorVector, float& colorValue)
566551
{
567-
unsigned long color = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
568-
// cppcheck-suppress invalidPointerCast
569-
colorValue = *reinterpret_cast<float*>(&color);
552+
Color colors;
553+
colors.longColor = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
554+
colorValue = colors.floatColor;
570555
}
571556

572557
void colorVectorToValue(const Eigen::Vector3f& colorVector, float& colorValue)

grid_map_core/src/Polygon.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Polygon::~Polygon() {}
3232
bool Polygon::isInside(const Position& point) const
3333
{
3434
int cross = 0;
35-
for (int i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
35+
for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
3636
if ( ((vertices_[i].y() > point.y()) != (vertices_[j].y() > point.y()))
3737
&& (point.x() < (vertices_[j].x() - vertices_[i].x()) * (point.y() - vertices_[i].y()) /
3838
(vertices_[j].y() - vertices_[i].y()) + vertices_[i].x()) )
@@ -102,7 +102,7 @@ double Polygon::getArea() const
102102
{
103103
double area = 0.0;
104104
int j = vertices_.size() - 1;
105-
for (int i = 0; i < vertices_.size(); i++) {
105+
for (size_t i = 0; i < vertices_.size(); i++) {
106106
area += (vertices_.at(j).x() + vertices_.at(i).x())
107107
* (vertices_.at(j).y() - vertices_.at(i).y());
108108
j = i;
@@ -116,7 +116,7 @@ Position Polygon::getCentroid() const
116116
std::vector<Position> vertices = getVertices();
117117
vertices.push_back(vertices.at(0));
118118
double area = 0.0;
119-
for (int i = 0; i < vertices.size() - 1; i++) {
119+
for (size_t i = 0; i < vertices.size() - 1; i++) {
120120
const double a = vertices[i].x() * vertices[i+1].y() - vertices[i+1].x() * vertices[i].y();
121121
area += a;
122122
centroid.x() += a * (vertices[i].x() + vertices[i+1].x());
@@ -220,7 +220,7 @@ bool Polygon::offsetInward(const double margin)
220220
return true;
221221
}
222222

223-
std::vector<Polygon> Polygon::triangulate(const TriangulationMethods& method) const
223+
std::vector<Polygon> Polygon::triangulate(const TriangulationMethods& /*method*/) const
224224
{
225225
// TODO Add more triangulation methods.
226226
// https://en.wikipedia.org/wiki/Polygon_triangulation
@@ -311,7 +311,7 @@ Polygon Polygon::monotoneChainConvexHullOfPoints(const std::vector<Position>& po
311311

312312
int k = 0;
313313
// Build lower hull
314-
for (int i = 0; i < sortedPoints.size(); ++i) {
314+
for (size_t i = 0; i < sortedPoints.size(); ++i) {
315315
while (k >= 2 && vectorsMakeClockwiseTurn(pointsConvexHull.at(k - 2), pointsConvexHull.at(k - 1), sortedPoints.at(i))) {
316316
k--;
317317
}

grid_map_core/src/iterators/PolygonIterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool PolygonIterator::isInside() const
7474
return polygon_.isInside(position);
7575
}
7676

77-
void PolygonIterator::findSubmapParameters(const grid_map::Polygon& polygon, Index& startIndex, Size& bufferSize) const
77+
void PolygonIterator::findSubmapParameters(const grid_map::Polygon& /*polygon*/, Index& startIndex, Size& bufferSize) const
7878
{
7979
Position topLeft = polygon_.getVertices()[0];
8080
Position bottomRight = topLeft;

grid_map_core/src/iterators/SpiralIterator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ SpiralIterator& SpiralIterator::operator =(const SpiralIterator& other)
5151
return *this;
5252
}
5353

54-
bool SpiralIterator::operator !=(const SpiralIterator& other) const
54+
bool SpiralIterator::operator !=(const SpiralIterator& /*other*/) const
5555
{
5656
return (pointsRing_.back() != pointsRing_.back()).any();
5757
}
@@ -101,16 +101,16 @@ void SpiralIterator::generateRing()
101101
normal.x() = -signum(point.y());
102102
normal.y() = signum(point.x());
103103
if (normal.x() != 0
104-
&& (int) Vector(point.x() + normal.x(), point.y()).norm() == distance_)
104+
&& static_cast<unsigned int>(Vector(point.x() + normal.x(), point.y()).norm()) == distance_)
105105
point.x() += normal.x();
106106
else if (normal.y() != 0
107-
&& (int) Vector(point.x(), point.y() + normal.y()).norm() == distance_)
107+
&& static_cast<unsigned int>(Vector(point.x(), point.y() + normal.y()).norm()) == distance_)
108108
point.y() += normal.y();
109109
else {
110110
point.x() += normal.x();
111111
point.y() += normal.y();
112112
}
113-
} while (point.x() != distance_ || point.y() != 0);
113+
} while (static_cast<unsigned int>(point.x()) != distance_ || point.y() != 0);
114114
}
115115

116116
double SpiralIterator::getCurrentRadius() const

0 commit comments

Comments
 (0)