ADL for AlmostEqual* and use math:: instead of base:: (#9634)

* ADL for AlmostEqual* and use math:: instead of base::

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-07-07 20:49:00 +02:00
committed by Konstantin Pastbin
parent 82133c5743
commit 30718e106e
175 changed files with 542 additions and 559 deletions

View File

@@ -30,10 +30,10 @@ double const kAnglesInBucket = 360.0 / kNumBuckets;
uint32_t Bearing(m2::PointD const & a, m2::PointD const & b)
{
auto const angle = location::AngleToBearing(base::RadToDeg(ang::AngleTo(a, b)));
auto const angle = location::AngleToBearing(math::RadToDeg(ang::AngleTo(a, b)));
CHECK_LESS_OR_EQUAL(angle, 360, ("Angle should be less than or equal to 360."));
CHECK_GREATER_OR_EQUAL(angle, 0, ("Angle should be greater than or equal to 0"));
return base::Clamp(angle / kAnglesInBucket, 0.0, 255.0);
return math::Clamp(angle / kAnglesInBucket, 0.0, 255.0);
}
} // namespace cpg

View File

@@ -402,10 +402,10 @@ size_t constexpr GetOptimalBatchSize()
{
// This code computes the most optimal (in the sense of cache lines
// occupancy) batch size.
size_t constexpr a = base::LCM(sizeof(LinearSegment), kCacheLineSize) / sizeof(LinearSegment);
size_t constexpr a = math::LCM(sizeof(LinearSegment), kCacheLineSize) / sizeof(LinearSegment);
size_t constexpr b =
base::LCM(sizeof(IRoadGraph::EdgeVector), kCacheLineSize) / sizeof(IRoadGraph::EdgeVector);
return base::LCM(a, b);
math::LCM(sizeof(IRoadGraph::EdgeVector), kCacheLineSize) / sizeof(IRoadGraph::EdgeVector);
return math::LCM(a, b);
}
} // namespace

View File

@@ -105,8 +105,8 @@ bool FirstCoordinateFromXML(pugi::xml_node const & node, ms::LatLon & latLon)
if (!GetLatLon(node.child("olr:coordinate"), lat, lon))
return false;
latLon.m_lat = ((lat - base::Sign(lat) * 0.5) * 360) / (1 << 24);
latLon.m_lon = ((lon - base::Sign(lon) * 0.5) * 360) / (1 << 24);
latLon.m_lat = ((lat - math::Sign(lat) * 0.5) * 360) / (1 << 24);
latLon.m_lon = ((lon - math::Sign(lon) * 0.5) * 360) / (1 << 24);
return true;
}

View File

@@ -39,10 +39,10 @@ double const kAnglesInBucket = 360.0 / kNumBuckets;
uint32_t Bearing(m2::PointD const & a, m2::PointD const & b)
{
auto const angle = location::AngleToBearing(base::RadToDeg(ang::AngleTo(a, b)));
auto const angle = location::AngleToBearing(math::RadToDeg(ang::AngleTo(a, b)));
CHECK_LESS_OR_EQUAL(angle, 360, ("Angle should be less than or equal to 360."));
CHECK_GREATER_OR_EQUAL(angle, 0, ("Angle should be greater than or equal to 0"));
return base::Clamp(angle / kAnglesInBucket, 0.0, 255.0);
return math::Clamp(angle / kAnglesInBucket, 0.0, 255.0);
}
} // namespace
@@ -61,7 +61,7 @@ void Router::Vertex::Score::AddBearingPenalty(int expected, int actual)
ASSERT_GREATER_OR_EQUAL(actual, 0, ());
int const diff = abs(expected - actual);
double angle = base::DegToRad(std::min(diff, kNumBuckets - diff) * kAnglesInBucket);
double angle = math::DegToRad(std::min(diff, kNumBuckets - diff) * kAnglesInBucket);
m_penalty += kBearingErrorCoeff * angle * kBearingDist;
}
@@ -568,8 +568,8 @@ double Router::GetCoverage(m2::PointD const & u, m2::PointD const & v, It b, It
double const sp = DotProduct(uv, s - u) / sqlen;
double const tp = DotProduct(uv, t - u) / sqlen;
double const start = base::Clamp(std::min(sp, tp), 0.0, 1.0);
double const finish = base::Clamp(std::max(sp, tp), 0.0, 1.0);
double const start = math::Clamp(std::min(sp, tp), 0.0, 1.0);
double const finish = math::Clamp(std::max(sp, tp), 0.0, 1.0);
covs.emplace_back(start, finish);
}
@@ -627,7 +627,7 @@ double Router::GetMatchingScore(m2::PointD const & u, m2::PointD const & v, It b
cov += mercator::DistanceOnEarth(s, t);
}
return len == 0 ? 0 : base::Clamp(cov / len, 0.0, 1.0);
return len == 0 ? 0 : math::Clamp(cov / len, 0.0, 1.0);
}
template <typename It, typename Fn>

View File

@@ -36,12 +36,12 @@ double constexpr kAnglesInBucket = 360.0 / kNumBuckets;
double ToAngleInDeg(uint32_t angleInBuckets)
{
CHECK_LESS_OR_EQUAL(angleInBuckets, 255, ());
return base::Clamp(kAnglesInBucket * static_cast<double>(angleInBuckets), 0.0, 360.0);
return math::Clamp(kAnglesInBucket * static_cast<double>(angleInBuckets), 0.0, 360.0);
}
uint32_t BearingInDeg(m2::PointD const & a, m2::PointD const & b)
{
auto const angle = location::AngleToBearing(base::RadToDeg(ang::AngleTo(a, b)));
auto const angle = location::AngleToBearing(math::RadToDeg(ang::AngleTo(a, b)));
CHECK(0.0 <= angle && angle <= 360.0, (angle));
return angle;
}