MCPcopy Create free account
hub / github.com/comaps/comaps / Simplify

Method Simplify

libs/map/routing_manager.cpp:1329–1392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1327}
1328
1329void RoutingManager::DistanceAltitude::Simplify(double altitudeDeviation)
1330{
1331 class IterT
1332 {
1333 DistanceAltitude const & m_da;
1334 size_t m_ind = 0;
1335
1336 public:
1337 IterT(DistanceAltitude const & da, bool isBeg) : m_da(da) { m_ind = isBeg ? 0 : m_da.GetSize(); }
1338
1339 IterT(IterT const & rhs) = default;
1340 IterT & operator=(IterT const & rhs)
1341 {
1342 m_ind = rhs.m_ind;
1343 return *this;
1344 }
1345
1346 bool operator!=(IterT const & rhs) const { return m_ind != rhs.m_ind; }
1347
1348 IterT & operator++()
1349 {
1350 ++m_ind;
1351 return *this;
1352 }
1353 IterT operator+(size_t inc) const
1354 {
1355 IterT res = *this;
1356 res.m_ind += inc;
1357 return res;
1358 }
1359 int64_t operator-(IterT const & rhs) const { return int64_t(m_ind) - int64_t(rhs.m_ind); }
1360
1361 m2::PointD operator*() const { return {m_da.m_distances[m_ind], double(m_da.m_altitudes[m_ind])}; }
1362 };
1363
1364 std::vector<m2::PointD> out;
1365
1366 // 1. Deviation from approximated altitude.
1367 // double constexpr eps = 1.415; // ~sqrt(2)
1368 // struct DeviationFromApproxY
1369 // {
1370 // double operator()(m2::PointD const & a, m2::PointD const & b, m2::PointD const & x) const
1371 // {
1372 // double f = (x.x - a.x) / (b.x - a.x);
1373 // ASSERT(0 <= f && f <= 1, (f)); // distance is an icreasing function
1374 // double const approxY = (1 - f) * a.y + f * b.y;
1375 // return fabs(approxY - x.y);
1376 // }
1377 // } distFn;
1378 // SimplifyNearOptimal(20 /* maxFalseLookAhead */, IterT(*this, true), IterT(*this, false),
1379 // eps, distFn, AccumulateSkipSmallTrg(distFn, out, eps));
1380
1381 // 2. Default square distance from segment.
1382 SimplifyDefault(IterT(*this, true), IterT(*this, false), math::Pow2(altitudeDeviation), out);
1383
1384 size_t const count = out.size();
1385 m_distances.resize(count);
1386 m_altitudes.resize(count);

Calls 5

SimplifyDefaultFunction · 0.85
IterTClass · 0.85
Pow2Function · 0.85
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected