diff options
author | Maxim Pimenov <m@maps.me> | 2018-11-20 15:03:25 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2018-11-23 16:59:58 +0300 |
commit | d75839e65c4a63ed0e4a7b192d584e8b83efb435 (patch) | |
tree | e047a2d0d4d55371fdb67c5cbef6ebd10f7506a4 /coding | |
parent | 3467f9aad381da685c13746e92c145d917e99439 (diff) |
[coding] Moved functions that encode points to one common file.
Diffstat (limited to 'coding')
-rw-r--r-- | coding/CMakeLists.txt | 6 | ||||
-rw-r--r-- | coding/coding_tests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | coding/coding_tests/geometry_coding_test.cpp | 5 | ||||
-rw-r--r-- | coding/coding_tests/geometry_serialization_test.cpp | 4 | ||||
-rw-r--r-- | coding/coding_tests/point_coding_tests.cpp (renamed from coding/coding_tests/point_to_integer_test.cpp) | 46 | ||||
-rw-r--r-- | coding/coding_tests/pointd_to_pointu_tests.cpp | 52 | ||||
-rw-r--r-- | coding/geometry_coding.cpp | 8 | ||||
-rw-r--r-- | coding/geometry_coding.hpp | 2 | ||||
-rw-r--r-- | coding/point_coding.cpp | 109 | ||||
-rw-r--r-- | coding/point_coding.hpp | 77 | ||||
-rw-r--r-- | coding/point_to_integer.cpp | 53 | ||||
-rw-r--r-- | coding/point_to_integer.hpp | 43 | ||||
-rw-r--r-- | coding/pointd_to_pointu.cpp | 61 | ||||
-rw-r--r-- | coding/pointd_to_pointu.hpp | 17 | ||||
-rw-r--r-- | coding/traffic.hpp | 2 |
15 files changed, 241 insertions, 247 deletions
diff --git a/coding/CMakeLists.txt b/coding/CMakeLists.txt index e9c5f80aa9..d07ad421f2 100644 --- a/coding/CMakeLists.txt +++ b/coding/CMakeLists.txt @@ -57,10 +57,8 @@ set( multilang_utf8_string.cpp multilang_utf8_string.hpp parse_xml.hpp - point_to_integer.cpp - point_to_integer.hpp - pointd_to_pointu.cpp - pointd_to_pointu.hpp + point_coding.cpp + point_coding.hpp polymorph_reader.hpp read_write_utils.hpp reader.cpp diff --git a/coding/coding_tests/CMakeLists.txt b/coding/coding_tests/CMakeLists.txt index 6955a79419..f8ee6ec16c 100644 --- a/coding/coding_tests/CMakeLists.txt +++ b/coding/coding_tests/CMakeLists.txt @@ -25,8 +25,7 @@ set( mem_file_writer_test.cpp multilang_utf8_string_test.cpp png_decoder_test.cpp - point_to_integer_test.cpp - pointd_to_pointu_tests.cpp + point_coding_tests.cpp reader_cache_test.cpp reader_test.cpp reader_test.hpp diff --git a/coding/coding_tests/geometry_coding_test.cpp b/coding/coding_tests/geometry_coding_test.cpp index d3caf8e5df..3e398a17b3 100644 --- a/coding/coding_tests/geometry_coding_test.cpp +++ b/coding/coding_tests/geometry_coding_test.cpp @@ -3,8 +3,7 @@ #include "coding/byte_stream.hpp" #include "coding/coding_tests/test_polylines.hpp" #include "coding/geometry_coding.hpp" -#include "coding/point_to_integer.hpp" -#include "coding/pointd_to_pointu.hpp" +#include "coding/point_coding.hpp" #include "coding/varint.hpp" #include "coding/writer.hpp" @@ -23,7 +22,7 @@ namespace { m2::PointU D2U(m2::PointD const & p) { return PointDToPointU(p, POINT_COORD_BITS); } -m2::PointU GetMaxPoint() { return D2U(m2::PointD(MercatorBounds::maxX, MercatorBounds::maxY)); } +m2::PointU GetMaxPoint() { return D2U(m2::PointD(MercatorBounds::kMaxX, MercatorBounds::kMaxY)); } void TestPolylineEncode(string testName, vector<m2::PointU> const & points, m2::PointU const & maxPoint, diff --git a/coding/coding_tests/geometry_serialization_test.cpp b/coding/coding_tests/geometry_serialization_test.cpp index 1aa9636ad2..6e858ab14a 100644 --- a/coding/coding_tests/geometry_serialization_test.cpp +++ b/coding/coding_tests/geometry_serialization_test.cpp @@ -14,12 +14,12 @@ namespace { bool is_equal(double d1, double d2) { - return (fabs(d1 - d2) < MercatorBounds::GetCellID2PointAbsEpsilon()); + return (fabs(d1 - d2) < kCellIdToPointEps); } bool is_equal(m2::PointD const & p1, m2::PointD const & p2) { - return p1.EqualDxDy(p2, MercatorBounds::GetCellID2PointAbsEpsilon()); + return p1.EqualDxDy(p2, kCellIdToPointEps); } bool is_equal(m2::RectD const & r1, m2::RectD const & r2) diff --git a/coding/coding_tests/point_to_integer_test.cpp b/coding/coding_tests/point_coding_tests.cpp index 2842fedfdf..d5a0a8dc96 100644 --- a/coding/coding_tests/point_to_integer_test.cpp +++ b/coding/coding_tests/point_coding_tests.cpp @@ -1,8 +1,8 @@ #include "testing/testing.hpp" #include "coding/coding_tests/test_polylines.hpp" -#include "coding/point_to_integer.hpp" -#include "coding/pointd_to_pointu.hpp" + +#include "coding/point_coding.hpp" #include "geometry/mercator.hpp" @@ -14,7 +14,7 @@ using namespace std; namespace { -double const kEps = MercatorBounds::GetCellID2PointAbsEpsilon(); +double const kEps = kCellIdToPointEps; uint32_t const kCoordBits = POINT_COORD_BITS; uint32_t const kBig = uint32_t{1} << 30; @@ -34,6 +34,44 @@ void CheckEqualPoints(m2::PointD const & p1, m2::PointD const & p2) } } // namespace +UNIT_TEST(PointDToPointU_Epsilons) +{ + m2::PointD const arrPt[] = {{-180, -180}, {-180, 180}, {180, 180}, {180, -180}}; + m2::PointD const arrD[] = {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}}; + size_t const count = ARRAY_SIZE(arrPt); + + double eps = 1.0; + while (true) + { + size_t i = 0; + for (; i < count; ++i) + { + m2::PointU p0 = PointDToPointU(arrPt[i].x, arrPt[i].y, kCoordBits); + m2::PointU p1 = PointDToPointU(arrPt[i].x + arrD[i].x * eps, + arrPt[i].y + arrD[i].y * eps, + kCoordBits); + + if (p0 != p1) + break; + } + if (i == count) + break; + + eps *= 0.1; + } + + LOG(LINFO, ("Epsilon (relative error) =", eps)); + + for (size_t i = 0; i < count; ++i) + { + m2::PointU const p1 = PointDToPointU(arrPt[i].x, arrPt[i].y, kCoordBits); + m2::PointU const p2(p1.x + arrD[i].x, p1.y + arrD[i].y); + m2::PointD const p3 = PointUToPointD(p2, kCoordBits); + + LOG(LINFO, ("Dx =", p3.x - arrPt[i].x, "Dy =", p3.y - arrPt[i].y)); + } +} + UNIT_TEST(PointToInt64Obsolete_Smoke) { m2::PointD const arr[] = {{1.25, 1.3}, {180, 90}, {-180, -90}, {0, 0}}; @@ -112,7 +150,7 @@ UNIT_TEST(PointUToUint64Obsolete_1bit) TEST_EQUAL((1ULL << 60) - 1, PointUToUint64Obsolete(m2::PointU(kBig - 1, kBig - 1)), ()); } -UNIT_TEST(PointToInt64_DataSet1) +UNIT_TEST(PointToInt64Obsolete_DataSet1) { using namespace geometry_coding_tests; diff --git a/coding/coding_tests/pointd_to_pointu_tests.cpp b/coding/coding_tests/pointd_to_pointu_tests.cpp deleted file mode 100644 index 606403b69d..0000000000 --- a/coding/coding_tests/pointd_to_pointu_tests.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "testing/testing.hpp" - -#include "coding/pointd_to_pointu.hpp" - -#include "base/logging.hpp" - -#include <cmath> - -using namespace std; - -namespace -{ -uint32_t const kCoordBits = POINT_COORD_BITS; -} // namespace - -UNIT_TEST(PointDToPointU_Epsilons) -{ - m2::PointD const arrPt[] = {{-180, -180}, {-180, 180}, {180, 180}, {180, -180}}; - m2::PointD const arrD[] = {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}}; - size_t const count = ARRAY_SIZE(arrPt); - - double eps = 1.0; - while (true) - { - size_t i = 0; - for (; i < count; ++i) - { - m2::PointU p0 = PointDToPointU(arrPt[i].x, arrPt[i].y, kCoordBits); - m2::PointU p1 = PointDToPointU(arrPt[i].x + arrD[i].x * eps, - arrPt[i].y + arrD[i].y * eps, - kCoordBits); - - if (p0 != p1) - break; - } - if (i == count) - break; - - eps *= 0.1; - } - - LOG(LINFO, ("Epsilon (relative error) =", eps)); - - for (size_t i = 0; i < count; ++i) - { - m2::PointU const p1 = PointDToPointU(arrPt[i].x, arrPt[i].y, kCoordBits); - m2::PointU const p2(p1.x + arrD[i].x, p1.y + arrD[i].y); - m2::PointD const p3 = PointUToPointD(p2, kCoordBits); - - LOG(LINFO, ("Dx =", p3.x - arrPt[i].x, "Dy =", p3.y - arrPt[i].y)); - } -} diff --git a/coding/geometry_coding.cpp b/coding/geometry_coding.cpp index e6e821bce8..6dd2cd2ccb 100644 --- a/coding/geometry_coding.cpp +++ b/coding/geometry_coding.cpp @@ -1,6 +1,6 @@ #include "coding/geometry_coding.hpp" -#include "coding/point_to_integer.hpp" +#include "coding/point_coding.hpp" #include "geometry/mercator.hpp" @@ -326,14 +326,14 @@ m2::PointU D2U(m2::PointD const & p, uint32_t coordBits) { return PointDToPointU m2::PointD U2D(m2::PointU const & p, uint32_t coordBits) { m2::PointD const pt = PointUToPointD(p, coordBits); - ASSERT(MercatorBounds::minX <= pt.x && pt.y <= MercatorBounds::maxX, (p, pt, coordBits)); - ASSERT(MercatorBounds::minY <= pt.x && pt.y <= MercatorBounds::maxY, (p, pt, coordBits)); + ASSERT(MercatorBounds::kMinX <= pt.x && pt.y <= MercatorBounds::kMaxX, (p, pt, coordBits)); + ASSERT(MercatorBounds::kMinY <= pt.x && pt.y <= MercatorBounds::kMaxY, (p, pt, coordBits)); return pt; } m2::PointU GetMaxPoint(GeometryCodingParams const & params) { - return D2U(m2::PointD(MercatorBounds::maxX, MercatorBounds::maxY), params.GetCoordBits()); + return D2U(m2::PointD(MercatorBounds::kMaxX, MercatorBounds::kMaxY), params.GetCoordBits()); } m2::PointU GetBasePoint(GeometryCodingParams const & params) { return params.GetBasePoint(); } diff --git a/coding/geometry_coding.hpp b/coding/geometry_coding.hpp index 26b8db04e4..28f7869f32 100644 --- a/coding/geometry_coding.hpp +++ b/coding/geometry_coding.hpp @@ -2,7 +2,7 @@ #include "geometry/point2d.hpp" -#include "coding/pointd_to_pointu.hpp" +#include "coding/point_coding.hpp" #include "coding/tesselator_decl.hpp" #include "coding/varint.hpp" #include "coding/writer.hpp" diff --git a/coding/point_coding.cpp b/coding/point_coding.cpp new file mode 100644 index 0000000000..bb65162750 --- /dev/null +++ b/coding/point_coding.cpp @@ -0,0 +1,109 @@ +#include "coding/point_coding.hpp" + +#include "geometry/mercator.hpp" + +#include "base/assert.hpp" +#include "base/bits.hpp" +#include "base/math.hpp" + +namespace +{ +double CoordSize(uint32_t coordBits) { return (1 << coordBits) - 1; } +} // namespace + +uint32_t DoubleToUint32(double x, double min, double max, uint32_t coordBits) +{ + ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); + ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); + x = base::clamp(x, min, max); + uint64_t const fullMask = bits::GetFullMask(static_cast<uint8_t>(coordBits)); + return static_cast<uint32_t>(0.5 + (x - min) / (max - min) * fullMask); +} + +double Uint32ToDouble(uint32_t x, double min, double max, uint32_t coordBits) +{ + ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); + ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); + return min + + static_cast<double>(x) * (max - min) / bits::GetFullMask(static_cast<uint8_t>(coordBits)); +} + +m2::PointU PointDToPointU(double x, double y, uint32_t coordBits) +{ + x = base::clamp(x, MercatorBounds::kMinX, MercatorBounds::kMaxX); + y = base::clamp(y, MercatorBounds::kMinY, MercatorBounds::kMaxY); + + uint32_t const ix = static_cast<uint32_t>( + 0.5 + (x - MercatorBounds::kMinX) / MercatorBounds::kRangeX * CoordSize(coordBits)); + uint32_t const iy = static_cast<uint32_t>( + 0.5 + (y - MercatorBounds::kMinY) / MercatorBounds::kRangeY * CoordSize(coordBits)); + + ASSERT_LESS_OR_EQUAL(ix, CoordSize(coordBits), ()); + ASSERT_LESS_OR_EQUAL(iy, CoordSize(coordBits), ()); + + return m2::PointU(ix, iy); +} + +m2::PointU PointDToPointU(m2::PointD const & pt, uint32_t coordBits) +{ + return PointDToPointU(pt.x, pt.y, coordBits); +} + +m2::PointD PointUToPointD(m2::PointU const & pt, uint32_t coordBits) +{ + return m2::PointD(static_cast<double>(pt.x) * MercatorBounds::kRangeX / CoordSize(coordBits) + + MercatorBounds::kMinX, + static_cast<double>(pt.y) * MercatorBounds::kRangeY / CoordSize(coordBits) + + MercatorBounds::kMinY); +} + +// Obsolete functions ------------------------------------------------------------------------------ + +int64_t PointToInt64Obsolete(double x, double y, uint32_t coordBits) +{ + int64_t const res = static_cast<int64_t>(PointUToUint64Obsolete(PointDToPointU(x, y, coordBits))); + + ASSERT_GREATER_OR_EQUAL(res, 0, ("Highest bits of (ix, iy) are not used, so res should be > 0.")); + ASSERT_LESS_OR_EQUAL(static_cast<uint64_t>(res), uint64_t{3} << 2 * POINT_COORD_BITS, ()); + return res; +} + +int64_t PointToInt64Obsolete(m2::PointD const & pt, uint32_t coordBits) +{ + return PointToInt64Obsolete(pt.x, pt.y, coordBits); +} + +m2::PointD Int64ToPointObsolete(int64_t v, uint32_t coordBits) +{ + ASSERT_GREATER_OR_EQUAL(v, 0, ("Highest bits of (ix, iy) are not used, so res should be > 0.")); + ASSERT_LESS_OR_EQUAL(static_cast<uint64_t>(v), uint64_t{3} << 2 * POINT_COORD_BITS, ()); + return PointUToPointD(Uint64ToPointUObsolete(static_cast<uint64_t>(v)), coordBits); +} + +std::pair<int64_t, int64_t> RectToInt64Obsolete(m2::RectD const & r, uint32_t coordBits) +{ + int64_t const p1 = PointToInt64Obsolete(r.minX(), r.minY(), coordBits); + int64_t const p2 = PointToInt64Obsolete(r.maxX(), r.maxY(), coordBits); + return std::make_pair(p1, p2); +} + +m2::RectD Int64ToRectObsolete(std::pair<int64_t, int64_t> const & p, uint32_t coordBits) +{ + m2::PointD const pt1 = Int64ToPointObsolete(p.first, coordBits); + m2::PointD const pt2 = Int64ToPointObsolete(p.second, coordBits); + return m2::RectD(pt1, pt2); +} + +uint64_t PointUToUint64Obsolete(m2::PointU const & pt) +{ + uint64_t const res = bits::BitwiseMerge(pt.x, pt.y); + ASSERT_EQUAL(pt, Uint64ToPointUObsolete(res), ()); + return res; +} + +m2::PointU Uint64ToPointUObsolete(int64_t v) +{ + m2::PointU res; + bits::BitwiseSplit(v, res.x, res.y); + return res; +} diff --git a/coding/point_coding.hpp b/coding/point_coding.hpp new file mode 100644 index 0000000000..c8dd7e930d --- /dev/null +++ b/coding/point_coding.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include "geometry/point2d.hpp" +#include "geometry/rect2d.hpp" + +#include <cstdint> +#include <utility> + +#define POINT_COORD_BITS 30 + +// 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. +// +// The constant is loosely tied to MercatorBounds::kRangeX / (1 << POINT_COORD_BITS): +// The range of possible values for point coordinates +// MercatorBounds::kRangeX = 360.0 +// The number of distinct values for each coordinate after encoding +// (1 << POINT_COORD_BITS) = 1073741824 ≈ 1e9 +// Distance between two discernible points in the uniform case +// 360.0 / 1e9 ≈ 4e-7 ≈ 0.04 * |kMwmPointAccuracy|. +// +// On the other hand, this should be enough for most purposes because +// 1e-5 difference in the coordinates of a mercator-proected point corresponds to roughly +// 1 meter difference on the equator and we do not expect most OSM points to be mapped +// with better precision. +// +// todo(@m) By this argument, it seems that 1e-6 is a better choice. +double constexpr kMwmPointAccuracy = 1e-5; + +// todo(@m) Explain this constant. +double constexpr kCellIdToPointEps = 1e-4; + +uint32_t DoubleToUint32(double x, double min, double max, uint32_t coordBits); + +double Uint32ToDouble(uint32_t x, double min, double max, uint32_t coordBits); + +m2::PointU PointDToPointU(double x, double y, uint32_t coordBits); + +m2::PointU PointDToPointU(m2::PointD const & pt, uint32_t coordBits); + +m2::PointD PointUToPointD(m2::PointU const & p, uint32_t coordBits); + +// All functions below are deprecated and are left +// only for backward compatibility. +// +// Their intention was to store a point with unsigned 32-bit integer +// coordinates to a signed or to an unsigned 64-bit integer by interleaving the +// bits of the point's coordinates. +// +// A possible reason for interleaving is to lower the number of bytes +// needed by the varint encoding, at least if the coordinates are of the +// same order of magnitude. However, this is hard to justify: +// 1. We have no reason to expect the coordinates to be of the same order. +// 2. If you need to serialize a point, doing it separately +// for each coordinate is almost always a better option. +// 3. If you need to temporarily store the point as an uint, +// you do not need the complexity of interleaving. +// +// Another possible reason to interleave bits of x and y arises +// when implementing the Z-order curve but we have this +// written elsewhere (see geometry/cellid.hpp). + +int64_t PointToInt64Obsolete(double x, double y, uint32_t coordBits); + +int64_t PointToInt64Obsolete(m2::PointD const & pt, uint32_t coordBits); + +m2::PointD Int64ToPointObsolete(int64_t v, uint32_t coordBits); + +std::pair<int64_t, int64_t> RectToInt64Obsolete(m2::RectD const & r, uint32_t coordBits); + +m2::RectD Int64ToRectObsolete(std::pair<int64_t, int64_t> const & p, uint32_t coordBits); + +uint64_t PointUToUint64Obsolete(m2::PointU const & pt); + +m2::PointU Uint64ToPointUObsolete(int64_t v); diff --git a/coding/point_to_integer.cpp b/coding/point_to_integer.cpp deleted file mode 100644 index 2e809e7bf1..0000000000 --- a/coding/point_to_integer.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "coding/point_to_integer.hpp" - -#include "base/assert.hpp" -#include "base/bits.hpp" - -int64_t PointToInt64Obsolete(double x, double y, uint32_t coordBits) -{ - int64_t const res = static_cast<int64_t>(PointUToUint64Obsolete(PointDToPointU(x, y, coordBits))); - - ASSERT_GREATER_OR_EQUAL(res, 0, ("Highest bits of (ix, iy) are not used, so res should be > 0.")); - ASSERT_LESS_OR_EQUAL(static_cast<uint64_t>(res), uint64_t{3} << 2 * POINT_COORD_BITS, ()); - return res; -} - -int64_t PointToInt64Obsolete(m2::PointD const & pt, uint32_t coordBits) -{ - return PointToInt64Obsolete(pt.x, pt.y, coordBits); -} - -m2::PointD Int64ToPointObsolete(int64_t v, uint32_t coordBits) -{ - ASSERT_GREATER_OR_EQUAL(v, 0, ("Highest bits of (ix, iy) are not used, so res should be > 0.")); - ASSERT_LESS_OR_EQUAL(static_cast<uint64_t>(v), uint64_t{3} << 2 * POINT_COORD_BITS, ()); - return PointUToPointD(Uint64ToPointUObsolete(static_cast<uint64_t>(v)), coordBits); -} - -std::pair<int64_t, int64_t> RectToInt64Obsolete(m2::RectD const & r, uint32_t coordBits) -{ - int64_t const p1 = PointToInt64Obsolete(r.minX(), r.minY(), coordBits); - int64_t const p2 = PointToInt64Obsolete(r.maxX(), r.maxY(), coordBits); - return std::make_pair(p1, p2); -} - -m2::RectD Int64ToRectObsolete(std::pair<int64_t, int64_t> const & p, uint32_t coordBits) -{ - m2::PointD const pt1 = Int64ToPointObsolete(p.first, coordBits); - m2::PointD const pt2 = Int64ToPointObsolete(p.second, coordBits); - return m2::RectD(pt1, pt2); -} - -uint64_t PointUToUint64Obsolete(m2::PointU const & pt) -{ - uint64_t const res = bits::BitwiseMerge(pt.x, pt.y); - ASSERT_EQUAL(pt, Uint64ToPointUObsolete(res), ()); - return res; -} - -m2::PointU Uint64ToPointUObsolete(int64_t v) -{ - m2::PointU res; - bits::BitwiseSplit(v, res.x, res.y); - return res; -} diff --git a/coding/point_to_integer.hpp b/coding/point_to_integer.hpp deleted file mode 100644 index 923ab971d4..0000000000 --- a/coding/point_to_integer.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "coding/pointd_to_pointu.hpp" - -#include "geometry/point2d.hpp" -#include "geometry/rect2d.hpp" - -#include <cstdint> -#include <utility> - -// All functions in this file are deprecated and are left -// only for backward compatibility. -// -// Their intention was to store a point with unsigned 32-bit integer -// coordinates to a signed or to an unsigned 64-bit integer by interleaving the -// bits of the point's coordinates. -// -// A possible reason for interleaving is to lower the number of bytes -// needed by the varint encoding, at least if the coordinates are of the -// same order of magnitude. However, this is hard to justify: -// 1. We have no reason to expect the coordinates to be of the same order. -// 2. If you need to serialize a point, doing it separately -// for each coordinate is almost always a better option. -// 3. If you need to temporarily store the point as an uint, -// you do not need the complexity of interleaving. -// -// Another possible reason to interleave bits of x and y arises -// when implementing the Z-order curve but we have this -// written elsewhere (see geometry/cellid.hpp). - -int64_t PointToInt64Obsolete(double x, double y, uint32_t coordBits); - -int64_t PointToInt64Obsolete(m2::PointD const & pt, uint32_t coordBits); - -m2::PointD Int64ToPointObsolete(int64_t v, uint32_t coordBits); - -std::pair<int64_t, int64_t> RectToInt64Obsolete(m2::RectD const & r, uint32_t coordBits); - -m2::RectD Int64ToRectObsolete(std::pair<int64_t, int64_t> const & p, uint32_t coordBits); - -uint64_t PointUToUint64Obsolete(m2::PointU const & pt); - -m2::PointU Uint64ToPointUObsolete(int64_t v); diff --git a/coding/pointd_to_pointu.cpp b/coding/pointd_to_pointu.cpp deleted file mode 100644 index 7dd2593da1..0000000000 --- a/coding/pointd_to_pointu.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "coding/pointd_to_pointu.hpp" - -#include "geometry/mercator.hpp" - -#include "base/bits.hpp" -#include "base/math.hpp" - -namespace -{ -double CoordSize(uint32_t coordBits) { return (1 << coordBits) - 1; } -} // namespace - -uint32_t DoubleToUint32(double x, double min, double max, uint32_t coordBits) -{ - ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); - ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); - x = base::clamp(x, min, max); - return static_cast<uint32_t>(0.5 + (x - min) / (max - min) * bits::GetFullMask(static_cast<uint8_t>(coordBits))); -} - -double Uint32ToDouble(uint32_t x, double min, double max, uint32_t coordBits) -{ - ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); - ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); - return min + static_cast<double>(x) * (max - min) / bits::GetFullMask(static_cast<uint8_t>(coordBits)); -} - -m2::PointU PointDToPointU(double x, double y, uint32_t coordBits) -{ - x = base::clamp(x, MercatorBounds::minX, MercatorBounds::maxX); - y = base::clamp(y, MercatorBounds::minY, MercatorBounds::maxY); - - uint32_t const ix = static_cast<uint32_t>(0.5 + - (x - MercatorBounds::minX) / - (MercatorBounds::maxX - MercatorBounds::minX) * - CoordSize(coordBits)); - uint32_t const iy = static_cast<uint32_t>(0.5 + - (y - MercatorBounds::minY) / - (MercatorBounds::maxY - MercatorBounds::minY) * - CoordSize(coordBits)); - - ASSERT_LESS_OR_EQUAL(ix, CoordSize(coordBits), ()); - ASSERT_LESS_OR_EQUAL(iy, CoordSize(coordBits), ()); - - return m2::PointU(ix, iy); -} - -m2::PointU PointDToPointU(m2::PointD const & pt, uint32_t coordBits) -{ - return PointDToPointU(pt.x, pt.y, coordBits); -} - -m2::PointD PointUToPointD(m2::PointU const & pt, uint32_t coordBits) -{ - return m2::PointD(static_cast<double>(pt.x) * (MercatorBounds::maxX - MercatorBounds::minX) / - CoordSize(coordBits) + - MercatorBounds::minX, - static_cast<double>(pt.y) * (MercatorBounds::maxY - MercatorBounds::minY) / - CoordSize(coordBits) + - MercatorBounds::minY); -} diff --git a/coding/pointd_to_pointu.hpp b/coding/pointd_to_pointu.hpp deleted file mode 100644 index e5fd99a042..0000000000 --- a/coding/pointd_to_pointu.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "geometry/point2d.hpp" - -#include <cstdint> - -#define POINT_COORD_BITS 30 - -uint32_t DoubleToUint32(double x, double min, double max, uint32_t coordBits); - -double Uint32ToDouble(uint32_t x, double min, double max, uint32_t coordBits); - -m2::PointU PointDToPointU(double x, double y, uint32_t coordBits); - -m2::PointU PointDToPointU(m2::PointD const & pt, uint32_t coordBits); - -m2::PointD PointUToPointD(m2::PointU const & p, uint32_t coordBits); diff --git a/coding/traffic.hpp b/coding/traffic.hpp index 97b6d317fb..363cc56e2f 100644 --- a/coding/traffic.hpp +++ b/coding/traffic.hpp @@ -1,6 +1,6 @@ #pragma once -#include "coding/pointd_to_pointu.hpp" +#include "coding/point_coding.hpp" #include "coding/reader.hpp" #include "coding/varint.hpp" #include "coding/writer.hpp" |