diff options
author | vng <viktor.govako@gmail.com> | 2011-01-30 20:38:30 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:11:21 +0300 |
commit | 8371e69d15eaeecb270dcbdfa448598d436bb196 (patch) | |
tree | b556c2352c13d370a3a2bad67c9a445f0b58513c /indexer/geometry_serialization.cpp | |
parent | 3551c4143e840e52b7ffb247e7a1c8ebde861965 (diff) |
Build-in new geometry coding API in feature geometry serilization.
Only for pathes for a while ...
Diffstat (limited to 'indexer/geometry_serialization.cpp')
-rw-r--r-- | indexer/geometry_serialization.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/indexer/geometry_serialization.cpp b/indexer/geometry_serialization.cpp new file mode 100644 index 0000000000..63086a8776 --- /dev/null +++ b/indexer/geometry_serialization.cpp @@ -0,0 +1,69 @@ +#include "geometry_serialization.hpp" +#include "mercator.hpp" +#include "point_to_int64.hpp" +#include "geometry_coding.hpp" + +#include "../geometry/pointu_to_uint64.hpp" + +#include "../std/algorithm.hpp" +#include "../std/iterator.hpp" + + +namespace serial +{ + namespace pts + { + inline m2::PointU D2U(m2::PointD const & p) + { + return PointD2PointU(p.x, p.y); + } + + inline m2::PointD U2D(m2::PointU const & p) + { + CoordPointT const pt = PointU2PointD(p); + return m2::PointD(pt.first, pt.second); + } + + inline m2::PointU GetMaxPoint() + { + return D2U(m2::PointD(MercatorBounds::maxX, MercatorBounds::maxY)); + } + + inline m2::PointU GetBasePoint(int64_t base) + { + return m2::Uint64ToPointU(base); + } + } + + void EncodePath(vector<m2::PointD> const & points, int64_t base, vector<uint64_t> & deltas) + { + vector<m2::PointU> upoints; + upoints.reserve(points.size()); + + transform(points.begin(), points.end(), back_inserter(upoints), &pts::D2U); + + geo_coding::EncodePolyline(upoints, pts::GetBasePoint(base), pts::GetMaxPoint(), deltas); + } + + void DecodePath(vector<uint64_t> const & deltas, int64_t base, OutPointsT & points) + { + vector<m2::PointU> upoints; + upoints.reserve(deltas.size()); + + geo_coding::DecodePolyline(deltas, pts::GetBasePoint(base), pts::GetMaxPoint(), upoints); + + points.reserve(upoints.size()); + transform(upoints.begin(), upoints.end(), back_inserter(points), &pts::U2D); + } + + void const * LoadInnerPath(void const * pBeg, size_t count, int64_t base, OutPointsT & points) + { + vector<uint64_t> deltas; + deltas.reserve(count); + void const * ret = ReadVarUint64Array(static_cast<char const *>(pBeg), count, + MakeBackInsertFunctor(deltas)); + + DecodePath(deltas, base, points); + return ret; + } +} |