Skip to content

Commit 9da8045

Browse files
committed
Fix various clang-tidy issues with the expire code
* Don't use var of type double as loop variable clang-analyzer-security.FloatLoopCounter * Use const where possible * Explicit conversion
1 parent 7459bbc commit 9da8045

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/expire-tiles.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,14 @@ void expire_tiles::from_line_segment(geom::point_t const &a,
173173
double const x_step = x_len / hyp_len;
174174
double const y_step = y_len / hyp_len;
175175

176-
for (double step = 0; step <= hyp_len; step += 0.4) {
177-
/* Interpolate points 1 tile width apart */
178-
double next_step = step + 0.4;
179-
if (next_step > hyp_len) {
180-
next_step = hyp_len;
181-
}
182-
double x1 = tilec_a.x() + ((double)step * x_step);
183-
double y1 = tilec_a.y() + ((double)step * y_step);
184-
double x2 = tilec_a.x() + ((double)next_step * x_step);
185-
double y2 = tilec_a.y() + ((double)next_step * y_step);
176+
for (int i = 0; i <= hyp_len / 0.4; ++i) {
177+
double const step = i * 0.4;
178+
double const next_step = std::min(hyp_len, (i + 1) * 0.4);
179+
180+
double const x1 = tilec_a.x() + (step * x_step);
181+
double y1 = tilec_a.y() + (step * y_step);
182+
double const x2 = tilec_a.x() + (next_step * x_step);
183+
double y2 = tilec_a.y() + (next_step * y_step);
186184

187185
/* The line (x1,y1),(x2,y2) is up to 1 tile width long
188186
x1 will always be <= x2
@@ -192,11 +190,11 @@ void expire_tiles::from_line_segment(geom::point_t const &a,
192190
if (y1 > y2) {
193191
std::swap(y1, y2);
194192
}
195-
for (int x = x1 - expire_config.buffer; x <= x2 + expire_config.buffer;
196-
++x) {
193+
for (int x = static_cast<int>(x1 - expire_config.buffer);
194+
x <= static_cast<int>(x2 + expire_config.buffer); ++x) {
197195
uint32_t const norm_x = normalise_tile_x_coord(x);
198-
for (int y = y1 - expire_config.buffer;
199-
y <= y2 + expire_config.buffer; ++y) {
196+
for (int y = static_cast<int>(y1 - expire_config.buffer);
197+
y <= static_cast<int>(y2 + expire_config.buffer); ++y) {
200198
if (y >= 0) {
201199
expire_tile(norm_x, static_cast<uint32_t>(y));
202200
}

0 commit comments

Comments
 (0)