@@ -87,14 +87,18 @@ class CDynamicGrid
87
87
m_resolution = resolution;
88
88
89
89
// Now the number of cells should be integers:
90
- m_size_x = round ((m_x_max - m_x_min) / m_resolution);
91
- m_size_y = round ((m_y_max - m_y_min) / m_resolution);
90
+ m_size_x = static_cast <std:: size_t >( round ((m_x_max - m_x_min) / m_resolution) );
91
+ m_size_y = static_cast <std:: size_t >( round ((m_y_max - m_y_min) / m_resolution) );
92
92
93
93
// Cells memory:
94
94
if (fill_value)
95
+ {
95
96
m_map.assign (m_size_x * m_size_y, *fill_value);
97
+ }
96
98
else
99
+ {
97
100
m_map.resize (m_size_x * m_size_y);
101
+ }
98
102
}
99
103
100
104
/* * Erase the contents of all the cells. */
@@ -125,7 +129,9 @@ class CDynamicGrid
125
129
// Is resize really necessary?
126
130
if (new_x_min >= m_x_min && new_y_min >= m_y_min && new_x_max <= m_x_max &&
127
131
new_y_max <= m_y_max)
132
+ {
128
133
return ;
134
+ }
129
135
130
136
if (new_x_min > m_x_min) new_x_min = m_x_min;
131
137
if (new_x_max < m_x_max) new_x_max = m_x_max;
@@ -153,23 +159,26 @@ class CDynamicGrid
153
159
new_y_max = m_resolution * round (new_y_max / m_resolution);
154
160
155
161
// Change the map size: Extensions at each side:
156
- unsigned int extra_x_izq = round ((m_x_min - new_x_min) / m_resolution);
157
- unsigned int extra_y_arr = round ((m_y_min - new_y_min) / m_resolution);
162
+ const auto extra_x_left = static_cast <std:: size_t >( round ((m_x_min - new_x_min) / m_resolution) );
163
+ const auto extra_y_top = static_cast <std:: size_t >( round ((m_y_min - new_y_min) / m_resolution) );
158
164
159
- unsigned int new_size_x = round ((new_x_max - new_x_min) / m_resolution);
160
- unsigned int new_size_y = round ((new_y_max - new_y_min) / m_resolution);
165
+ const auto new_size_x = static_cast <std:: size_t >( round ((new_x_max - new_x_min) / m_resolution) );
166
+ const auto new_size_y = static_cast <std:: size_t >( round ((new_y_max - new_y_min) / m_resolution) );
161
167
162
168
// Reserve new memory:
163
169
grid_data_t new_map;
164
170
new_map.resize (new_size_x * new_size_y, defaultValueNewCells);
165
171
166
172
// Copy previous rows:
167
- unsigned int x, y;
168
173
iterator itSrc, itDst;
169
- for (y = 0 ; y < m_size_y; y++)
174
+ for (std:: size_t y = 0 ; y < m_size_y; y++)
170
175
{
171
- for (x = 0 , itSrc = (m_map.begin () + y * m_size_x),
172
- itDst = (new_map.begin () + extra_x_izq + (y + extra_y_arr) * new_size_x);
176
+ const auto idxSrc = static_cast <typename std::vector<T>::difference_type>(y * m_size_x);
177
+ const auto idxDst = static_cast <typename std::vector<T>::difference_type>(
178
+ extra_x_left + (y + extra_y_top) * new_size_x);
179
+
180
+ std::size_t x;
181
+ for (x = 0 , itSrc = (m_map.begin () + idxSrc), itDst = (new_map.begin () + idxDst);
173
182
x < m_size_x; ++x, ++itSrc, ++itDst)
174
183
{
175
184
*itDst = *itSrc;
@@ -198,7 +207,7 @@ class CDynamicGrid
198
207
const int cy = y2idx (y);
199
208
if (cx < 0 || cx >= static_cast <int >(m_size_x)) return nullptr ;
200
209
if (cy < 0 || cy >= static_cast <int >(m_size_y)) return nullptr ;
201
- return &m_map[cx + cy * m_size_x];
210
+ return &m_map[static_cast < size_t >(cx) + static_cast < size_t >(cy) * m_size_x];
202
211
}
203
212
/* * \overload */
204
213
inline const T* cellByPos (double x, double y) const
@@ -207,7 +216,7 @@ class CDynamicGrid
207
216
const int cy = y2idx (y);
208
217
if (cx < 0 || cx >= static_cast <int >(m_size_x)) return nullptr ;
209
218
if (cy < 0 || cy >= static_cast <int >(m_size_y)) return nullptr ;
210
- return &m_map[cx + cy * m_size_x];
219
+ return &m_map[static_cast < size_t >(cx) + static_cast < size_t >(cy) * m_size_x];
211
220
}
212
221
213
222
/* * Returns a pointer to the contents of a cell given by its cell indexes,
0 commit comments