summaryrefslogtreecommitdiffstats
path: root/server/src/geo.cpp
blob: 1776f3cf77b6796e019530fa227b3d3ee67d1275 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module;

#include <boost/geometry.hpp>

module routemon:geo$impl;

import :geo;

namespace routemon::geo {

auto split_linestring_with_overlap_segments(
    linestring const& ls, double max_split_distance_m,
    std::vector<linestring>& append_to) -> void
{
  if (bgeo::is_empty(ls))
    return;

  auto current_ls = linestring{};
  auto current_ls_length = 0.0;
  auto previous = std::optional<point>{};
  bgeo::for_each_point(
      ls,
      [&](point p) -> void
      {
        bgeo::append(current_ls, p);
        if (previous)
        {
          auto d = bgeo::distance(*previous, p, vincenty_strategy());
          current_ls_length += d;
          if (current_ls_length > max_split_distance_m)
          {
            append_to.push_back(std::move(current_ls));
            current_ls = linestring{*previous, p};
            current_ls_length = d;
          }
        }
        previous = p;
      });
  append_to.emplace_back(std::move(current_ls));
}

} // namespace routemon::geo