Fix performance-type-promotion-in-math-fn clang-tidy warning

This commit is contained in:
Siarhei Fedartsou 2024-05-26 10:47:42 +02:00
parent b7a990d0b5
commit f8c78d447c
4 changed files with 24 additions and 26 deletions

View File

@ -54,7 +54,6 @@ Checks: >
performance-*,
-performance-noexcept-move-constructor,
-performance-no-int-to-ptr,
-performance-type-promotion-in-math-fn,
readability-*,
-readability-avoid-const-params-in-decls,
-readability-braces-around-statements,

View File

@ -443,8 +443,8 @@ class RouteAPI : public BaseAPI
if (requested_annotations & RouteParameters::AnnotationsType::Speed)
{
double prev_speed = 0;
speed =
GetAnnotations<float>(fb_result,
speed = GetAnnotations<float>(
fb_result,
leg_geometry,
[&prev_speed](const guidance::LegGeometry::Annotation &anno)
{
@ -454,8 +454,7 @@ class RouteAPI : public BaseAPI
}
else
{
auto speed =
round(anno.distance / anno.duration * 10.) / 10.;
auto speed = std::round(anno.distance / anno.duration * 10.) / 10.;
prev_speed = speed;
return util::json::clamp_float(speed);
}

View File

@ -497,13 +497,13 @@ void encodeVectorTile(const DataFacadeBase &facade,
{
// Calculate the speed for this line
std::uint32_t speed_kmh_idx = static_cast<std::uint32_t>(
round(length / from_alias<double>(forward_duration) * 10 * 3.6));
std::round(length / from_alias<double>(forward_duration) * 10 * 3.6));
// Rate values are in meters per weight-unit - and similar to speeds, we
// present 1 decimal place of precision (these values are added as
// double/10) lower down
std::uint32_t forward_rate = static_cast<std::uint32_t>(
round(length / from_alias<double>(forward_weight) * 10.));
std::round(length / from_alias<double>(forward_weight) * 10.));
auto tile_line = coordinatesToTileLine(a, b, tile_bbox);
if (!tile_line.empty())
@ -531,13 +531,13 @@ void encodeVectorTile(const DataFacadeBase &facade,
{
// Calculate the speed for this line
std::uint32_t speed_kmh_idx = static_cast<std::uint32_t>(
round(length / from_alias<double>(reverse_duration) * 10 * 3.6));
std::round(length / from_alias<double>(reverse_duration) * 10 * 3.6));
// Rate values are in meters per weight-unit - and similar to speeds, we
// present 1 decimal place of precision (these values are added as
// double/10) lower down
std::uint32_t reverse_rate = static_cast<std::uint32_t>(
round(length / from_alias<double>(reverse_weight) * 10.));
std::round(length / from_alias<double>(reverse_weight) * 10.));
auto tile_line = coordinatesToTileLine(b, a, tile_bbox);
if (!tile_line.empty())

View File

@ -54,8 +54,8 @@ void test_route_same_coordinates_fixture(bool use_json_only_api)
itr.get<json::Object>().values["hint"] = "";
// Round value to 6 decimal places for double comparison later
itr.get<json::Object>().values["distance"] =
round(itr.get<json::Object>().values["distance"].get<json::Number>().value * 1000000);
itr.get<json::Object>().values["distance"] = std::round(
itr.get<json::Object>().values["distance"].get<json::Number>().value * 1000000);
}
const auto location = json::Array{{{7.437070}, {43.749248}}};
@ -65,11 +65,11 @@ void test_route_same_coordinates_fixture(bool use_json_only_api)
{"waypoints",
json::Array{{json::Object{{{"name", "Boulevard du Larvotto"},
{"location", location},
{"distance", round(0.137249 * 1000000)},
{"distance", std::round(0.137249 * 1000000)},
{"hint", ""}}},
json::Object{{{"name", "Boulevard du Larvotto"},
{"location", location},
{"distance", round(0.137249 * 1000000)},
{"distance", std::round(0.137249 * 1000000)},
{"hint", ""}}}}}},
{"routes",
json::Array{{json::Object{