Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Alexander Borsuk
94e4d69dee ADL for AlmostEqual* and use math:: instead of base::
Signed-off-by: Alexander Borsuk <me@alex.bio>
2024-11-22 23:51:10 +01:00
172 changed files with 518 additions and 534 deletions

View file

@ -132,7 +132,7 @@ void Framework::OnLocationUpdated(location::GpsInfo const & info)
void Framework::OnCompassUpdated(location::CompassInfo const & info, bool forceRedraw)
{
static double const COMPASS_THRESHOLD = base::DegToRad(1.0);
static double const COMPASS_THRESHOLD = math::DegToRad(1.0);
/// @todo Do not emit compass bearing too often.
/// Need to make more experiments in future.

View file

@ -119,30 +119,30 @@ UNIT_TEST(CacheSmoke_3)
base::CacheWithStat<uint32_t, char> cache(3); // it contains 2^3=8 elements
// 0 access, cache miss is 0
TEST(base::AlmostEqualAbs(0.0, cache.GetCacheMiss(), kEpsilon), ());
TEST(AlmostEqualAbs(0.0, cache.GetCacheMiss(), kEpsilon), ());
bool found = true;
cache.Find(1, found);
TEST(!found, ());
// 1 access, 1 miss, cache miss = 1/1 = 1
TEST(base::AlmostEqualAbs(1.0, cache.GetCacheMiss(), kEpsilon), ());
TEST(AlmostEqualAbs(1.0, cache.GetCacheMiss(), kEpsilon), ());
found = false;
cache.Find(1, found);
TEST(found, ());
// 2 access, 1 miss, cache miss = 1/2 = 0.5
TEST(base::AlmostEqualAbs(0.5, cache.GetCacheMiss(), kEpsilon), ());
TEST(AlmostEqualAbs(0.5, cache.GetCacheMiss(), kEpsilon), ());
found = false;
cache.Find(2, found);
TEST(!found, ());
// 3 access, 2 miss, cache miss = 2/3 = 0.6(6)
TEST(base::AlmostEqualAbs(2.0/3.0, cache.GetCacheMiss(), kEpsilon), ());
TEST(AlmostEqualAbs(2.0/3.0, cache.GetCacheMiss(), kEpsilon), ());
cache.Reset();
// 0 access, cache miss is 0
TEST(base::AlmostEqualAbs(0.0, cache.GetCacheMiss(), kEpsilon), ());
TEST(AlmostEqualAbs(0.0, cache.GetCacheMiss(), kEpsilon), ());
}
UNIT_TEST(CacheSmoke_4)

View file

@ -40,7 +40,7 @@ UNIT_TEST(Cancellable_Smoke)
TEST(cancellable.IsCancelled(), ());
TEST_EQUAL(cancellable.CancellationStatus(), Cancellable::Status::CancelCalled, ());
TEST(base::AlmostEqualAbs(x, 0.739, 1e-3), ());
TEST(AlmostEqualAbs(x, 0.739, 1e-3), ());
}
UNIT_TEST(Cancellable_Deadline)
@ -72,7 +72,7 @@ UNIT_TEST(Cancellable_Deadline)
TEST(cancellable.IsCancelled(), ());
TEST_EQUAL(cancellable.CancellationStatus(), Cancellable::Status::DeadlineExceeded, ());
TEST(base::AlmostEqualAbs(x, 0.739, 1e-3), ());
TEST(AlmostEqualAbs(x, 0.739, 1e-3), ());
cancellable.Cancel();
TEST(cancellable.IsCancelled(), ());

View file

@ -270,12 +270,12 @@ UNIT_TEST(LevenshteinDFA_PrefixDFASmoke)
auto generate = [](vector<char> const & alphabet, size_t size, vector<string> & result)
{
result.clear();
result.resize(base::PowUint(alphabet.size(), size));
result.resize(math::PowUint(alphabet.size(), size));
for (size_t letterNumber = 0; letterNumber < size; ++letterNumber)
{
for (size_t i = 0; i < result.size(); ++i)
{
auto const letterIndex = (i / base::PowUint(alphabet.size(), size - letterNumber - 1)) % alphabet.size();
auto const letterIndex = (i / math::PowUint(alphabet.size(), size - letterNumber - 1)) % alphabet.size();
result[i].push_back(alphabet[letterIndex]);
}
}

View file

@ -6,6 +6,10 @@
#include <boost/math/special_functions/next.hpp>
namespace math_test
{
using namespace math;
namespace
{
// Returns the next representable floating point value without using conversion to integer.
@ -29,12 +33,12 @@ void TestMaxULPs()
Float y = x;
for (unsigned int i = 0; i <= maxULPs; ++i)
{
TEST(base::AlmostEqualULPs(x, y, maxULPs), (x, y, maxULPs, x - y, dir));
TEST(AlmostEqualULPs(x, y, maxULPs), (x, y, maxULPs, x - y, dir));
Float const nextY = NextFloat(y, dir);
TEST_NOT_EQUAL(y, nextY, (i, base, dir));
y = nextY;
}
TEST(!base::AlmostEqualULPs(x, y, maxULPs), (x, y, maxULPs, x - y));
TEST(!AlmostEqualULPs(x, y, maxULPs), (x, y, maxULPs, x - y));
}
}
}
@ -43,7 +47,7 @@ void TestMaxULPs()
UNIT_TEST(PowUInt)
{
TEST_EQUAL(base::PowUint(3, 10), 59049, ());
TEST_EQUAL(PowUint(3, 10), 59049, ());
}
UNIT_TEST(AlmostEqualULPs_double)
@ -64,10 +68,10 @@ UNIT_TEST(AlmostEqualULPs_double)
TEST_ALMOST_EQUAL_ULPS(1.0/dmax, 1.0/dmax, ());
TEST_ALMOST_EQUAL_ULPS(-1.0/dmax, -1.0/dmax, ());
TEST(!base::AlmostEqualULPs(1.0, -1.0), ());
TEST(!base::AlmostEqualULPs(2.0, -2.0), ());
TEST(!base::AlmostEqualULPs(dmax, -dmax), ());
TEST(!base::AlmostEqualULPs(0.0, eps), ());
TEST(!AlmostEqualULPs(1.0, -1.0), ());
TEST(!AlmostEqualULPs(2.0, -2.0), ());
TEST(!AlmostEqualULPs(dmax, -dmax), ());
TEST(!AlmostEqualULPs(0.0, eps), ());
}
UNIT_TEST(AlmostEqualULPs_float)
@ -88,10 +92,10 @@ UNIT_TEST(AlmostEqualULPs_float)
TEST_ALMOST_EQUAL_ULPS(1.0f/dmax, 1.0f/dmax, ());
TEST_ALMOST_EQUAL_ULPS(-1.0f/dmax, -1.0f/dmax, ());
TEST(!base::AlmostEqualULPs(1.0f, -1.0f), ());
TEST(!base::AlmostEqualULPs(2.0f, -2.0f), ());
TEST(!base::AlmostEqualULPs(dmax, -dmax), ());
TEST(!base::AlmostEqualULPs(0.0f, eps), ());
TEST(!AlmostEqualULPs(1.0f, -1.0f), ());
TEST(!AlmostEqualULPs(2.0f, -2.0f), ());
TEST(!AlmostEqualULPs(dmax, -dmax), ());
TEST(!AlmostEqualULPs(0.0f, eps), ());
}
UNIT_TEST(AlmostEqual_Smoke)
@ -99,15 +103,15 @@ UNIT_TEST(AlmostEqual_Smoke)
double constexpr small = 1e-18;
double constexpr eps = 1e-10;
TEST(base::AlmostEqualAbs(0.0, 0.0 + small, eps), ());
TEST(!base::AlmostEqualRel(0.0, 0.0 + small, eps), ());
TEST(!base::AlmostEqualULPs(0.0, 0.0 + small), ());
TEST(AlmostEqualAbs(0.0, 0.0 + small, eps), ());
TEST(!AlmostEqualRel(0.0, 0.0 + small, eps), ());
TEST(!AlmostEqualULPs(0.0, 0.0 + small), ());
TEST(base::AlmostEqualAbs(1.0, 1.0 + small, eps), ());
TEST(base::AlmostEqualRel(1.0, 1.0 + small, eps), ());
TEST(base::AlmostEqualULPs(1.0, 1.0 + small), ());
TEST(AlmostEqualAbs(1.0, 1.0 + small, eps), ());
TEST(AlmostEqualRel(1.0, 1.0 + small, eps), ());
TEST(AlmostEqualULPs(1.0, 1.0 + small), ());
TEST(base::AlmostEqualRel(123456789.0, 123456780.0, 1e-7), ());
TEST(AlmostEqualRel(123456789.0, 123456780.0, 1e-7), ());
}
UNIT_TEST(AlmostEqualULPs_MaxULPs_double)
@ -135,32 +139,33 @@ UNIT_TEST(TEST_FLOAT_DOUBLE_EQUAL_macros)
UNIT_TEST(GCD)
{
TEST_EQUAL(base::GCD(6, 3), 3, ());
TEST_EQUAL(base::GCD(14, 7), 7, ());
TEST_EQUAL(base::GCD(100, 100), 100, ());
TEST_EQUAL(base::GCD(7, 3), 1, ());
TEST_EQUAL(base::GCD(8, 3), 1, ());
TEST_EQUAL(base::GCD(9, 3), 3, ());
TEST_EQUAL(GCD(6, 3), 3, ());
TEST_EQUAL(GCD(14, 7), 7, ());
TEST_EQUAL(GCD(100, 100), 100, ());
TEST_EQUAL(GCD(7, 3), 1, ());
TEST_EQUAL(GCD(8, 3), 1, ());
TEST_EQUAL(GCD(9, 3), 3, ());
}
UNIT_TEST(LCM)
{
TEST_EQUAL(base::LCM(6, 3), 6, ());
TEST_EQUAL(base::LCM(14, 7), 14, ());
TEST_EQUAL(base::LCM(100, 100), 100, ());
TEST_EQUAL(base::LCM(7, 3), 21, ());
TEST_EQUAL(base::LCM(8, 3), 24, ());
TEST_EQUAL(base::LCM(9, 3), 9, ());
TEST_EQUAL(LCM(6, 3), 6, ());
TEST_EQUAL(LCM(14, 7), 14, ());
TEST_EQUAL(LCM(100, 100), 100, ());
TEST_EQUAL(LCM(7, 3), 21, ());
TEST_EQUAL(LCM(8, 3), 24, ());
TEST_EQUAL(LCM(9, 3), 9, ());
}
UNIT_TEST(Sign)
{
TEST_EQUAL(1, base::Sign(1), ());
TEST_EQUAL(1, base::Sign(10.4), ());
TEST_EQUAL(1, Sign(1), ());
TEST_EQUAL(1, Sign(10.4), ());
TEST_EQUAL(0, base::Sign(0), ());
TEST_EQUAL(0, base::Sign(0.0), ());
TEST_EQUAL(0, Sign(0), ());
TEST_EQUAL(0, Sign(0.0), ());
TEST_EQUAL(-1, base::Sign(-11), ());
TEST_EQUAL(-1, base::Sign(-10.4), ());
TEST_EQUAL(-1, Sign(-11), ());
TEST_EQUAL(-1, Sign(-10.4), ());
}
} // namespace math_test

View file

@ -5,9 +5,6 @@
#include <cstring>
#include <limits>
namespace base
{
template <typename Float>
bool AlmostEqualULPs(Float x, Float y, uint32_t maxULPs)
{
@ -38,14 +35,12 @@ bool AlmostEqualULPs(Float x, Float y, uint32_t maxULPs)
// Calculate diff with special case to avoid IntType overflow.
UIntType diff;
if ((xInt >= 0) == (yInt >= 0))
diff = Abs(xInt - yInt);
diff = math::Abs(xInt - yInt);
else
diff = UIntType(Abs(xInt)) + UIntType(Abs(yInt));
diff = UIntType(math::Abs(xInt)) + UIntType(math::Abs(yInt));
return diff <= maxULPs;
}
template bool AlmostEqualULPs<float>(float x, float y, uint32_t maxULPs);
template bool AlmostEqualULPs<double>(double x, double y, uint32_t maxULPs);
} // namespace base

View file

@ -12,10 +12,7 @@ namespace math
double constexpr pi = 3.14159265358979323846;
double constexpr pi2 = pi / 2.0;
double constexpr pi4 = pi / 4.0;
} // namespace math
namespace base
{
template <typename T>
T Abs(T x)
{
@ -30,6 +27,7 @@ int constexpr Sign(Number const number) noexcept
{
return number == 0 ? 0 : number > 0 ? 1 : -1;
}
} // namespace math
// Compare floats or doubles for almost equality.
// maxULPs - number of closest floating point values that are considered equal.
@ -39,6 +37,7 @@ int constexpr Sign(Number const number) noexcept
// This function is deprecated. Use AlmostEqualAbs, AlmostEqualRel or AlmostEqualAbsOrRel instead.
// See https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
// for details.
// NOTE: Intentionally in the global namespace for ADL (see point2d.hpp)
template <typename Float>
bool AlmostEqualULPs(Float x, Float y, uint32_t maxULPs = 256);
@ -47,6 +46,7 @@ bool AlmostEqualULPs(Float x, Float y, uint32_t maxULPs = 256);
// The default value for eps is deliberately not provided: the intended usage
// is for the client to choose the precision according to the problem domain,
// explicitly define the precision constant and call this function.
// NOTE: Intentionally in the global namespace for ADL (see point2d.hpp)
template <typename Float>
bool AlmostEqualAbs(Float x, Float y, Float eps)
{
@ -69,6 +69,8 @@ bool AlmostEqualAbsOrRel(Float x, Float y, Float eps)
return AlmostEqualAbs(x, y, eps) || AlmostEqualRel(x, y, eps);
}
namespace math
{
template <typename Float>
Float constexpr DegToRad(Float deg)
{
@ -171,4 +173,4 @@ size_t Hash(T1 const & t1, T2 const & t2)
/// @todo Probably, we need better hash for 2 integral types.
return (std::hash<T1>()(t1) ^ (std::hash<T2>()(t2) << 1));
}
} // namespace base
} // namespace math

