diff options
| author | Rutger Broekhoff | 2026-08-29 12:01:42 +0200 |
|---|---|---|
| committer | Rutger Broekhoff | 2026-08-29 12:01:42 +0200 |
| commit | 52b3cd46c76fd4be18aeb8422a08a073484b9fad (patch) | |
| tree | b4f23957c096e6bce5369bb94a4e8e23de71761a /server/src/geo.cpp | |
| parent | 35878b76049b9c3e752480e9f298b7e2da6fdf1f (diff) | |
| download | routemon-52b3cd46c76fd4be18aeb8422a08a073484b9fad.tar.gz routemon-52b3cd46c76fd4be18aeb8422a08a073484b9fad.zip | |
More module implementation partition units
Diffstat (limited to 'server/src/geo.cpp')
| -rw-r--r-- | server/src/geo.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/server/src/geo.cpp b/server/src/geo.cpp new file mode 100644 index 0000000..1776f3c --- /dev/null +++ b/server/src/geo.cpp | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <boost/geometry.hpp> | ||
| 4 | |||
| 5 | module routemon:geo$impl; | ||
| 6 | |||
| 7 | import :geo; | ||
| 8 | |||
| 9 | namespace routemon::geo { | ||
| 10 | |||
| 11 | auto split_linestring_with_overlap_segments( | ||
| 12 | linestring const& ls, double max_split_distance_m, | ||
| 13 | std::vector<linestring>& append_to) -> void | ||
| 14 | { | ||
| 15 | if (bgeo::is_empty(ls)) | ||
| 16 | return; | ||
| 17 | |||
| 18 | auto current_ls = linestring{}; | ||
| 19 | auto current_ls_length = 0.0; | ||
| 20 | auto previous = std::optional<point>{}; | ||
| 21 | bgeo::for_each_point( | ||
| 22 | ls, | ||
| 23 | [&](point p) -> void | ||
| 24 | { | ||
| 25 | bgeo::append(current_ls, p); | ||
| 26 | if (previous) | ||
| 27 | { | ||
| 28 | auto d = bgeo::distance(*previous, p, vincenty_strategy()); | ||
| 29 | current_ls_length += d; | ||
| 30 | if (current_ls_length > max_split_distance_m) | ||
| 31 | { | ||
| 32 | append_to.push_back(std::move(current_ls)); | ||
| 33 | current_ls = linestring{*previous, p}; | ||
| 34 | current_ls_length = d; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | previous = p; | ||
| 38 | }); | ||
| 39 | append_to.emplace_back(std::move(current_ls)); | ||
| 40 | } | ||
| 41 | |||
| 42 | } // namespace routemon::geo | ||