Skip to content

Commit a96357b

Browse files
author
Jay Herpin
committed
grid_map_sdf: add the missing <limits> include and match the ament style
Utils.hpp uses std::numeric_limits without including <limits>, relying on it arriving transitively. The four SignedDistance2d files were backported from master, which is formatted to a different standard than the kilted release branch, so cpplint and uncrustify rejected them. Reformat with the ament config this package already tests against, and move the over-long trailing comments onto their own lines. (cherry picked from commit 3b56b13)
1 parent 0c30a16 commit a96357b

4 files changed

Lines changed: 266 additions & 195 deletions

File tree

‎grid_map_sdf/include/grid_map_sdf/PixelBorderDistance.hpp‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <cassert>
1313
#include <cmath>
1414

15-
namespace grid_map {
16-
namespace signed_distance_field {
15+
namespace grid_map
16+
{
17+
namespace signed_distance_field
18+
{
1719

1820
/**
1921
* Returns distance between the center of a pixel and the border of an other pixel.
@@ -23,24 +25,28 @@ namespace signed_distance_field {
2325
* @param j : location of pixel 2
2426
* @return : absolute distance between center of pixel 1 and the border of pixel 2
2527
*/
26-
inline float pixelBorderDistance(float i, float j) {
28+
inline float pixelBorderDistance(float i, float j)
29+
{
2730
return std::max(std::abs(i - j) - 0.5F, 0.0F);
2831
}
2932

3033
/**
3134
* Returns square pixelBorderDistance, adding offset f.
3235
*/
33-
inline float squarePixelBorderDistance(float i, float j, float f) {
36+
inline float squarePixelBorderDistance(float i, float j, float f)
37+
{
3438
const float d{pixelBorderDistance(i, j)};
3539
return d * d + f;
3640
}
3741

38-
namespace internal {
42+
namespace internal
43+
{
3944

4045
/**
4146
* Return equidistancepoint between origin and pixel p (with p > 0) with offset fp
4247
*/
43-
inline float intersectionPointRightSideOfOrigin(float p, float fp) {
48+
inline float intersectionPointRightSideOfOrigin(float p, float fp)
49+
{
4450
/*
4551
* There are 5 different solutions
4652
* In decreasing order:
@@ -70,7 +76,8 @@ inline float intersectionPointRightSideOfOrigin(float p, float fp) {
7076
/**
7177
* Return equidistancepoint between origin and pixel p with offset fp
7278
*/
73-
inline float intersectionOffsetFromOrigin(float p, float fp) {
79+
inline float intersectionOffsetFromOrigin(float p, float fp)
80+
{
7481
if (p > 0.0F) {
7582
return intersectionPointRightSideOfOrigin(p, fp);
7683
} else {
@@ -86,9 +93,10 @@ inline float intersectionOffsetFromOrigin(float p, float fp) {
8693
* It is the solution to the following equation:
8794
* squarePixelBorderDistance(s, q, fq) == squarePixelBorderDistance(s, p, fp)
8895
*/
89-
inline float equidistancePoint(float q, float fq, float p, float fp) {
90-
assert(q == p ||
91-
std::abs(q - p) >= 1.0F); // Check that q and p are proper pixel locations: either the same pixel or non-overlapping pixels
96+
inline float equidistancePoint(float q, float fq, float p, float fp)
97+
{
98+
// Check that q and p are proper pixel locations: either the same pixel or non-overlapping pixels
99+
assert(q == p || std::abs(q - p) >= 1.0F);
92100
assert((q == p) ? fp == fq : true); // Check when q and p are equal, the offsets are also equal
93101

94102
if (fp == fq) { // quite common case when both pixels are of the same class (occupied / free)
@@ -101,4 +109,4 @@ inline float equidistancePoint(float q, float fq, float p, float fp) {
101109
}
102110

103111
} // namespace signed_distance_field
104-
} // namespace grid_map
112+
} // namespace grid_map

‎grid_map_sdf/include/grid_map_sdf/SignedDistance2d.hpp‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
#include "Utils.hpp"
1616

17-
namespace grid_map {
18-
namespace signed_distance_field {
17+
namespace grid_map
18+
{
19+
namespace signed_distance_field
20+
{
1921

2022
/**
2123
* Computes the signed distance field at a specified height for a given elevation map.
@@ -27,7 +29,9 @@ namespace signed_distance_field {
2729
* @param maxHeight : the maximum height contained in elevationMap
2830
* @return The signed distance field at the query height.
2931
*/
30-
Matrix signedDistanceAtHeight(const Matrix& elevationMap, float height, float resolution, float minHeight, float maxHeight);
32+
Matrix signedDistanceAtHeight(
33+
const Matrix & elevationMap, float height, float resolution,
34+
float minHeight, float maxHeight);
3135

3236
/**
3337
* Same as above, but returns the sdf in transposed form.
@@ -42,8 +46,10 @@ Matrix signedDistanceAtHeight(const Matrix& elevationMap, float height, float re
4246
* @param minHeight : the lowest height contained in elevationMap
4347
* @param maxHeight : the maximum height contained in elevationMap
4448
*/
45-
void signedDistanceAtHeightTranspose(const Matrix& elevationMap, Matrix& sdfTranspose, Matrix& tmp, Matrix& tmpTranspose, float height,
46-
float resolution, float minHeight, float maxHeight);
49+
void signedDistanceAtHeightTranspose(
50+
const Matrix & elevationMap, Matrix & sdfTranspose, Matrix & tmp, Matrix & tmpTranspose,
51+
float height,
52+
float resolution, float minHeight, float maxHeight);
4753

4854
/**
4955
* Gets the 2D signed distance from an occupancy grid.
@@ -53,7 +59,9 @@ void signedDistanceAtHeightTranspose(const Matrix& elevationMap, Matrix& sdfTran
5359
* @param resolution : resolution of the grid.
5460
* @return signed distance for each point in the grid to the occupancy border.
5561
*/
56-
Matrix signedDistanceFromOccupancy(const Eigen::Matrix<bool, -1, -1>& occupancyGrid, float resolution);
62+
Matrix signedDistanceFromOccupancy(
63+
const Eigen::Matrix<bool, -1, -1> & occupancyGrid,
64+
float resolution);
5765

5866
} // namespace signed_distance_field
59-
} // namespace grid_map
67+
} // namespace grid_map

‎grid_map_sdf/include/grid_map_sdf/Utils.hpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88

99
#pragma once
1010

11-
namespace grid_map {
12-
namespace signed_distance_field {
11+
#include <limits>
12+
13+
namespace grid_map
14+
{
15+
namespace signed_distance_field
16+
{
1317

1418
// Check existence of inf
1519
static_assert(std::numeric_limits<float>::has_infinity, "float does not support infinity");
@@ -18,4 +22,4 @@ static_assert(std::numeric_limits<float>::has_infinity, "float does not support
1822
constexpr float INF = std::numeric_limits<float>::infinity();
1923

2024
} // namespace signed_distance_field
21-
} // namespace grid_map
25+
} // namespace grid_map

0 commit comments

Comments
 (0)