View file

@ -68,7 +68,7 @@ namespace math
{
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Cols; ++j)
if (base::Abs(m_data[i * Cols + j] - m(i, j)) > eps)
if (Abs(m_data[i * Cols + j] - m(i, j)) > eps)
return false;
return true;

View file

@ -23,7 +23,7 @@ public:
{
ASSERT_GREATER(m_windowSize, 0, ());
m_windowSize = windowSize;
m_removeMultiplier = base::PowUint(m_multiplier, m_windowSize - 1);
m_removeMultiplier = math::PowUint(m_multiplier, m_windowSize - 1);
#ifdef DEBUG
while (!m_queue.empty()) m_queue.pop();
#endif

View file

@ -118,13 +118,13 @@ std::pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc,
// 4. calculate the Sun's true longitude
double L = M + (1.916 * sin(base::DegToRad(M))) + (0.020 * sin(2 * base::DegToRad(M))) + 282.634;
double L = M + (1.916 * sin(math::DegToRad(M))) + (0.020 * sin(2 * math::DegToRad(M))) + 282.634;
// NOTE: L potentially needs to be adjusted into the range [0,360) by adding/subtracting 360
L = NormalizeAngle(L);
// 5a. calculate the Sun's right ascension
double RA = base::RadToDeg( atan(0.91764 * tan(base::DegToRad(L))) );
double RA = math::RadToDeg( atan(0.91764 * tan(math::DegToRad(L))) );
// NOTE: RA potentially needs to be adjusted into the range [0,360) by adding/subtracting 360
RA = NormalizeAngle(RA);
@ -140,12 +140,12 @@ std::pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc,
// 6. calculate the Sun's declination
double sinDec = 0.39782 * sin(base::DegToRad(L));
double sinDec = 0.39782 * sin(math::DegToRad(L));
double cosDec = cos(asin(sinDec));
// 7a. calculate the Sun's local hour angle
double cosH = (cos(base::DegToRad(kZenith)) - (sinDec * sin(base::DegToRad(latitude)))) / (cosDec * cos(base::DegToRad(latitude)));
double cosH = (cos(math::DegToRad(kZenith)) - (sinDec * sin(math::DegToRad(latitude)))) / (cosDec * cos(math::DegToRad(latitude)));
// if cosH > 1 then sun is never rises on this location on specified date (polar night)
// if cosH < -1 then sun is never sets on this location on specified date (polar day)
@ -163,9 +163,9 @@ std::pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc,
double H = 0;
if (sunrise)
H = 360 - base::RadToDeg(acos(cosH));
H = 360 - math::RadToDeg(acos(cosH));
else
H = base::RadToDeg(acos(cosH));
H = math::RadToDeg(acos(cosH));
H = H / 15;

View file

@ -19,7 +19,7 @@ namespace
{
bool IsEqual(double d1, double d2)
{
return base::AlmostEqualAbs(d1, d2, kMwmPointAccuracy);
return AlmostEqualAbs(d1, d2, kMwmPointAccuracy);
}
bool IsEqual(m2::PointD const & p1, m2::PointD const & p2)

View file

@ -102,7 +102,7 @@ UNIT_TEST(PointDToPointU_WithLimitRect)
auto const pt = m2::PointD(distX(rng), distY(rng));
auto const pointU = PointDToPointU(pt, coordBits, limitRect);
auto const pointD = PointUToPointD(pointU, coordBits, limitRect);
TEST(base::AlmostEqualAbs(pt, pointD, kEps), (limitRect, pt, pointD, coordBits, kEps));
TEST(AlmostEqualAbs(pt, pointD, kEps), (limitRect, pt, pointD, coordBits, kEps));
}
}
}

View file

