diff options
author | Maxim Pimenov <m@maps.me> | 2018-04-09 14:27:33 +0300 |
---|---|---|
committer | Roman Kuznetsov <r.kuznetsow@gmail.com> | 2018-04-10 14:31:32 +0300 |
commit | 8651b85289754a09b662e0412b5cae172284c3be (patch) | |
tree | 08d176fad5682b2b54397c3066b5cc553846b4c5 /coding/point_to_integer.cpp | |
parent | 9666660b84740e6bbe0585e59fccd1347c4c793f (diff) |
[coding] [geometry] Deprecated PointToInt.
For some reason we have been using bitwise merge to store
a pair of 32-bit unsigned integer coordinates. Since the
width of the coordinates is fixed and storage in general
has nothing to do with the Z-order curve where bitwise
merge is appropriate, this commit marks this method of
storage as obsolete (and effectively deprecated).
The functions to convert between PointD and PointU are
still serviceable. Their usage is slightly refactored.
Diffstat (limited to 'coding/point_to_integer.cpp')
-rw-r--r-- | coding/point_to_integer.cpp | 77 |
1 files changed, 21 insertions, 56 deletions
diff --git a/coding/point_to_integer.cpp b/coding/point_to_integer.cpp index 002cf98b3d..b477b8d3ec 100644 --- a/coding/point_to_integer.cpp +++ b/coding/point_to_integer.cpp @@ -1,87 +1,52 @@ #include "coding/point_to_integer.hpp" -#include "geometry/mercator.hpp" -#include "geometry/pointu_to_uint64.hpp" - +#include "base/assert.hpp" #include "base/bits.hpp" -#include <algorithm> - -namespace +int64_t PointToInt64Obsolete(double x, double y, uint32_t coordBits) { -inline double CoordSize(uint32_t coordBits) { return (1 << coordBits) - 1; } -} - -m2::PointU PointD2PointU(double x, double y, uint32_t coordBits) -{ - x = my::clamp(x, MercatorBounds::minX, MercatorBounds::maxX); - y = my::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); -} - -int64_t PointToInt64(double x, double y, uint32_t coordBits) -{ - int64_t const res = static_cast<int64_t>(m2::PointUToUint64(PointD2PointU(x, y, coordBits))); + int64_t const res = static_cast<int64_t>(PointUToUint64Obsolete(PointDToPointU(x, y, coordBits))); ASSERT_LESS_OR_EQUAL(res, 3ULL << 2 * POINT_COORD_BITS, ()); ASSERT_GREATER_OR_EQUAL(res, 0, ("Highest bits of (ix, iy) are not used, so res should be > 0.")); return res; } -m2::PointD PointU2PointD(m2::PointU const & pt, uint32_t coordBits) +int64_t PointToInt64Obsolete(m2::PointD 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); + return PointToInt64Obsolete(pt.x, pt.y, coordBits); } -m2::PointD Int64ToPoint(int64_t v, uint32_t coordBits) +m2::PointD Int64ToPointObsolete(int64_t v, uint32_t coordBits) { ASSERT_LESS_OR_EQUAL(v, 3ULL << 2 * POINT_COORD_BITS, ()); - return PointU2PointD(m2::Uint64ToPointU(static_cast<uint64_t>(v)), coordBits); + return PointUToPointD(Uint64ToPointUObsolete(static_cast<uint64_t>(v)), coordBits); } -std::pair<int64_t, int64_t> RectToInt64(m2::RectD const & r, uint32_t coordBits) +std::pair<int64_t, int64_t> RectToInt64Obsolete(m2::RectD const & r, uint32_t coordBits) { - int64_t const p1 = PointToInt64(r.minX(), r.minY(), coordBits); - int64_t const p2 = PointToInt64(r.maxX(), r.maxY(), 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 Int64ToRect(std::pair<int64_t, int64_t> const & p, uint32_t coordBits) +m2::RectD Int64ToRectObsolete(std::pair<int64_t, int64_t> const & p, uint32_t coordBits) { - m2::PointD const pt1 = Int64ToPoint(p.first, coordBits); - m2::PointD const pt2 = Int64ToPoint(p.second, coordBits); + m2::PointD const pt1 = Int64ToPointObsolete(p.first, coordBits); + m2::PointD const pt2 = Int64ToPointObsolete(p.second, coordBits); return m2::RectD(pt1, pt2); } -uint32_t DoubleToUint32(double x, double min, double max, uint32_t coordBits) +uint64_t PointUToUint64Obsolete(m2::PointU const & pt) { - ASSERT_GREATER_OR_EQUAL(coordBits, 1, ()); - ASSERT_LESS_OR_EQUAL(coordBits, 32, ()); - x = my::clamp(x, min, max); - return static_cast<uint32_t>(0.5 + (x - min) / (max - min) * bits::GetFullMask(static_cast<uint8_t>(coordBits))); + uint64_t const res = bits::BitwiseMerge(pt.x, pt.y); + ASSERT_EQUAL(pt, Uint64ToPointUObsolete(res), ()); + return res; } -double Uint32ToDouble(uint32_t x, double min, double max, uint32_t coordBits) +m2::PointU Uint64ToPointUObsolete(int64_t v) { - 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 res; + bits::BitwiseSplit(v, res.x, res.y); + return res; } |