Skip to content

Commit 1a6f4c4

Browse files
Fix performance-type-promotion-in-math-fn clang-tidy warning (#6908)
1 parent 163a2cf commit 1a6f4c4

File tree

5 files changed

+26
-28
lines changed

5 files changed

+26
-28
lines changed

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ Checks: >
5454
performance-*,
5555
-performance-noexcept-move-constructor,
5656
-performance-no-int-to-ptr,
57-
-performance-type-promotion-in-math-fn,
5857
readability-*,
5958
-readability-avoid-const-params-in-decls,
6059
-readability-braces-around-statements,

include/engine/api/route_api.hpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -443,23 +443,22 @@ class RouteAPI : public BaseAPI
443443
if (requested_annotations & RouteParameters::AnnotationsType::Speed)
444444
{
445445
double prev_speed = 0;
446-
speed =
447-
GetAnnotations<float>(fb_result,
448-
leg_geometry,
449-
[&prev_speed](const guidance::LegGeometry::Annotation &anno)
450-
{
451-
if (anno.duration < std::numeric_limits<float>::min())
452-
{
453-
return prev_speed;
454-
}
455-
else
456-
{
457-
auto speed =
458-
round(anno.distance / anno.duration * 10.) / 10.;
459-
prev_speed = speed;
460-
return util::json::clamp_float(speed);
461-
}
462-
});
446+
speed = GetAnnotations<float>(
447+
fb_result,
448+
leg_geometry,
449+
[&prev_speed](const guidance::LegGeometry::Annotation &anno)
450+
{
451+
if (anno.duration < std::numeric_limits<float>::min())
452+
{
453+
return prev_speed;
454+
}
455+
else
456+
{
457+
auto speed = std::round(anno.distance / anno.duration * 10.) / 10.;
458+
prev_speed = speed;
459+
return util::json::clamp_float(speed);
460+
}
461+
});
463462
}
464463

465464
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> duration;

src/engine/plugins/tile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,13 @@ void encodeVectorTile(const DataFacadeBase &facade,
497497
{
498498
// Calculate the speed for this line
499499
std::uint32_t speed_kmh_idx = static_cast<std::uint32_t>(
500-
round(length / from_alias<double>(forward_duration) * 10 * 3.6));
500+
std::round(length / from_alias<double>(forward_duration) * 10 * 3.6));
501501

502502
// Rate values are in meters per weight-unit - and similar to speeds, we
503503
// present 1 decimal place of precision (these values are added as
504504
// double/10) lower down
505505
std::uint32_t forward_rate = static_cast<std::uint32_t>(
506-
round(length / from_alias<double>(forward_weight) * 10.));
506+
std::round(length / from_alias<double>(forward_weight) * 10.));
507507

508508
auto tile_line = coordinatesToTileLine(a, b, tile_bbox);
509509
if (!tile_line.empty())
@@ -531,13 +531,13 @@ void encodeVectorTile(const DataFacadeBase &facade,
531531
{
532532
// Calculate the speed for this line
533533
std::uint32_t speed_kmh_idx = static_cast<std::uint32_t>(
534-
round(length / from_alias<double>(reverse_duration) * 10 * 3.6));
534+
std::round(length / from_alias<double>(reverse_duration) * 10 * 3.6));
535535

536536
// Rate values are in meters per weight-unit - and similar to speeds, we
537537
// present 1 decimal place of precision (these values are added as
538538
// double/10) lower down
539539
std::uint32_t reverse_rate = static_cast<std::uint32_t>(
540-
round(length / from_alias<double>(reverse_weight) * 10.));
540+
std::round(length / from_alias<double>(reverse_weight) * 10.));
541541

542542
auto tile_line = coordinatesToTileLine(b, a, tile_bbox);
543543
if (!tile_line.empty())

src/extractor/raster_source.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ RasterDatum RasterSource::GetRasterData(const int lon, const int lat) const
4040
return {};
4141
}
4242

43-
const std::size_t xth = static_cast<std::size_t>(round((lon - xmin) / xstep));
44-
const std::size_t yth = static_cast<std::size_t>(round((ymax - lat) / ystep));
43+
const std::size_t xth = static_cast<std::size_t>(std::round((lon - xmin) / xstep));
44+
const std::size_t yth = static_cast<std::size_t>(std::round((ymax - lat) / ystep));
4545

4646
return {raster_data(xth, yth)};
4747
}

unit_tests/library/route.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ void test_route_same_coordinates_fixture(bool use_json_only_api)
5454
itr.get<json::Object>().values["hint"] = "";
5555

5656
// Round value to 6 decimal places for double comparison later
57-
itr.get<json::Object>().values["distance"] =
58-
round(itr.get<json::Object>().values["distance"].get<json::Number>().value * 1000000);
57+
itr.get<json::Object>().values["distance"] = std::round(
58+
itr.get<json::Object>().values["distance"].get<json::Number>().value * 1000000);
5959
}
6060

6161
const auto location = json::Array{{{7.437070}, {43.749248}}};
@@ -65,11 +65,11 @@ void test_route_same_coordinates_fixture(bool use_json_only_api)
6565
{"waypoints",
6666
json::Array{{json::Object{{{"name", "Boulevard du Larvotto"},
6767
{"location", location},
68-
{"distance", round(0.137249 * 1000000)},
68+
{"distance", std::round(0.137249 * 1000000)},
6969
{"hint", ""}}},
7070
json::Object{{{"name", "Boulevard du Larvotto"},
7171
{"location", location},
72-
{"distance", round(0.137249 * 1000000)},
72+
{"distance", std::round(0.137249 * 1000000)},
7373
{"hint", ""}}}}}},
7474
{"routes",
7575
json::Array{{json::Object{

0 commit comments

Comments
 (0)