@ -12,10 +12,10 @@
#include <cstdint>
#include <vector>
using namespace std;
namespace coding
namespace traffic_test
{
using std::vector;
double CalculateLength(vector<TrafficGPSEncoder::DataPoint> const & path)
{
double res = 0;
@ -30,7 +30,7 @@ double CalculateLength(vector<TrafficGPSEncoder::DataPoint> const & path)
void Test(vector<TrafficGPSEncoder::DataPoint> & points)
{
double const kEps = 1e-5;
double constexpr kEps = 1e-5;
for (uint32_t version = 0; version <= TrafficGPSEncoder::kLatestVersion; ++version)
{
@ -48,9 +48,9 @@ void Test(vector<TrafficGPSEncoder::DataPoint> & points)
{
TEST_EQUAL(points[i].m_timestamp, result[i].m_timestamp,
(points[i].m_timestamp, result[i].m_timestamp));
TEST(base::AlmostEqualAbsOrRel(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat, kEps),
TEST(AlmostEqualAbsOrRel(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat, kEps),
(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat));
TEST(base::AlmostEqualAbsOrRel(points[i].m_latLon.m_lon, result[i].m_latLon.m_lon, kEps),
TEST(AlmostEqualAbsOrRel(points[i].m_latLon.m_lon, result[i].m_latLon.m_lon, kEps),
(points[i].m_latLon.m_lon, result[i].m_latLon.m_lon));
}
@ -150,4 +150,4 @@ UNIT_TEST(Traffic_Serialization_ExtremeLatLon)
};
Test(path);
}
} // namespace coding
} // namespace traffic_test

View file

@ -14,8 +14,8 @@ namespace
inline m2::PointU ClampPoint(m2::PointD const & maxPoint, m2::PointD const & point)
{
using uvalue_t = m2::PointU::value_type;
return { static_cast<uvalue_t>(base::Clamp(point.x, 0.0, maxPoint.x)),
static_cast<uvalue_t>(base::Clamp(point.y, 0.0, maxPoint.y)) };
return { static_cast<uvalue_t>(math::Clamp(point.x, 0.0, maxPoint.x)),
static_cast<uvalue_t>(math::Clamp(point.y, 0.0, maxPoint.y)) };
}
struct edge_less_p0

View file

@ -50,7 +50,7 @@ double Uint32ToDouble(uint32_t x, double min, double max, uint8_t coordBits)
// It doesn't work because of possible floating errors.
//ASSERT(d >= min && d <= max, (d, x, min, max, coordBits));
return base::Clamp(d, min, max);
return math::Clamp(d, min, max);
}
m2::PointU PointDToPointU(double x, double y, uint8_t coordBits)

View file

@ -13,7 +13,7 @@ uint8_t constexpr kFeatureSorterPointCoordBits = 27;
// The absolute precision of the point encoding in the mwm files.
// If both x and y coordinates of two points lie within |kMwmPointAccuracy| of one
// another we consider the points equal. In other words, |kMwmPointAccuracy| may
// be used as the eps value for both x and y in Point::EqualDxDy, base::AlmostEqualAbs and such.
// be used as the eps value for both x and y in Point::EqualDxDy, AlmostEqualAbs and such.
//
// The constant is loosely tied to mercator::Bounds::kRangeX / (1 << kPointCoordBits):
// The range of possible values for point coordinates

View file

@ -38,9 +38,9 @@ struct Color
constexpr Color operator*(float s) const
{
return {static_cast<uint8_t>(base::Clamp(GetRedF() * s, 0.0f, 1.0f) * 255.0f),
static_cast<uint8_t>(base::Clamp(GetGreenF() * s, 0.0f, 1.0f) * 255.0f),
static_cast<uint8_t>(base::Clamp(GetBlueF() * s, 0.0f, 1.0f) * 255.0f), GetAlpha()};
return {static_cast<uint8_t>(math::Clamp(GetRedF() * s, 0.0f, 1.0f) * 255.0f),
static_cast<uint8_t>(math::Clamp(GetGreenF() * s, 0.0f, 1.0f) * 255.0f),
static_cast<uint8_t>(math::Clamp(GetBlueF() * s, 0.0f, 1.0f) * 255.0f), GetAlpha()};
}
constexpr static Color Black() { return {0, 0, 0, 255}; }

View file

@ -11,7 +11,7 @@ namespace dp
CPUBuffer::CPUBuffer(uint8_t elementSize, uint32_t capacity)
: TBase(elementSize, capacity)
{
uint32_t memorySize = base::NextPowOf2(GetCapacity() * GetElementSize());
uint32_t memorySize = math::NextPowOf2(GetCapacity() * GetElementSize());
m_memory = SharedBufferManager::instance().reserveSharedBuffer(memorySize);
m_memoryCursor = NonConstData();
}

View file

@ -21,10 +21,10 @@ void TestPacker(StipplePenPacker & packer, uint32_t width, m2::RectU const & exp
bool IsRectsEqual(m2::RectF const & r1, m2::RectF const & r2)
{
return base::AlmostEqualULPs(r1.minX(), r2.minX()) &&
base::AlmostEqualULPs(r1.minY(), r2.minY()) &&
base::AlmostEqualULPs(r1.maxX(), r2.maxX()) &&
base::AlmostEqualULPs(r1.maxY(), r2.maxY());
return AlmostEqualULPs(r1.minX(), r2.minX()) &&
AlmostEqualULPs(r1.minY(), r2.minY()) &&
AlmostEqualULPs(r1.maxX(), r2.maxX()) &&
AlmostEqualULPs(r1.maxY(), r2.maxY());
}
} // namespace

View file

@ -195,7 +195,7 @@ void StipplePenIndex::UploadResources(ref_ptr<dp::GraphicsContext> context, ref_
for (auto const & n : pendingNodes)
height += n.second.GetSize().y;
uint32_t const reserveBufferSize = base::NextPowOf2(height * kMaxStipplePenLength);
uint32_t const reserveBufferSize = math::NextPowOf2(height * kMaxStipplePenLength);
SharedBufferManager & mng = SharedBufferManager::instance();
SharedBufferManager::shared_buffer_ptr_t ptr = mng.reserveSharedBuffer(reserveBufferSize);

View file

@ -56,7 +56,7 @@ void ParseColorsList(std::string const & colorsFile, ToDo toDo)
m2::PointU StipplePenTextureSize(size_t patternsCount, uint32_t maxTextureSize)
{
uint32_t const sz = base::NextPowOf2(static_cast<uint32_t>(patternsCount) + kReservedPatterns);
uint32_t const sz = math::NextPowOf2(static_cast<uint32_t>(patternsCount) + kReservedPatterns);
// No problem if assert will fire here. Just pen texture will be 2x bigger :)
//ASSERT_LESS_OR_EQUAL(sz, kMinStippleTextureHeight, (patternsCount));
uint32_t const stippleTextureHeight = std::min(maxTextureSize, std::max(sz, kMinStippleTextureHeight));
@ -69,7 +69,7 @@ m2::PointU ColorTextureSize(size_t colorsCount, uint32_t maxTextureSize)
uint32_t const sz = static_cast<uint32_t>(floor(sqrt(colorsCount + kReservedColors)));
// No problem if assert will fire here. Just color texture will be 2x bigger :)
ASSERT_LESS_OR_EQUAL(sz, kMinColorTextureSize, (colorsCount));
uint32_t colorTextureSize = std::max(base::NextPowOf2(sz), kMinColorTextureSize);
uint32_t colorTextureSize = std::max(math::NextPowOf2(sz), kMinColorTextureSize);
colorTextureSize *= ColorTexture::GetColorSizeInPixels();
colorTextureSize = std::min(maxTextureSize, colorTextureSize);

View file

@ -144,7 +144,7 @@ void ColorPalette::UploadResources(ref_ptr<dp::GraphicsContext> context, ref_ptr
size_t const pixelStride = uploadRect.SizeX();
size_t const byteCount = kBytesPerPixel * uploadRect.SizeX() * uploadRect.SizeY();
size_t const bufferSize = static_cast<size_t>(base::NextPowOf2(static_cast<uint32_t>(byteCount)));
size_t const bufferSize = static_cast<size_t>(math::NextPowOf2(static_cast<uint32_t>(byteCount)));
SharedBufferManager::shared_buffer_ptr_t buffer = SharedBufferManager::instance().reserveSharedBuffer(bufferSize);
uint8_t * pointer = SharedBufferManager::GetRawPointer(buffer);

View file

@ -125,20 +125,20 @@ uint32_t VulkanMemoryManager::GetOffsetAlignment(ResourceType resourceType) cons
if (resourceType == ResourceType::Uniform)
{
static uint32_t const kUniformAlignment =
base::LCM(static_cast<uint32_t>(m_deviceLimits.minUniformBufferOffsetAlignment),
math::LCM(static_cast<uint32_t>(m_deviceLimits.minUniformBufferOffsetAlignment),
static_cast<uint32_t>(m_deviceLimits.nonCoherentAtomSize));
return kUniformAlignment;
}
static uint32_t const kAlignment =
base::LCM(static_cast<uint32_t>(m_deviceLimits.minMemoryMapAlignment),
math::LCM(static_cast<uint32_t>(m_deviceLimits.minMemoryMapAlignment),
static_cast<uint32_t>(m_deviceLimits.nonCoherentAtomSize));
return kAlignment;
}
uint32_t VulkanMemoryManager::GetSizeAlignment(VkMemoryRequirements const & memReqs) const
{
return base::LCM(static_cast<uint32_t>(memReqs.alignment),
return math::LCM(static_cast<uint32_t>(memReqs.alignment),
static_cast<uint32_t>(m_deviceLimits.nonCoherentAtomSize));
}

View file

@ -12,7 +12,7 @@ double CalcAnimSpeedDuration(double pxDiff, double pxSpeed)
{
double constexpr kEps = 1e-5;
if (base::AlmostEqualAbs(pxDiff, 0.0, kEps))
if (AlmostEqualAbs(pxDiff, 0.0, kEps))
return 0.0;
return fabs(pxDiff) / pxSpeed;

View file

@ -774,7 +774,7 @@ ApplyLineFeatureGeometry::ApplyLineFeatureGeometry(TileKey const & tileKey, TIns
: TBase(tileKey, insertShape, f, CaptionDescription())
, m_currentScaleGtoP(currentScaleGtoP)
// TODO(pastk) : calculate just once in the RuleDrawer.
, m_minSegmentSqrLength(base::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale() / currentScaleGtoP))
, m_minSegmentSqrLength(math::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale() / currentScaleGtoP))
, m_simplify(tileKey.m_zoomLevel >= 10 && tileKey.m_zoomLevel <= 12)
{
m_spline.Reset(new m2::Spline(f.GetPointsCount()));

View file

@ -61,8 +61,8 @@ namespace
P const & pxP = arr[i];
P const gP = nav.PtoG(pxP);
P const pxP2 = nav.GtoP(gP);
TEST(base::AlmostEqualAbs(pxP.x, pxP2.x, 0.00001), (pxP.x, pxP2.x));
TEST(base::AlmostEqualAbs(pxP.y, pxP2.y, 0.00001), (pxP.y, pxP2.y));
TEST(AlmostEqualAbs(pxP.x, pxP2.x, 0.00001), (pxP.x, pxP2.x));
TEST(AlmostEqualAbs(pxP.y, pxP2.y, 0.00001), (pxP.y, pxP2.y));
}
}
}

View file

@ -145,7 +145,7 @@ dp::Color GpsTrackRenderer::CalculatePointColor(size_t pointIndex, m2::PointD co
endAlpha = kMaxNightAlpha;
}
double const ta = base::Clamp(lengthFromStart / fullLength, 0.0, 1.0);
double const ta = math::Clamp(lengthFromStart / fullLength, 0.0, 1.0);
double const alpha = startAlpha * (1.0 - ta) + endAlpha * ta;
if ((end.m_timestamp - start.m_timestamp) > kUnknownDistanceTime)
@ -157,7 +157,7 @@ dp::Color GpsTrackRenderer::CalculatePointColor(size_t pointIndex, m2::PointD co
double const length = (end.m_point - start.m_point).Length();
double const dist = (curPoint - start.m_point).Length();
double const td = base::Clamp(dist / length, 0.0, 1.0);
double const td = math::Clamp(dist / length, 0.0, 1.0);
double const speed = std::max(start.m_speedMPS * (1.0 - td) + end.m_speedMPS * td, 0.0);
dp::Color const color = GetColorBySpeed(speed);

View file

@ -51,8 +51,8 @@ public:
bool Update(ScreenBase const & screen) override
{
static double const kVisibleStartAngle = base::DegToRad(5.0);
static double const kVisibleEndAngle = base::DegToRad(355.0);
static double const kVisibleStartAngle = math::DegToRad(5.0);
static double const kVisibleEndAngle = math::DegToRad(355.0);
auto const angle = static_cast<float>(ang::AngleIn2PI(screen.GetAngle()));

View file

@ -113,7 +113,7 @@ RulerHelper::RulerHelper()
void RulerHelper::Update(ScreenBase const & screen)
{
m2::PointD pivot = screen.PixelRect().Center();
int const minPxWidth = base::SignedRound(kMinPixelWidth * df::VisualParams::Instance().GetVisualScale());
int const minPxWidth = math::SignedRound(kMinPixelWidth * df::VisualParams::Instance().GetVisualScale());
m2::PointD pt1 = screen.PtoG(pivot);
m2::PointD pt0 = screen.PtoG(pivot - m2::PointD(minPxWidth, 0));
@ -133,7 +133,7 @@ void RulerHelper::Update(ScreenBase const & screen)
double const a = ang::AngleTo(pt1, pt0);
pt0 = mercator::GetSmPoint(pt1, cos(a) * metersDiff, sin(a) * metersDiff);
m_pixelLength = base::SignedRound(pivot.Length(screen.GtoP(pt0)));
m_pixelLength = math::SignedRound(pivot.Length(screen.GtoP(pt0)));
}
int drawScale = df::GetDrawTileScale(screen);

View file

@ -264,7 +264,7 @@ float GetProjectionLength(glsl::vec2 const & newPoint, glsl::vec2 const & startP
glsl::vec2 const v2 = newPoint - startPoint;
float const squareLen = glsl::dot(v1, v1);
float const proj = glsl::dot(v1, v2) / squareLen;
return sqrt(squareLen) * base::Clamp(proj, 0.0f, 1.0f);
return sqrt(squareLen) * math::Clamp(proj, 0.0f, 1.0f);
}
} // namespace df

View file

@ -428,7 +428,7 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
if ((!m_isCompassAvailable || glueArrowInRouting || isMovingFast) && info.HasBearing())
{
SetDirection(base::DegToRad(info.m_bearing));
SetDirection(math::DegToRad(info.m_bearing));
m_lastGPSBearingTimer.Reset();
}
@ -614,7 +614,7 @@ bool MyPositionController::AlmostCurrentPosition(m2::PointD const & pos) const
bool MyPositionController::AlmostCurrentAzimut(double azimut) const
{
double constexpr kDirectionEqualityDelta = 1e-3;
return base::AlmostEqualAbs(azimut, m_drawDirection, kDirectionEqualityDelta);
return AlmostEqualAbs(azimut, m_drawDirection, kDirectionEqualityDelta);
}
void MyPositionController::SetDirection(double bearing)

View file

@ -666,8 +666,8 @@ void RouteShape::BatchGeometry(ref_ptr<dp::GraphicsContext> context, dp::RenderS
uint32_t constexpr kMaxBatchSize = 65000;
uint32_t constexpr kIndicesScalar = 2;
verticesCount = base::Clamp(verticesCount, kMinBatchSize, kMaxBatchSize);
auto const indicesCount = base::Clamp(verticesCount * kIndicesScalar, kMinBatchSize, kMaxBatchSize);
verticesCount = math::Clamp(verticesCount, kMinBatchSize, kMaxBatchSize);
auto const indicesCount = math::Clamp(verticesCount * kIndicesScalar, kMinBatchSize, kMaxBatchSize);
dp::Batcher batcher(indicesCount, verticesCount);
batcher.SetBatcherHash(static_cast<uint64_t>(BatcherBucket::Routing));

View file

@ -323,7 +323,7 @@ bool TrafficRenderer::CanBeRenderedAsLine(RoadClass const & roadClass, int zoomL
if (it == lineDrawerEnd)
return false;
width = std::max(1, base::SignedRound(TrafficRenderer::GetPixelWidthInternal(roadClass, zoomLevel)));
width = std::max(1, math::SignedRound(TrafficRenderer::GetPixelWidthInternal(roadClass, zoomLevel)));
return width <= dp::SupportManager::Instance().GetMaxLineWidth();
}
} // namespace df

View file

@ -851,8 +851,8 @@ void UpdateShapeInfos(std::vector<ShapeInfoPT> & shapeInfos, m2::PointD const &
for (ShapeInfoPT & info : shapeInfos)
{
if (base::AlmostEqualAbs(info.m_direction, newDir, kEps) ||
base::AlmostEqualAbs(info.m_direction, newDirReverse, kEps))
if (AlmostEqualAbs(info.m_direction, newDir, kEps) ||
AlmostEqualAbs(info.m_direction, newDirReverse, kEps))
{
for (auto const & color : colors)
info.m_colors.insert(color);
@ -1249,7 +1249,7 @@ bool StopHasMultipleShapes(std::vector<ShapeInfoPT> const & shapeInfosIn,
{
auto const it =
std::find_if(shapeInfosOut.begin(), shapeInfosOut.end(), [&si](ShapeInfoPT const & so) {
return base::AlmostEqualAbs(si.m_direction, so.m_direction, kEps);
return AlmostEqualAbs(si.m_direction, so.m_direction, kEps);
});
if (it != shapeInfosOut.end())
++count;

View file

@ -144,7 +144,7 @@ UserEventStream::UserEventStream()
, m_animationSystem(AnimationSystem::Instance())
, m_startDragOrg(m2::PointD::Zero())
, m_startDoubleTapAndHold(m2::PointD::Zero())
, m_dragThreshold(base::Pow2(VisualParams::Instance().GetDragThreshold()))
, m_dragThreshold(math::Pow2(VisualParams::Instance().GetDragThreshold()))
{
}

View file

@ -549,7 +549,7 @@ void CacheUserLines(ref_ptr<dp::GraphicsContext> context, TileKey const & tileKe
// This var is used only if simplify == true.
double minSegmentSqrLength = 1.0;
if (simplify)
minSegmentSqrLength = base::Pow2(4.0 * vs * GetScreenScale(tileKey.m_zoomLevel));
minSegmentSqrLength = math::Pow2(4.0 * vs * GetScreenScale(tileKey.m_zoomLevel));
m2::RectD const tileRect = tileKey.GetGlobalRect();

View file

@ -61,7 +61,7 @@ double VisualParams::GetFontScale() const
void VisualParams::SetFontScale(double fontScale)
{
ASSERT_INITED;
m_fontScale = base::Clamp(fontScale, 0.5, 2.0);
m_fontScale = math::Clamp(fontScale, 0.5, 2.0);
}
void VisualParams::SetVisualScale(double visualScale)
@ -186,7 +186,7 @@ int GetTileScaleBase(m2::RectD const & r)
{
double const sz = std::max(r.SizeX(), r.SizeY());
ASSERT_GREATER(sz, 0., ("Rect should not be a point:", r));
return std::max(1, base::SignedRound(std::log2(mercator::Bounds::kRangeX / sz)));
return std::max(1, math::SignedRound(std::log2(mercator::Bounds::kRangeX / sz)));
}
double GetTileScaleBase(double drawScale)
@ -224,12 +224,12 @@ m2::RectD GetRectForDrawScale(int drawScale, m2::PointD const & center)
m2::RectD GetRectForDrawScale(double drawScale, m2::PointD const & center, uint32_t tileSize, double visualScale)
{
return GetRectForDrawScale(base::SignedRound(drawScale), center, tileSize, visualScale);
return GetRectForDrawScale(math::SignedRound(drawScale), center, tileSize, visualScale);
}
m2::RectD GetRectForDrawScale(double drawScale, m2::PointD const & center)
{
return GetRectForDrawScale(base::SignedRound(drawScale), center);
return GetRectForDrawScale(math::SignedRound(drawScale), center);
}
uint32_t CalculateTileSize(uint32_t screenWidth, uint32_t screenHeight)
@ -257,9 +257,9 @@ uint32_t CalculateTileSize(uint32_t screenWidth, uint32_t screenHeight)
}
#ifndef OMIM_OS_DESKTOP
return static_cast<uint32_t>(base::Clamp(res / 2, 256, 1024));
return static_cast<uint32_t>(math::Clamp(res / 2, 256, 1024));
#else
return static_cast<uint32_t>(base::Clamp(res / 2, 512, 1024));
return static_cast<uint32_t>(math::Clamp(res / 2, 512, 1024));
#endif
}
@ -312,7 +312,7 @@ void ExtractZoomFactors(ScreenBase const & s, double & zoom, int & index, float
double GetNormalizedZoomLevel(double screenScale, int minZoom)
{
double const kMaxZoom = scales::GetUpperStyleScale() + 1.0;
return base::Clamp((GetZoomLevel(screenScale) - minZoom) / (kMaxZoom - minZoom), 0.0, 1.0);
return math::Clamp((GetZoomLevel(screenScale) - minZoom) / (kMaxZoom - minZoom), 0.0, 1.0);
}
double GetScreenScale(double zoomLevel)
@ -330,7 +330,7 @@ double GetZoomLevel(double screenScale)
auto const pxLen = static_cast<double>(p.GetTileSize());
auto const len = pxLen * screenScale;
auto const factor = mercator::Bounds::kRangeX / len;
return base::Clamp(GetDrawTileScale(fabs(std::log2(factor))), 1.0, scales::GetUpperStyleScale() + 1.0);
return math::Clamp(GetDrawTileScale(fabs(std::log2(factor))), 1.0, scales::GetUpperStyleScale() + 1.0);
}
float CalculateRadius(ScreenBase const & screen, ArrayView<float> const & zoom2radius)

View file

@ -190,7 +190,7 @@ OsmOAuth::Response ServerApi06::GetXmlFeaturesAtLatLon(double lat, double lon, d
double const latDegreeOffset = radiusInMeters * mercator::Bounds::kDegreesInMeter;
double const minLat = std::max(-90.0, lat - latDegreeOffset);
double const maxLat = std::min( 90.0, lat + latDegreeOffset);
double const cosL = std::max(cos(base::DegToRad(std::max(fabs(minLat), fabs(maxLat)))), 0.00001);
double const cosL = std::max(cos(math::DegToRad(std::max(fabs(minLat), fabs(maxLat)))), 0.00001);
double const lonDegreeOffset = radiusInMeters * mercator::Bounds::kDegreesInMeter / cosL;
double const minLon = std::max(-180.0, lon - lonDegreeOffset);
double const maxLon = std::min( 180.0, lon + lonDegreeOffset);

View file

@ -76,7 +76,7 @@ bool ConvergenceTest(double lat, double lon, double latEps, double lonEps)
ge0::LatLonToString(tmpLat, tmpLon, urlPrefix + 0, 9);
parser.DecodeLatLon(urlPrefix, tmpLat, tmpLon);
}
return base::AlmostEqualAbs(lat, tmpLat, latEps) && base::AlmostEqualAbs(lon, tmpLon, lonEps);
return AlmostEqualAbs(lat, tmpLat, latEps) && AlmostEqualAbs(lon, tmpLon, lonEps);
}
UNIT_TEST(Base64DecodingWorksForAValidChar)

View file

@ -87,7 +87,7 @@ public:
std::vector<m2::PointD> out;
/// @todo Choose scale level for simplification.
SimplifyDefault(in.begin(), in.end(), base::Pow2(scales::GetEpsilonForSimplify(10)), out);
SimplifyDefault(in.begin(), in.end(), math::Pow2(scales::GetEpsilonForSimplify(10)), out);
serial::SaveOuterPath(out, cp, *w);
}

View file

@ -70,12 +70,12 @@ public:
explicit ContainsCompareFn(double eps) : m_eps(eps), m_squareEps(eps*eps) {}
bool EqualPoints(m2::PointD const & p1, m2::PointD const & p2) const
{
return base::AlmostEqualAbs(p1.x, p2.x, m_eps) &&
base::AlmostEqualAbs(p1.y, p2.y, m_eps);
return AlmostEqualAbs(p1.x, p2.x, m_eps) &&
AlmostEqualAbs(p1.y, p2.y, m_eps);
}
bool EqualZeroSquarePrecision(double val) const
{
return base::AlmostEqualAbs(val, 0.0, m_squareEps);
return AlmostEqualAbs(val, 0.0, m_squareEps);
}
};

View file

@ -36,7 +36,7 @@ struct hash<generator::CompositeId>
{
size_t operator()(generator::CompositeId const & id) const
{
return base::Hash(id.m_mainId, id.m_additionalId);
return math::Hash(id.m_mainId, id.m_additionalId);
}
};
} // namespace std

View file

@ -29,7 +29,7 @@ namespace
{
bool IsEqual(double d1, double d2)
{
return base::AlmostEqualAbs(d1, d2, kMwmPointAccuracy);
return AlmostEqualAbs(d1, d2, kMwmPointAccuracy);
}
bool IsEqual(m2::PointD const & p1, m2::PointD const & p2)

View file

@ -68,10 +68,10 @@ public:
// p is close to the borders of |m_rect|, in which case returns a very large number.
double operator()(m2::PointD const & a, m2::PointD const & b, m2::PointD const & p) const
{
if (base::AlmostEqualAbs(p.x, m_rect.minX(), m_eps) ||
base::AlmostEqualAbs(p.x, m_rect.maxX(), m_eps) ||
base::AlmostEqualAbs(p.y, m_rect.minY(), m_eps) ||
base::AlmostEqualAbs(p.y, m_rect.maxY(), m_eps))
if (AlmostEqualAbs(p.x, m_rect.minX(), m_eps) ||
AlmostEqualAbs(p.x, m_rect.maxX(), m_eps) ||
AlmostEqualAbs(p.y, m_rect.minY(), m_eps) ||
AlmostEqualAbs(p.y, m_rect.maxY(), m_eps))
{
// Points near rect should be in a result simplified vector.
return std::numeric_limits<double>::max();
@ -96,7 +96,7 @@ void SimplifyPoints(DistanceFn distFn, int level, PointsContainer const & in, Po
if (in.size() < 2)
return;
double const eps = base::Pow2(scales::GetEpsilonForSimplify(level));
double const eps = math::Pow2(scales::GetEpsilonForSimplify(level));
SimplifyNearOptimal(20, in.begin(), in.end(), eps, distFn,
AccumulateSkipSmallTrg<DistanceFn, m2::PointD>(distFn, out, eps));

View file

@ -97,7 +97,7 @@ bool LinearLeastSquaresFactors(std::vector<double> const & xs, std::vector<doubl
mx2 += xs[i] * xs[i] / n;
}
if (base::AlmostEqualAbs(mx * mx, mx2, kEpsilon))
if (AlmostEqualAbs(mx * mx, mx2, kEpsilon))
return false;
k = (my * mx - mxy) / (mx * mx - mx2);

View file

@ -126,7 +126,7 @@ bool CheckPostcodeExists(unordered_map<string, vector<m2::PointD>> const & data,
for (size_t i = 0; i < geometry.size(); ++i)
{
if (!m2::AlmostEqualAbs(geometry[i], it->second[i], kMwmPointAccuracy))
if (!AlmostEqualAbs(geometry[i], it->second[i], kMwmPointAccuracy))
return false;
}

View file

@ -123,7 +123,7 @@ bool CheckPolygonExistance(std::vector<std::vector<m2::PointD>> const & polygons
for (size_t i = 0; i < polygon.size(); ++i)
{
if (!m2::AlmostEqualAbs(polygon[i], polygonToFind[i], 1e-6))
if (!AlmostEqualAbs(polygon[i], polygonToFind[i], 1e-6))
{
same = false;
break;
@ -262,7 +262,7 @@ UNIT_TEST(AreaOnEarth_Convex_Polygon_1)
double const areaOnEarth = generator::AreaOnEarth(points);
TEST(base::AlmostEqualRel(areaTriangulated,
TEST(AlmostEqualRel(areaTriangulated,
areaOnEarth,
1e-6), (areaTriangulated, areaOnEarth));
}
@ -286,7 +286,7 @@ UNIT_TEST(AreaOnEarth_Convex_Polygon_2)
double const areaOnEarth = generator::AreaOnEarth(points);
double const areaForConvexPolygon = CalculateEarthAreaForConvexPolygon(latlons);
TEST(base::AlmostEqualRel(areaForConvexPolygon,
TEST(AlmostEqualRel(areaForConvexPolygon,
areaOnEarth,
1e-6), (areaForConvexPolygon, areaOnEarth));
}
@ -319,7 +319,7 @@ UNIT_TEST(AreaOnEarth_Concave_Polygon)
double const areaOnEarth = generator::AreaOnEarth(points);
TEST(base::AlmostEqualRel(areaTriangulated,
TEST(AlmostEqualRel(areaTriangulated,
areaOnEarth,
1e-6), ());
}

View file

@ -55,12 +55,12 @@ void TestRunCmpPoints(std::vector<m2::PointD> const & pointsFact,
TEST_EQUAL(pointsFact.size(), pointsPlan.size(), ());
TEST_GREATER(pointsFact.size(), 2, ());
for (size_t i = 0; i < pointsFact.size(); ++i)
TEST(m2::AlmostEqualAbs(pointsFact[i], pointsPlan[i], kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(pointsFact[i], pointsPlan[i], kMwmPointAccuracy), ());
}
void TestRunCmpNumbers(double val1, double val2)
{
TEST(base::AlmostEqualAbs(val1, val2, kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(val1, val2, kMwmPointAccuracy), ());
}
UNIT_TEST(PointToPolygon_GeneralProperties)
@ -81,10 +81,10 @@ UNIT_TEST(PointToPolygon_GeneralProperties)
for (size_t i = 0; i < circlePlain.size() - 1; ++i)
{
double const rCurrent = DistanceOnPlain(circlePlain[i], center);
TEST(base::AlmostEqualAbs(rCurrent, r, kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(rCurrent, r, kMwmPointAccuracy), ());
double const vertexLengthCurrent = DistanceOnPlain(circlePlain[i], circlePlain[i + 1]);
TEST(base::AlmostEqualAbs(vertexLengthCurrent, vertexLenght, kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(vertexLengthCurrent, vertexLenght, kMwmPointAccuracy), ());
}
}
}
@ -97,7 +97,7 @@ UNIT_TEST(TrimSegment_Vertical)
double const dist = 1.0;
m2::PointD const point = GetPointAtDistFromTarget(a /* source */, b /* target */, dist);
m2::PointD const pointPlan(2.0, 2.0);
TEST(m2::AlmostEqualAbs(point, pointPlan, kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(point, pointPlan, kMwmPointAccuracy), ());
}
UNIT_TEST(TrimSegment_VerticalNegative)
@ -107,7 +107,7 @@ UNIT_TEST(TrimSegment_VerticalNegative)
double const dist = 4.0;
m2::PointD const point = GetPointAtDistFromTarget(a /* source */, b /* target */, dist);
m2::PointD const pointPlan(-3.0, 2.0);
TEST(m2::AlmostEqualAbs(point, pointPlan, kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(point, pointPlan, kMwmPointAccuracy), ());
}
UNIT_TEST(TrimSegment_ExceptionalCase)
@ -116,7 +116,7 @@ UNIT_TEST(TrimSegment_ExceptionalCase)
m2::PointD const b(2.0, 3.0);
double const dist = 10.0;
m2::PointD const point = GetPointAtDistFromTarget(a /* source */, b /* target */, dist);
TEST(m2::AlmostEqualAbs(point, a, kMwmPointAccuracy), ());
TEST(AlmostEqualAbs(point, a, kMwmPointAccuracy), ());
}
UNIT_TEST(PointToCircle_ZeroMeridian)
@ -192,19 +192,19 @@ UNIT_TEST(Manage_MiniRoundabout_1Road)
// Check for "diameters" equality.
double const diameter = r * 2.;
TEST(base::AlmostEqualAbs(DistanceOnPlain(circlePlain[0], circlePlain[3]), diameter,
TEST(AlmostEqualAbs(DistanceOnPlain(circlePlain[0], circlePlain[3]), diameter,
kMwmPointAccuracy),
());
TEST(base::AlmostEqualAbs(DistanceOnPlain(circlePlain[1], circlePlain[4]), diameter,
TEST(AlmostEqualAbs(DistanceOnPlain(circlePlain[1], circlePlain[4]), diameter,
kMwmPointAccuracy),
());
TEST(base::AlmostEqualAbs(DistanceOnPlain(circlePlain[2], circlePlain[5]), diameter,
TEST(AlmostEqualAbs(DistanceOnPlain(circlePlain[2], circlePlain[5]), diameter,
kMwmPointAccuracy),
());
double const edgeLen = DistanceOnPlain(circlePlain[0], circlePlain[1]);
for (size_t i = 1; i < circlePlain.size(); ++i)
TEST(base::AlmostEqualAbs(DistanceOnPlain(circlePlain[i - 1], circlePlain[i]), edgeLen,
TEST(AlmostEqualAbs(DistanceOnPlain(circlePlain[i - 1], circlePlain[i]), edgeLen,
kMwmPointAccuracy),
());

View file

@ -31,8 +31,8 @@ UNIT_TEST(OSM_O5M_Source_Node_read_test)
TEST_EQUAL(em.uid, 395071, ());
TEST_EQUAL(em.version, 8, ());
TEST_EQUAL(em.changeset, 12059128, ());
TEST(base::AlmostEqualAbs(em.lon, 38.7666704, 1e-7), ());
TEST(base::AlmostEqualAbs(em.lat, 55.0927062, 1e-7), ());
TEST(AlmostEqualAbs(em.lon, 38.7666704, 1e-7), ());
TEST(AlmostEqualAbs(em.lat, 55.0927062, 1e-7), ());
auto const tags = em.Tags();
auto tagIterator = tags.begin();

View file

@ -928,7 +928,7 @@ UNIT_TEST(MiniRoundabout_Connectivity)
{
for (auto const & p : roundabout)
{
if (m2::AlmostEqualAbs(p, pt, kMwmPointAccuracy))
if (AlmostEqualAbs(p, pt, kMwmPointAccuracy))
return true;
}
return false;

View file

@ -97,7 +97,7 @@ void CheckCameraMapsEquality(CameraMap const & lhs, CameraMap const & rhs, doubl
// It can differ on Jenknins and local computer.
TEST_EQUAL(vectorL[i].first.GetPointId(), vectorR[i].first.GetPointId(), ());
TEST_EQUAL(vectorL[i].second.m_maxSpeedKmPH, vectorR[i].second.m_maxSpeedKmPH, ());
TEST(base::AlmostEqualAbs(vectorL[i].second.m_coef, vectorR[i].second.m_coef, epsilon), ());
TEST(AlmostEqualAbs(vectorL[i].second.m_coef, vectorR[i].second.m_coef, epsilon), ());
}
}
@ -352,7 +352,7 @@ UNIT_TEST(SpeedCameraGenerationTest_CameraIsNearFeature_1)
auto epsilon = mercator::DistanceOnEarth({0, 0}, {kMwmPointAccuracy, kMwmPointAccuracy}) /
mercator::DistanceOnEarth(mercator::FromLatLon(55.7793100, 37.3699100),
mercator::FromLatLon(55.7793300, 37.3699300));
epsilon = base::Clamp(epsilon, 0.0, 1.0);
epsilon = math::Clamp(epsilon, 0.0, 1.0);
CameraMap const answer = {
{SegmentCoord(0, 0), std::vector<RouteSegment::SpeedCamera>{{0.5, 100}}}};
TestSpeedCameraSectionBuilding(osmContent, answer, epsilon);
@ -389,7 +389,7 @@ UNIT_TEST(SpeedCameraGenerationTest_CameraIsNearFeature_2)
auto epsilon = mercator::DistanceOnEarth({0, 0}, {kMwmPointAccuracy, kMwmPointAccuracy}) /
mercator::DistanceOnEarth(mercator::FromLatLon(55.7793100, 37.3699100),
mercator::FromLatLon(55.7793300, 37.3699300));
epsilon = base::Clamp(epsilon, 0.0, 1.0);
epsilon = math::Clamp(epsilon, 0.0, 1.0);
CameraMap const answer = {
{SegmentCoord(0, 0), std::vector<RouteSegment::SpeedCamera>{{0.25, 100}}}

View file

@ -36,7 +36,7 @@ namespace generator
{
bool operator==(HierarchyEntry const & lhs, HierarchyEntry const & rhs)
{
return base::AlmostEqualAbs(lhs.m_center, rhs.m_center, 1e-7) &&
return AlmostEqualAbs(lhs.m_center, rhs.m_center, 1e-7) &&
(std::tie(lhs.m_id, lhs.m_parentId, lhs.m_depth, lhs.m_name, lhs.m_country, lhs.m_type) ==
std::tie(rhs.m_id, rhs.m_parentId, rhs.m_depth, rhs.m_name, rhs.m_country, rhs.m_type));
}

View file

@ -46,7 +46,7 @@ feature::FeatureBuilder::PointSeq::iterator GetIterOnRoad(m2::PointD const & poi
{
return std::find_if(road.begin(), road.end(), [&point](m2::PointD const & pointOnRoad)
{
return m2::AlmostEqualAbs(pointOnRoad, point, kMwmPointAccuracy);
return AlmostEqualAbs(pointOnRoad, point, kMwmPointAccuracy);
});
}
} // namespace
@ -149,7 +149,7 @@ MiniRoundaboutTransformer::PointsT MiniRoundaboutTransformer::CreateSurrogateRoa
*itPointOnSurrogateRoad /* source */, roundaboutOnRoad.m_location /* target */,
m_radiusMercator /* dist */);
if (m2::AlmostEqualAbs(nextPointOnSurrogateRoad, *itPointOnSurrogateRoad, kMwmPointAccuracy))
if (AlmostEqualAbs(nextPointOnSurrogateRoad, *itPointOnSurrogateRoad, kMwmPointAccuracy))
return {};
AddPointToCircle(roundaboutCircle, nextPointOnSurrogateRoad);
@ -174,7 +174,7 @@ bool MiniRoundaboutTransformer::AddRoundaboutToRoad(RoundaboutUnit const & round
GetPointAtDistFromTarget(*itPointNearRoundabout /* source */, roundaboutCenter /* target */,
m_radiusMercator /* dist */);
if (isMiddlePoint && !m2::AlmostEqualAbs(nextPointOnRoad, *itPointNearRoundabout, kMwmPointAccuracy))
if (isMiddlePoint && !AlmostEqualAbs(nextPointOnRoad, *itPointNearRoundabout, kMwmPointAccuracy))
{
auto surrogateRoad = CreateSurrogateRoad(roundaboutOnRoad, roundaboutCircle, road, itPointUpd);
if (surrogateRoad.size() < 2)
@ -319,7 +319,7 @@ std::vector<m2::PointD> PointToPolygon(m2::PointD const & center, double radiusM
vertices.reserve(verticesCount);
double const kAngularPitch = 2 * math::pi / static_cast<double>(verticesCount);
double angle = base::DegToRad(initAngleDeg);
double angle = math::DegToRad(initAngleDeg);
for (size_t i = 0; i < verticesCount; ++i)
{

View file

@ -375,7 +375,7 @@ std::string MetadataTagProcessorImpl::ValidateAndFormat_duration(std::string con
return {};
auto const format = [](double hours) -> std::string {
if (base::AlmostEqualAbs(hours, 0.0, 1e-5))
if (AlmostEqualAbs(hours, 0.0, 1e-5))
return {};
std::stringstream ss;

View file

@ -1391,7 +1391,7 @@ void GetNameAndType(OsmElement * p, FeatureBuilderParams & params,
// atoi error value (0) should match empty layer constant.
static_assert(feature::LAYER_EMPTY == 0);
params.layer = atoi(v.c_str());
params.layer = base::Clamp(params.layer, int8_t{feature::LAYER_LOW}, int8_t{feature::LAYER_HIGH});
params.layer = math::Clamp(params.layer, int8_t{feature::LAYER_LOW}, int8_t{feature::LAYER_HIGH});
}
}},
});

View file

@ -187,8 +187,8 @@ bool OsmElement::operator==(OsmElement const & other) const
{
return m_type == other.m_type
&& m_id == other.m_id
&& base::AlmostEqualAbs(m_lon, other.m_lon, mercator::kPointEqualityEps)
&& base::AlmostEqualAbs(m_lat, other.m_lat, mercator::kPointEqualityEps)
&& AlmostEqualAbs(m_lon, other.m_lon, mercator::kPointEqualityEps)
&& AlmostEqualAbs(m_lat, other.m_lat, mercator::kPointEqualityEps)
&& m_ref == other.m_ref
&& m_k == other.m_k
&& m_v == other.m_v

View file

@ -81,7 +81,7 @@ bool IsWorsePlace(FeaturePlace const & left, FeaturePlace const & right)
// We need to compare areas to choose bigger feature from multipolygonal features.
// |kMaxAreaM2| should be greater than cities exclaves (like airports or Zelenograd for Moscow).
double const kMaxAreaM2 = 4e8;
area = base::Clamp(area, 0.0, kMaxAreaM2);
area = math::Clamp(area, 0.0, kMaxAreaM2);
return area / kMaxAreaM2;
};

View file

@ -150,7 +150,7 @@ bool RestrictionCollector::FeatureHasPointWithCoords(uint32_t featureId,
for (uint32_t i = 0; i < pointsCount; ++i)
{
static double constexpr kEps = 1e-5;
if (base::AlmostEqualAbs(mercator::FromLatLon(roadGeometry.GetPoint(i)), coords, kEps))
if (AlmostEqualAbs(mercator::FromLatLon(roadGeometry.GetPoint(i)), coords, kEps))
return true;
}
@ -246,9 +246,9 @@ bool RestrictionCollector::CheckAndProcessUTurn(Restriction::Type & restrictionT
// https://wiki.openstreetmap.org/wiki/Relation:restriction
static auto constexpr kEps = 1e-5;
bool const viaIsFirstNode =
base::AlmostEqualAbs(coords, mercator::FromLatLon(road.GetPoint(0)), kEps);
AlmostEqualAbs(coords, mercator::FromLatLon(road.GetPoint(0)), kEps);
bool const viaIsLastNode =
base::AlmostEqualAbs(coords, mercator::FromLatLon(road.GetPoint(n - 1)), kEps);
AlmostEqualAbs(coords, mercator::FromLatLon(road.GetPoint(n - 1)), kEps);
if (viaIsFirstNode)
{

View file

@ -127,7 +127,7 @@ int TesselateInterior(PolygonsT const & polys, TrianglesInfo & info)
{
for (int j = 0; j < 3; ++j)
{
if (to.m_p[i] == from.m_p[base::NextModN(j, 3)] && to.m_p[base::NextModN(i, 3)] == from.m_p[j])
if (to.m_p[i] == from.m_p[math::NextModN(j, 3)] && to.m_p[math::NextModN(i, 3)] == from.m_p[j])
return std::make_pair(i, j);
}
}
@ -143,14 +143,14 @@ int TesselateInterior(PolygonsT const & polys, TrianglesInfo & info)
void TrianglesInfo::ListInfo::GetNeighbors(
Triangle const & trg, Triangle const & from, int * nb) const
{
int i = base::NextModN(CommonEdge(trg, from).first, 3);
int j = base::NextModN(i, 3);
int i = math::NextModN(CommonEdge(trg, from).first, 3);
int j = math::NextModN(i, 3);
int ind = 0;
TIterator it = m_neighbors.find(std::make_pair(trg.m_p[j], trg.m_p[i]));
nb[ind++] = (it != m_neighbors.end()) ? it->second : empty_key;
it = m_neighbors.find(std::make_pair(trg.m_p[base::NextModN(j, 3)], trg.m_p[j]));
it = m_neighbors.find(std::make_pair(trg.m_p[math::NextModN(j, 3)], trg.m_p[j]));
nb[ind++] = (it != m_neighbors.end()) ? it->second : empty_key;
}

View file

@ -69,7 +69,7 @@ namespace tesselator
{
size_t operator()(std::pair<T1, T2> const & p) const
{
return base::Hash(p.first, p.second);
return math::Hash(p.first, p.second);
}
};

View file

@ -9,7 +9,7 @@ double AngleIn2PI(double ang)
if (ang < 0.0)
ang += period;
if (base::AlmostEqualULPs(period, ang))
if (AlmostEqualULPs(period, ang))
return 0.0;
return ang;

View file

@ -4,6 +4,7 @@
#include "geometry/point3d.hpp"
#include "base/assert.hpp"
#include "base/math.hpp"
#include <algorithm>
#include <cmath>
@ -19,8 +20,8 @@ m3::PointD GetPointOnSphere(LatLon const & ll, double sphereRadius)
ASSERT(LatLon::kMinLat <= ll.m_lat && ll.m_lat <= LatLon::kMaxLat, (ll));
ASSERT(LatLon::kMinLon <= ll.m_lon && ll.m_lon <= LatLon::kMaxLon, (ll));
double const latRad = base::DegToRad(ll.m_lat);
double const lonRad = base::DegToRad(ll.m_lon);
double const latRad = math::DegToRad(ll.m_lat);
double const lonRad = math::DegToRad(ll.m_lon);
double const x = sphereRadius * cos(latRad) * cos(lonRad);
double const y = sphereRadius * cos(latRad) * sin(lonRad);
@ -44,9 +45,9 @@ double AreaOnEarth(LatLon const & ll1, LatLon const & ll2, LatLon const & ll3)
double const triple = m3::DotProduct(a, m3::CrossProduct(b, c));
ASSERT(base::AlmostEqualAbs(a.Length(), 1.0, 1e-5), ());
ASSERT(base::AlmostEqualAbs(b.Length(), 1.0, 1e-5), ());
ASSERT(base::AlmostEqualAbs(c.Length(), 1.0, 1e-5), ());
ASSERT(::AlmostEqualAbs(a.Length(), 1.0, 1e-5), ());
ASSERT(::AlmostEqualAbs(b.Length(), 1.0, 1e-5), ());
ASSERT(::AlmostEqualAbs(c.Length(), 1.0, 1e-5), ());
double constexpr lengthMultiplication = 1.0; // a.Length() * b.Length() * c.Length()
double const abc = m3::DotProduct(a, b); // * c.Length() == 1

View file

@ -49,7 +49,7 @@ private:
{
T res = 0;
for (size_t i = 0; i < Dim; ++i)
res += base::Pow2(a1[i] - a2[i]);
res += math::Pow2(a1[i] - a2[i]);
return std::sqrt(res);
}

View file

@ -16,7 +16,7 @@ std::vector<m3::PointD> CreateCircleOnNorth(double radiusMeters, double angleSte
double const z = ms::kEarthRadiusMeters * cos(angle);
std::vector<m3::PointD> result;
double const stepRad = base::DegToRad(angleStepDegree);
double const stepRad = math::DegToRad(angleStepDegree);
for (double angleRad = 0; angleRad < 2 * math::pi; angleRad += stepRad)
{
result.emplace_back(circleRadiusMeters * cos(angleRad),
@ -28,25 +28,25 @@ std::vector<m3::PointD> CreateCircleOnNorth(double radiusMeters, double angleSte
ms::LatLon FromEarth3dToSpherical(m3::PointD const & vec)
{
ASSERT(base::AlmostEqualAbs(vec.Length(), ms::kEarthRadiusMeters, 1e-5),
ASSERT(AlmostEqualAbs(vec.Length(), ms::kEarthRadiusMeters, 1e-5),
(vec.Length(), ms::kEarthRadiusMeters));
double sinLatRad = vec.z / ms::kEarthRadiusMeters;
sinLatRad = base::Clamp(sinLatRad, -1.0, 1.0);
sinLatRad = math::Clamp(sinLatRad, -1.0, 1.0);
double const cosLatRad = std::sqrt(1 - sinLatRad * sinLatRad);
CHECK(-1.0 <= cosLatRad && cosLatRad <= 1.0, (cosLatRad));
double const latRad = asin(sinLatRad);
double sinLonRad = vec.y / ms::kEarthRadiusMeters / cosLatRad;
sinLonRad = base::Clamp(sinLonRad, -1.0, 1.0);
sinLonRad = math::Clamp(sinLonRad, -1.0, 1.0);
double lonRad = asin(sinLonRad);
if (vec.y > 0 && vec.x < 0)
lonRad = math::pi - lonRad;
else if (vec.y < 0 && vec.x < 0)
lonRad = -(math::pi - fabs(lonRad));
auto const lat = base::RadToDeg(latRad);
auto const lon = base::RadToDeg(lonRad);
auto const lat = math::RadToDeg(latRad);
auto const lon = math::RadToDeg(lonRad);
return {lat, lon};
}

View file

@ -84,7 +84,7 @@ void CoverObject(IntersectF const & intersect, uint64_t cellPenaltyArea, CellIdC
return;
}
uint64_t const cellArea = base::Pow2(uint64_t(1 << (cellDepth - 1 - cell.Level())));
uint64_t const cellArea = math::Pow2(uint64_t(1 << (cellDepth - 1 - cell.Level())));
CellObjectIntersection const intersection = intersect(cell);
if (intersection == CELL_OBJECT_NO_INTERSECTION)
@ -101,7 +101,7 @@ void CoverObject(IntersectF const & intersect, uint64_t cellPenaltyArea, CellIdC
uint64_t subdivArea = 0;
for (size_t i = 0; i < subdiv.size(); ++i)
subdivArea += base::Pow2(uint64_t(1 << (cellDepth - 1 - subdiv[i].Level())));
subdivArea += math::Pow2(uint64_t(1 << (cellDepth - 1 - subdiv[i].Level())));
ASSERT(!subdiv.empty(), (cellPenaltyArea, out, cell));

View file

@ -9,10 +9,10 @@ namespace ms
{
double DistanceOnSphere(double lat1Deg, double lon1Deg, double lat2Deg, double lon2Deg)
{
double const lat1 = base::DegToRad(lat1Deg);
double const lat2 = base::DegToRad(lat2Deg);
double const lat1 = math::DegToRad(lat1Deg);
double const lat2 = math::DegToRad(lat2Deg);
double const dlat = sin((lat2 - lat1) * 0.5);
double const dlon = sin((base::DegToRad(lon2Deg) - base::DegToRad(lon1Deg)) * 0.5);
double const dlon = sin((math::DegToRad(lon2Deg) - math::DegToRad(lon1Deg)) * 0.5);
double const y = dlat * dlat + dlon * dlon * cos(lat1) * cos(lat2);
return 2.0 * atan2(sqrt(y), sqrt(std::max(0.0, 1.0 - y)));
}

View file

@ -75,16 +75,16 @@ UNIT_TEST(ShortestDistance)
UNIT_TEST(TwoVectorsAngle)
{
double constexpr eps = 1e-10;
TEST(base::AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
m2::Point<double>(0, 1) /* p1 */,
m2::Point<double>(1, 0)) /* p2 */, 3 * math::pi2, eps), ());
TEST(base::AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(1, 1) /* p */,
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(1, 1) /* p */,
m2::Point<double>(2, 2) /* p1 */,
m2::Point<double>(1, 2)) /* p2 */, math::pi4, eps), ());
TEST(base::AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
m2::Point<double>(1, 0) /* p1 */,
m2::Point<double>(0, -1)) /* p2 */, 3 * math::pi2, eps), ());
TEST(base::AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
TEST(AlmostEqualAbs(ang::TwoVectorsAngle(m2::Point<double>(0, 0) /* p */,
m2::Point<double>(1, 0) /* p1 */,
m2::Point<double>(-1, 0)) /* p2 */, math::pi, eps), ());
}

View file

@ -62,7 +62,7 @@ UNIT_TEST(CircleOnEarthEquator)
std::vector<m2::PointD> result;
result.reserve(kN);
auto constexpr kStepRad = base::DegToRad(kAngleStepDegree);
auto constexpr kStepRad = math::DegToRad(kAngleStepDegree);
double angleSumRad = 0.0;
double angleRad = -math::pi2;
while (angleSumRad < 2 * math::pi)

View file

@ -25,7 +25,7 @@ UNIT_TEST(IntersectionScore_PointsToPolygon)
auto const score = geometry::GetIntersectionScoreForPoints(corners1, corners2);
TEST(base::AlmostEqualAbs(score, 0.9, 1e-10), ());
TEST(AlmostEqualAbs(score, 0.9, 1e-10), ());
}
{
m2::RectD rectD = {0, 0, 10, 10};
@ -41,7 +41,7 @@ UNIT_TEST(IntersectionScore_PointsToPolygon)
auto const score = geometry::GetIntersectionScoreForPoints(corners1, corners2);
TEST(base::AlmostEqualAbs(score, 0.0, 1e-10), ());
TEST(AlmostEqualAbs(score, 0.0, 1e-10), ());
}
{
m2::RectD rectD = {0, 0, 10, 10};
@ -53,7 +53,7 @@ UNIT_TEST(IntersectionScore_PointsToPolygon)
m2::AnyRectD::Corners corners2 = {m2::PointD{10.0, 10.0}, {10.0, 0.0}, {0.0, 0.0}, {0.0, 10.0}};
auto const score = geometry::GetIntersectionScoreForPoints(corners1, corners2);
TEST(base::AlmostEqualAbs(score, 1.0, 1e-10), ());
TEST(AlmostEqualAbs(score, 1.0, 1e-10), ());
}
}
@ -68,7 +68,7 @@ UNIT_TEST(IntersectionScore_TrianglesToPolygon)
auto const score =
geometry::GetIntersectionScoreForTriangulated(triangiulated1, triangiulated2);
TEST(base::AlmostEqualAbs(score, 0.9, 1e-10), ());
TEST(AlmostEqualAbs(score, 0.9, 1e-10), ());
}
{
m2::RectD rectD = {0, 0, 10, 10};
@ -90,6 +90,6 @@ UNIT_TEST(IntersectionScore_TrianglesToPolygon)
auto const score =
geometry::GetIntersectionScoreForTriangulated(triangiulated1, triangiulated2);
TEST(base::AlmostEqualAbs(score, 0.0, 1e-10), ());
TEST(AlmostEqualAbs(score, 0.0, 1e-10), ());
}
}

View file

@ -53,17 +53,17 @@ UNIT_TEST(ParametrizedSegment2D_DegenerateSection)
UNIT_TEST(ParametrizedSegment2D_ClosestPoint)
{
using P = m2::PointD;
P arr[][4] =
{
{ P(3, 4), P(0, 0), P(10, 0), P(3, 0) },
{ P(3, 4), P(0, 0), P(0, 10), P(0, 4) },
{ P(3, 5), P(2, 2), P(5, 5), P(4, 4) },
{ P(5, 3), P(2, 2), P(5, 5), P(4, 4) },
{ P(2, 4), P(2, 2), P(5, 5), P(3, 3) },
{ P(4, 2), P(2, 2), P(5, 5), P(3, 3) },
{ P(5, 6), P(2, 2), P(5, 5), P(5, 5) },
{ P(1, 0), P(2, 2), P(5, 5), P(2, 2) }
};
@ -71,6 +71,6 @@ UNIT_TEST(ParametrizedSegment2D_ClosestPoint)
for (size_t i = 0; i < ARRAY_SIZE(arr); ++i)
{
m2::ParametrizedSegment<P> segment(arr[i][1], arr[i][2]);
TEST(m2::AlmostEqualULPs(segment.ClosestPointTo(arr[i][0]), arr[i][3]), (i));
TEST(AlmostEqualULPs(segment.ClosestPointTo(arr[i][0]), arr[i][3]), (i));
}
}

View file

@ -92,7 +92,7 @@ UNIT_TEST(Point3d_RotateXYZ)
TEST_ALMOST_EQUAL_ABS(rotatedFirst, m3::PointD(std::sqrt(2.0), 0.0, 1.0), 1e-10, ());
double const angleDegree = base::RadToDeg(acos(rotatedFirst.z / rotatedFirst.Length()));
double const angleDegree = math::RadToDeg(acos(rotatedFirst.z / rotatedFirst.Length()));
auto const north = rotatedFirst.RotateAroundY(-angleDegree);
TEST_ALMOST_EQUAL_ABS(north, m3::PointD(0.0, 0.0, std::sqrt(3.0)), 1e-10, ());

View file

@ -66,32 +66,32 @@ UNIT_TEST(GetArrowPoints)
{
std::array<m2::PointF, 3> arrPntsFlt;
m2::GetArrowPoints(m2::PointF(0, 0), m2::PointF(1, 0), 1.f, 1.f, arrPntsFlt);
TEST(m2::AlmostEqualULPs(arrPntsFlt[0], m2::PointF(1.f, 1.f)), ());
TEST(m2::AlmostEqualULPs(arrPntsFlt[1], m2::PointF(2.f, 0.f)), ());
TEST(m2::AlmostEqualULPs(arrPntsFlt[2], m2::PointF(1.f, -1.f)), ());
TEST(AlmostEqualULPs(arrPntsFlt[0], m2::PointF(1.f, 1.f)), ());
TEST(AlmostEqualULPs(arrPntsFlt[1], m2::PointF(2.f, 0.f)), ());
TEST(AlmostEqualULPs(arrPntsFlt[2], m2::PointF(1.f, -1.f)), ());
std::array<m2::PointD, 3> arrPntsDbl;
m2::GetArrowPoints(m2::PointD(-1., 2.), m2::PointD(-1., 100.), 2., 5., arrPntsDbl);
TEST(m2::AlmostEqualULPs(arrPntsDbl[0], m2::PointD(-3.f, 100.f)), ());
TEST(m2::AlmostEqualULPs(arrPntsDbl[1], m2::PointD(-1.f, 105.f)), ());
TEST(m2::AlmostEqualULPs(arrPntsDbl[2], m2::PointD(1.f, 100.f)), ());
TEST(AlmostEqualULPs(arrPntsDbl[0], m2::PointD(-3.f, 100.f)), ());
TEST(AlmostEqualULPs(arrPntsDbl[1], m2::PointD(-1.f, 105.f)), ());
TEST(AlmostEqualULPs(arrPntsDbl[2], m2::PointD(1.f, 100.f)), ());
}
UNIT_TEST(PointAtSegment)
{
TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f),
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f),
m2::PointF(0.5f, 0.f)),
());
TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f),
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f),
m2::PointF(0.f, 0.3f)),
());
TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.),
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.),
m2::PointD(3., 4.)),
());
TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointF(-3, -4), m2::PointF(-30, -40), 5.f),
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointF(-3, -4), m2::PointF(-30, -40), 5.f),
m2::PointF(-6.f, -8.f)),
());
TEST(m2::AlmostEqualULPs(m2::PointAtSegment(m2::PointD(14., -48.), m2::PointD(70., -240.), 25.),
TEST(AlmostEqualULPs(m2::PointAtSegment(m2::PointD(14., -48.), m2::PointD(70., -240.), 25.),
m2::PointD(21., -72.)),
());
}

View file

@ -33,7 +33,7 @@ UNIT_TEST(Rect_PolylineSmokeTest)
auto const limitRect = poly.GetLimitRect();
TEST_ALMOST_EQUAL_ABS(limitRect.LeftBottom(), m2::PointD(0.0, 0.0), kEps, ());
TEST(base::AlmostEqualAbs(limitRect.RightTop(), m2::PointD(1.0, 1.0), kEps), ());
TEST(AlmostEqualAbs(limitRect.RightTop(), m2::PointD(1.0, 1.0), kEps), ());
poly.PopBack();
TEST_EQUAL(poly.GetSize(), 2, ());

View file

@ -328,7 +328,7 @@ UNIT_TEST(Region_GetRandomPoint)
m2::ConvexHull const hull(points, 1e-9 /* eps */);
auto const hullRegion = m2::Region<P>(hull.Points().begin(), hull.Points().end());
LOG(LINFO, (hullRegion.CalculateArea()));
TEST(base::AlmostEqualRel(region.CalculateArea(), hullRegion.CalculateArea(), 0.05), ());
TEST(AlmostEqualRel(region.CalculateArea(), hullRegion.CalculateArea(), 0.05), ());
if (kNeedPlot)
{

View file

@ -22,10 +22,10 @@ namespace
b2 = screen.GtoP(b2);
// check that we are in boundaries.
TEST(base::Between(0, width, base::SignedRound(b1.x)), ());
TEST(base::Between(0, width, base::SignedRound(b2.x)), ());
TEST(base::Between(0, height, base::SignedRound(b1.y)), ());
TEST(base::Between(0, height, base::SignedRound(b2.y)), ());
TEST(math::Between(0, width, math::SignedRound(b1.x)), ());
TEST(math::Between(0, width, math::SignedRound(b2.x)), ());
TEST(math::Between(0, height, math::SignedRound(b1.y)), ());
TEST(math::Between(0, height, math::SignedRound(b2.y)), ());
}
}

View file

@ -9,7 +9,7 @@ bool EqualArrays(T (&a1)[N], T (&a2)[N])
{
for (size_t i = 0; i < N; ++i)
{
if (!base::AlmostEqualULPs(a1[i], a2[i]))
if (!AlmostEqualULPs(a1[i], a2[i]))
return false;
}
return true;

View file

@ -1,5 +1,7 @@
#include "latlon.hpp"
#include "base/math.hpp"
#include <sstream>
#include <tuple>
@ -14,7 +16,7 @@ bool LatLon::operator<(ms::LatLon const & rhs) const
bool LatLon::EqualDxDy(LatLon const & p, double eps) const
{
return (base::AlmostEqualAbs(m_lat, p.m_lat, eps) && base::AlmostEqualAbs(m_lon, p.m_lon, eps));
return (::AlmostEqualAbs(m_lat, p.m_lat, eps) && ::AlmostEqualAbs(m_lon, p.m_lon, eps));
}
std::string DebugPrint(LatLon const & t)
@ -24,13 +26,10 @@ std::string DebugPrint(LatLon const & t)
out << "ms::LatLon(" << t.m_lat << ", " << t.m_lon << ")";
return out.str();
}
} // namespace ms
namespace base
bool AlmostEqualAbs(LatLon const & ll1, LatLon const & ll2, double const & eps)
{
bool AlmostEqualAbs(ms::LatLon const & ll1, ms::LatLon const & ll2, double const & eps)
{
return base::AlmostEqualAbs(ll1.m_lat, ll2.m_lat, eps) &&
base::AlmostEqualAbs(ll1.m_lon, ll2.m_lon, eps);
return ::AlmostEqualAbs(ll1.m_lat, ll2.m_lat, eps) &&
::AlmostEqualAbs(ll1.m_lon, ll2.m_lon, eps);
}
} // namespace base
} // namespace ms

View file

@ -20,28 +20,25 @@ public:
double m_lat = kInvalid;
double m_lon = kInvalid;
LatLon() = default;
LatLon(double lat, double lon) : m_lat(lat), m_lon(lon) {}
constexpr LatLon() = default;
constexpr LatLon(double lat, double lon) : m_lat(lat), m_lon(lon) {}
static LatLon Invalid() { return LatLon(kInvalid, kInvalid); }
static LatLon Zero() { return LatLon(0.0, 0.0); }
static constexpr LatLon Invalid() { return LatLon(kInvalid, kInvalid); }
static constexpr LatLon Zero() { return LatLon(0.0, 0.0); }
bool IsValid() const { return m_lat != kInvalid && m_lon != kInvalid; }
bool operator==(ms::LatLon const & rhs) const;
bool operator<(ms::LatLon const & rhs) const;
bool constexpr IsValid() const { return m_lat != kInvalid && m_lon != kInvalid; }
bool operator==(LatLon const & rhs) const;
bool operator<(LatLon const & rhs) const;
bool EqualDxDy(LatLon const & p, double eps) const;
struct Hash
{
size_t operator()(ms::LatLon const & p) const { return base::Hash(p.m_lat, p.m_lon); }
size_t operator()(ms::LatLon const & p) const { return math::Hash(p.m_lat, p.m_lon); }
};
};
bool AlmostEqualAbs(LatLon const & ll1, LatLon const & ll2, double const & eps);
std::string DebugPrint(LatLon const & t);
} // namespace ms
namespace base
{
bool AlmostEqualAbs(ms::LatLon const & ll1, ms::LatLon const & ll2, double const & eps);
} // namespace base

View file

@ -18,7 +18,7 @@ m2::RectD MetersToXY(double lon, double lat, double lonMetersR, double latMeters
double const minLat = max(-90.0, lat - latDegreeOffset);
double const maxLat = min(90.0, lat + latDegreeOffset);
double const cosL = max(cos(base::DegToRad(max(fabs(minLat), fabs(maxLat)))), 0.00001);
double const cosL = max(cos(math::DegToRad(max(fabs(minLat), fabs(maxLat)))), 0.00001);
ASSERT_GREATER(cosL, 0.0, ());
double const lonDegreeOffset = lonMetersR * Bounds::kDegreesInMeter / cosL;
@ -38,7 +38,7 @@ m2::PointD GetSmPoint(m2::PointD const & pt, double lonMetersR, double latMeters
double const latDegreeOffset = latMetersR * Bounds::kDegreesInMeter;
double const newLat = min(90.0, max(-90.0, lat + latDegreeOffset));
double const cosL = max(cos(base::DegToRad(newLat)), 0.00001);
double const cosL = max(cos(math::DegToRad(newLat)), 0.00001);
ASSERT_GREATER(cosL, 0.0, ());
double const lonDegreeOffset = lonMetersR * Bounds::kDegreesInMeter / cosL;
@ -71,13 +71,13 @@ void ClampPoint(m2::PointD & pt)
double YToLat(double y)
{
return base::RadToDeg(2.0 * atan(tanh(0.5 * base::DegToRad(y))));
return math::RadToDeg(2.0 * atan(tanh(0.5 * math::DegToRad(y))));
}
double LatToY(double lat)
{
double const sinx = sin(base::DegToRad(base::Clamp(lat, -86.0, 86.0)));
double const res = base::RadToDeg(0.5 * log((1.0 + sinx) / (1.0 - sinx)));
double const sinx = sin(math::DegToRad(math::Clamp(lat, -86.0, 86.0)));
double const res = math::RadToDeg(0.5 * log((1.0 + sinx) / (1.0 - sinx)));
return ClampY(res);
}

View file

@ -30,14 +30,14 @@ struct Bounds
}
};
inline bool ValidLon(double d) { return base::Between(-180.0, 180.0, d); }
inline bool ValidLat(double d) { return base::Between(-90.0, 90.0, d); }
inline bool ValidLon(double d) { return math::Between(-180.0, 180.0, d); }
inline bool ValidLat(double d) { return math::Between(-90.0, 90.0, d); }
inline bool ValidX(double d) { return base::Between(Bounds::kMinX, Bounds::kMaxX, d); }
inline bool ValidY(double d) { return base::Between(Bounds::kMinY, Bounds::kMaxY, d); }
inline bool ValidX(double d) { return math::Between(Bounds::kMinX, Bounds::kMaxX, d); }
inline bool ValidY(double d) { return math::Between(Bounds::kMinY, Bounds::kMaxY, d); }
inline double ClampX(double d) { return base::Clamp(d, Bounds::kMinX, Bounds::kMaxX); }
inline double ClampY(double d) { return base::Clamp(d, Bounds::kMinY, Bounds::kMaxY); }
inline double ClampX(double d) { return math::Clamp(d, Bounds::kMinX, Bounds::kMaxX); }
inline double ClampY(double d) { return math::Clamp(d, Bounds::kMinY, Bounds::kMaxY); }
void ClampPoint(m2::PointD & pt);

View file

@ -32,6 +32,7 @@ double GetDistance(ms::LatLon const & point1, ms::LatLon const & point2)
{
using namespace base;
using namespace std;
using math::DegToRad, math::Pow2;
m2::PointD const p1 = {DegToRad(point1.m_lon), DegToRad(point1.m_lat)};
m2::PointD const p2 = {DegToRad(point2.m_lon), DegToRad(point2.m_lat)};
@ -81,7 +82,7 @@ double GetDistance(ms::LatLon const & point1, ms::LatLon const & point2)
// Fallback solution.
if (!AlmostEqualAbs(lambda, lambdaPrev, kEps))
return ms::DistanceOnEarth(point1, point2);
return DistanceOnEarth(point1, point2);
double constexpr aSquare = kA * kA;
double constexpr bSquare = kB * kB;

View file

@ -50,7 +50,7 @@ public:
return (p - m_p1).SquaredLength();
// Closest point is between |m_p0| and |m_p1|.
return base::Pow2(CrossProduct(diff, m_d));
return math::Pow2(CrossProduct(diff, m_d));
}
// Returns the point of the segment that is closest to |p|.

View file

@ -36,7 +36,7 @@ public:
return ((fabs(x - p.x) < eps) && (fabs(y - p.y) < eps));
}
T SquaredLength(Point<T> const & p) const { return base::Pow2(x - p.x) + base::Pow2(y - p.y); }
T SquaredLength(Point<T> const & p) const { return math::Pow2(x - p.x) + math::Pow2(y - p.y); }
double Length(Point<T> const & p) const { return std::sqrt(SquaredLength(p)); }
bool IsAlmostZero() const { return AlmostEqualULPs(*this, Point<T>(0, 0)); }
@ -158,7 +158,7 @@ public:
struct Hash
{
size_t operator()(m2::Point<T> const & p) const { return base::Hash(p.x, p.y); }
size_t operator()(Point const & p) const { return math::Hash(p.x, p.y); }
};
};
@ -170,31 +170,31 @@ using PointI = Point<int32_t>;
using PointI64 = Point<int64_t>;
template <typename T>
Point<T> const operator-(Point<T> const & a, Point<T> const & b)
Point<T> operator-(Point<T> const & a, Point<T> const & b)
{
return Point<T>(a.x - b.x, a.y - b.y);
}
template <typename T>
Point<T> const operator+(Point<T> const & a, Point<T> const & b)
Point<T> operator+(Point<T> const & a, Point<T> const & b)
{
return Point<T>(a.x + b.x, a.y + b.y);
}
template <typename T>
T const DotProduct(Point<T> const & a, Point<T> const & b)
T DotProduct(Point<T> const & a, Point<T> const & b)
{
return a.x * b.x + a.y * b.y;
}
template <typename T>
T const CrossProduct(Point<T> const & a, Point<T> const & b)
T CrossProduct(Point<T> const & a, Point<T> const & b)
{
return a.x * b.y - a.y * b.x;
}
template <typename T>
Point<T> const Rotate(Point<T> const & pt, T a)
Point<T> Rotate(Point<T> const & pt, T a)
{
Point<T> res(pt);
res.Rotate(a);
@ -202,19 +202,19 @@ Point<T> const Rotate(Point<T> const & pt, T a)
}
template <typename T, typename U>
Point<T> const Shift(Point<T> const & pt, U const & dx, U const & dy)
Point<T> Shift(Point<T> const & pt, U const & dx, U const & dy)
{
return Point<T>(pt.x + dx, pt.y + dy);
}
template <typename T, typename U>
Point<T> const Shift(Point<T> const & pt, Point<U> const & offset)
Point<T> Shift(Point<T> const & pt, Point<U> const & offset)
{
return Shift(pt, offset.x, offset.y);
}
template <typename T>
Point<T> const Floor(Point<T> const & pt)
Point<T> Floor(Point<T> const & pt)
{
Point<T> res;
res.x = floor(pt.x);
@ -223,7 +223,7 @@ Point<T> const Floor(Point<T> const & pt)
}
template <typename T>
std::string DebugPrint(m2::Point<T> const & p)
std::string DebugPrint(Point<T> const & p)
{
std::ostringstream out;
out.precision(20);
@ -232,15 +232,15 @@ std::string DebugPrint(m2::Point<T> const & p)
}
template <typename T>
bool AlmostEqualAbs(m2::Point<T> const & a, m2::Point<T> const & b, double eps)
bool AlmostEqualAbs(Point<T> const & a, Point<T> const & b, double eps)
{
return base::AlmostEqualAbs(a.x, b.x, eps) && base::AlmostEqualAbs(a.y, b.y, eps);
return ::AlmostEqualAbs(a.x, b.x, eps) && ::AlmostEqualAbs(a.y, b.y, eps);
}
template <typename T>
bool AlmostEqualULPs(m2::Point<T> const & a, m2::Point<T> const & b, unsigned int maxULPs = 256)
bool AlmostEqualULPs(Point<T> const & a, Point<T> const & b, unsigned int maxULPs = 256)
{
return base::AlmostEqualULPs(a.x, b.x, maxULPs) && base::AlmostEqualULPs(a.y, b.y, maxULPs);
return ::AlmostEqualULPs(a.x, b.x, maxULPs) && ::AlmostEqualULPs(a.y, b.y, maxULPs);
}
/// Calculate three points of a triangle (p1, p2 and p3) which give an arrow that
@ -250,7 +250,7 @@ bool AlmostEqualULPs(m2::Point<T> const & a, m2::Point<T> const & b, unsigned in
template <typename T, typename TT, typename PointT = Point<T>>
void GetArrowPoints(PointT const & b, PointT const & e, T w, T l, std::array<Point<TT>, 3> & arr)
{
ASSERT(!m2::AlmostEqualULPs(b, e), ());
ASSERT(!AlmostEqualULPs(b, e), ());
PointT const beVec = e - b;
PointT beNormalizedVec = beVec.Normalize();
@ -268,12 +268,12 @@ template <typename T>
Point<T> PointAtSegment(Point<T> const & p1, Point<T> const & p2, T shiftFromP1)
{
Point<T> p12 = p2 - p1;
shiftFromP1 = base::Clamp(shiftFromP1, static_cast<T>(0.0), static_cast<T>(p12.Length()));
shiftFromP1 = math::Clamp(shiftFromP1, static_cast<T>(0.0), static_cast<T>(p12.Length()));
return p1 + p12.Normalize() * shiftFromP1;
}
template <class TArchive, class PointT>
TArchive & operator>>(TArchive & ar, m2::Point<PointT> & pt)
TArchive & operator>>(TArchive & ar, Point<PointT> & pt)
{
ar >> pt.x;
ar >> pt.y;
@ -281,7 +281,7 @@ TArchive & operator>>(TArchive & ar, m2::Point<PointT> & pt)
}
template <class TArchive, class PointT>
TArchive & operator<<(TArchive & ar, m2::Point<PointT> const & pt)
TArchive & operator<<(TArchive & ar, Point<PointT> const & pt)
{
ar << pt.x;
ar << pt.y;
@ -296,18 +296,3 @@ bool operator<(Point<T> const & l, Point<T> const & r)
return l.y < r.y;
}
} // namespace m2
namespace base
{
template <typename T>
bool AlmostEqualULPs(m2::Point<T> const & p1, m2::Point<T> const & p2, unsigned int maxULPs = 256)
{
return m2::AlmostEqualULPs(p1, p2, maxULPs);
}
template <typename T>
bool AlmostEqualAbs(m2::Point<T> const & p1, m2::Point<T> const & p2, double eps)
{
return m2::AlmostEqualAbs(p1, p2, eps);
}
} // namespace base

View file

@ -31,7 +31,7 @@ public:
template <typename T>
Point<T> Point<T>::RotateAroundX(double angleDegree) const
{
double const angleRad = base::DegToRad(angleDegree);
double const angleRad = math::DegToRad(angleDegree);
Point<T> res;
res.x = x;
res.y = y * cos(angleRad) - z * sin(angleRad);
@ -42,7 +42,7 @@ Point<T> Point<T>::RotateAroundX(double angleDegree) const
template <typename T>
Point<T> Point<T>::RotateAroundY(double angleDegree) const
{
double const angleRad = base::DegToRad(angleDegree);
double const angleRad = math::DegToRad(angleDegree);
Point<T> res;
res.x = x * cos(angleRad) + z * sin(angleRad);
res.y = y;
@ -53,7 +53,7 @@ Point<T> Point<T>::RotateAroundY(double angleDegree) const
template <typename T>
Point<T> Point<T>::RotateAroundZ(double angleDegree) const
{
double const angleRad = base::DegToRad(angleDegree);
double const angleRad = math::DegToRad(angleDegree);
Point<T> res;
res.x = x * cos(angleRad) - y * sin(angleRad);
res.y = x * sin(angleRad) + y * cos(angleRad);
@ -93,14 +93,11 @@ std::string DebugPrint(Point<T> const & p)
out << "m3::Point<" << typeid(T).name() << ">(" << p.x << ", " << p.y << ", " << p.z << ")";
return out.str();
}
} // namespace m3
namespace base
{
template <typename T>
bool AlmostEqualAbs(m3::Point<T> const & p1, m3::Point<T> const & p2, double const & eps)
bool AlmostEqualAbs(Point<T> const & p1, Point<T> const & p2, double const & eps)
{
return base::AlmostEqualAbs(p1.x, p2.x, eps) && base::AlmostEqualAbs(p1.y, p2.y, eps) &&
base::AlmostEqualAbs(p1.z, p2.z, eps);
return ::AlmostEqualAbs(p1.x, p2.x, eps) && ::AlmostEqualAbs(p1.y, p2.y, eps) &&
::AlmostEqualAbs(p1.z, p2.z, eps);
}
} // namespace base
} // namespace m3

View file

@ -16,17 +16,17 @@ bool FindSingleStripForIndex(size_t i, size_t n, IsVisibleF isVisible)
{
// Searching for a strip only in a single direction, because the opposite direction
// is traversed from the last vertex of the possible strip.
size_t a = base::PrevModN(i, n);
size_t b = base::NextModN(i, n);
size_t a = math::PrevModN(i, n);
size_t b = math::NextModN(i, n);
for (size_t j = 2; j < n; ++j)
{
ASSERT_NOT_EQUAL(a, b, ());
if (!isVisible(a, b))
return false;
if (j & 1)
a = base::PrevModN(a, n);
a = math::PrevModN(a, n);
else
b = base::NextModN(b, n);
b = math::NextModN(b, n);
}
ASSERT_EQUAL(a, b, ());

View file

@ -195,8 +195,8 @@ public:
void SetSizesToIncludePoint(Point<T> const & pt)
{
Point<T> const c = Center();
T const dx = base::Abs(pt.x - c.x);
T const dy = base::Abs(pt.y - c.y);
T const dx = math::Abs(pt.x - c.x);
T const dy = math::Abs(pt.y - c.y);
m_minX = c.x - dx;
m_minY = c.y - dy;

View file

@ -27,8 +27,8 @@ struct DefEqualFloat
{
static_assert(std::is_floating_point<typename Point::value_type>::value, "");
return base::AlmostEqualAbs(p1.x, p2.x, static_cast<typename Point::value_type>(kPrecision)) &&
base::AlmostEqualAbs(p1.y, p2.y, static_cast<typename Point::value_type>(kPrecision));
return ::AlmostEqualAbs(p1.x, p2.x, static_cast<typename Point::value_type>(kPrecision)) &&
::AlmostEqualAbs(p1.y, p2.y, static_cast<typename Point::value_type>(kPrecision));
}
template <typename Coord>
@ -36,7 +36,7 @@ struct DefEqualFloat
{
static_assert(std::is_floating_point<Coord>::value, "");
return base::AlmostEqualAbs(val, 0.0, kPrecision * kPrecision);
return ::AlmostEqualAbs(val, 0.0, kPrecision * kPrecision);
}
// Determines if value of a val lays between a p1 and a p2 values with some precision.
bool IsAlmostBetween(double val, double p1, double p2) const
@ -322,7 +322,7 @@ public:
area += CrossProduct(prev, curr);
prev = curr;
}
area = base::Abs(area) / 2;
area = math::Abs(area) / 2;
return area;
}

View file

@ -218,11 +218,11 @@ void ScreenBase::SetAngle(double angle)
UpdateDependentParameters();
}
int ScreenBase::GetWidth() const { return base::SignedRound(m_PixelRect.SizeX()); }
int ScreenBase::GetWidth() const { return math::SignedRound(m_PixelRect.SizeX()); }
int ScreenBase::GetHeight() const { return base::SignedRound(m_PixelRect.SizeY()); }
int ScreenBase::GetHeight() const { return math::SignedRound(m_PixelRect.SizeY()); }
ScreenBase::MatrixT const ScreenBase::CalcTransform(m2::PointD const & oldPt1,
ScreenBase::MatrixT ScreenBase::CalcTransform(m2::PointD const & oldPt1,
m2::PointD const & oldPt2,
m2::PointD const & newPt1,
m2::PointD const & newPt2, bool allowRotate)

View file

@ -61,7 +61,7 @@ public:
void PtoG(double & x, double & y) const
{
double tempX = x;
double const tempX = x;
x = tempX * m_PtoG(0, 0) + y * m_PtoG(1, 0) + m_PtoG(2, 0);
y = tempX * m_PtoG(0, 1) + y * m_PtoG(1, 1) + m_PtoG(2, 1);
}
@ -122,7 +122,7 @@ public:
/// Compute arbitrary pixel transformation, that translates the (oldPt1, oldPt2) -> (newPt1,
/// newPt2)
static MatrixT const CalcTransform(m2::PointD const & oldPt1, m2::PointD const & oldPt2,
static MatrixT CalcTransform(m2::PointD const & oldPt1, m2::PointD const & oldPt2,
m2::PointD const & newPt1, m2::PointD const & newPt2,
bool allowRotate);

View file

@ -68,10 +68,10 @@ public:
#if 0 // DEBUG
double minX, minY, maxX, maxY;
GetCellBounds(id1, minX, minY, maxX, maxY);
ASSERT(base::Between(minX, maxX, x1), (x1, minX, maxX));
ASSERT(base::Between(minX, maxX, x2), (x2, minX, maxX));
ASSERT(base::Between(minY, maxY, y1), (y1, minY, maxY));
ASSERT(base::Between(minY, maxY, y2), (y2, minY, maxY));
ASSERT(math::Between(minX, maxX, x1), (x1, minX, maxX));
ASSERT(math::Between(minX, maxX, x2), (x2, minX, maxX));
ASSERT(math::Between(minY, maxY, y1), (y1, minY, maxY));
ASSERT(math::Between(minY, maxY, y2), (y2, minY, maxY));
#endif
return id1;
}

View file

@ -7,7 +7,7 @@ namespace feature
uint8_t PopulationToRank(uint64_t p)
{
return static_cast<uint8_t>(std::min(0xFF, base::SignedRound(log(double(p)) / log(1.1))));
return static_cast<uint8_t>(std::min(0xFF, math::SignedRound(log(double(p)) / log(1.1))));
}
uint64_t RankToPopulation(uint8_t r)

View file

@ -900,7 +900,7 @@ double GetRadiusByPopulationForRouting(uint64_t p, LocalityType localityType)
uint64_t GetPopulationByRadius(double r)
{
return base::SignedRound(pow(r / 550.0, 3.6));
return math::SignedRound(pow(r / 550.0, 3.6));
}
} // namespace ftypes

View file

@ -163,7 +163,7 @@ UNIT_TEST(TrieBuilder_Build)
vector<string> possibleStrings(1, string{});
for (int len = 1; len <= kMaxLen; ++len)
{
for (uint32_t i = 0, p = base::PowUint(kBase, len); i < p; ++i)
for (uint32_t i = 0, p = math::PowUint(kBase, len); i < p; ++i)
{
string s(len, 'A');
uint32_t t = i;

View file

@ -33,12 +33,12 @@ namespace scales
int GetScaleLevel(double ratio)
{
return base::SignedRound(GetScaleLevelD(ratio));
return math::SignedRound(GetScaleLevelD(ratio));
}
int GetScaleLevel(m2::RectD const & r)
{
return base::SignedRound(GetScaleLevelD(r));
return math::SignedRound(GetScaleLevelD(r));
}
namespace

View file

@ -30,7 +30,7 @@ CGFloat const kButtonsBottomOffset = 6;
- (void)layoutSubviews {
CGFloat spacing = self.availableHeight - self.zoomOut.maxY - self.location.height;
spacing = base::Clamp(spacing, kLocationButtonSpacingMin, kLocationButtonSpacingMax);
spacing = math::Clamp(spacing, kLocationButtonSpacingMin, kLocationButtonSpacingMax);
self.location.minY = self.zoomOut.maxY + spacing;
self.bounds = {{}, {self.zoomOut.width, self.location.maxY}};

View file

@ -32,9 +32,9 @@ static location::CompassInfo compassInfoFromHeading(CLHeading * h)
{
location::CompassInfo info;
if (h.trueHeading >= 0.0)
info.m_bearing = base::DegToRad(h.trueHeading);
info.m_bearing = math::DegToRad(h.trueHeading);
else if (h.headingAccuracy >= 0.0)
info.m_bearing = base::DegToRad(h.magneticHeading);
info.m_bearing = math::DegToRad(h.magneticHeading);
return info;
}

View file

@ -851,7 +851,7 @@ void BookmarkManager::UpdateElevationMyPosition(kml::TrackId const & trackId)
auto trackSelectionMark = GetMarkForEdit<TrackSelectionMark>(markId);
double const kEpsMeters = 1e-2;
if (!base::AlmostEqualAbs(trackSelectionMark->GetMyPositionDistance(),
if (!AlmostEqualAbs(trackSelectionMark->GetMyPositionDistance(),
myPositionDistance, kEpsMeters))
{
trackSelectionMark->SetMyPositionDistance(myPositionDistance);

View file

@ -145,7 +145,7 @@ bool NormalizeChartData(vector<double> const & distanceDataM,
ASSERT_LESS(0, nextPointIdx, ("distFormStartM is greater than 0 but nextPointIdx == 0."));
size_t const prevPointIdx = nextPointIdx - 1;
if (base::AlmostEqualAbs(distanceDataM[prevPointIdx], distanceDataM[nextPointIdx], kEpsilon))
if (AlmostEqualAbs(distanceDataM[prevPointIdx], distanceDataM[nextPointIdx], kEpsilon))
return static_cast<double>(altitudeDataM[prevPointIdx]);
double const k = (altitudeDataM[nextPointIdx] - altitudeDataM[prevPointIdx]) /

View file

@ -63,9 +63,9 @@ location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1,
result.m_timestamp += static_cast<double>(timeAfterPoint2Ms) / 1000.0;
result.m_longitude =
base::Clamp(e.Extrapolate(gpsInfo1.m_longitude, gpsInfo2.m_longitude), -180.0, 180.0);
math::Clamp(e.Extrapolate(gpsInfo1.m_longitude, gpsInfo2.m_longitude), -180.0, 180.0);
result.m_latitude =
base::Clamp(e.Extrapolate(gpsInfo1.m_latitude, gpsInfo2.m_latitude), -90.0, 90.0);
math::Clamp(e.Extrapolate(gpsInfo1.m_latitude, gpsInfo2.m_latitude), -90.0, 90.0);
result.m_altitude = e.Extrapolate(gpsInfo1.m_altitude, gpsInfo2.m_altitude);
// @TODO(bykoianko) Now |result.m_bearing| == |gpsInfo2.m_bearing|.

View file

@ -317,7 +317,7 @@ int main(int argc, char * argv[])
("Cumulative moving average, variance and standard deviation for each extrapolation:"));
for (size_t i = 0; i < extrapolationNumber; ++i)
{
double const variance = squareMes.Get()[i].Get() - base::Pow2(mes.Get()[i].Get());
double const variance = squareMes.Get()[i].Get() - math::Pow2(mes.Get()[i].Get());
LOG(LINFO,
("Extrapolation", i + 1, ",", Extrapolator::kExtrapolationPeriodMs * (i + 1),
"seconds after point two. Cumulative moving average =", mes.Get()[i].Get(), "meters.",

Some files were not shown because too many files have changed in this diff Show more