1#pragma once
2
3#include <mapbox/geojsonvt/clip.hpp>
4#include <mapbox/geojsonvt/types.hpp>
5
6namespace mapbox {
7namespace geojsonvt {
8namespace detail {
9
10inline void shiftCoords(vt_features& features, double offset) {
11 for (auto& feature : features) {
12 mapbox::geometry::for_each_point(geom&: feature.geometry,
13 f: [offset](vt_point& point) { point.x += offset; });
14 feature.bbox.min.x += offset;
15 feature.bbox.max.x += offset;
16 }
17}
18
19inline vt_features wrap(const vt_features& features, double buffer) {
20 // left world copy
21 auto left = clip<0>(features, k1: -1 - buffer, k2: buffer, minAll: -1, maxAll: 2);
22 // right world copy
23 auto right = clip<0>(features, k1: 1 - buffer, k2: 2 + buffer, minAll: -1, maxAll: 2);
24
25 if (left.empty() && right.empty())
26 return features;
27
28 // center world copy
29 auto merged = clip<0>(features, k1: -buffer, k2: 1 + buffer, minAll: -1, maxAll: 2);
30
31 if (!left.empty()) {
32 // merge left into center
33 shiftCoords(features&: left, offset: 1.0);
34 merged.insert(position: merged.begin(), first: left.begin(), last: left.end());
35 }
36 if (!right.empty()) {
37 // merge right into center
38 shiftCoords(features&: right, offset: -1.0);
39 merged.insert(position: merged.end(), first: right.begin(), last: right.end());
40 }
41 return merged;
42}
43
44} // namespace detail
45} // namespace geojsonvt
46} // namespace mapbox
47

source code of qtlocation/src/3rdparty/mapbox-gl-native/deps/geojsonvt/6.5.1/include/mapbox/geojsonvt/wrap.hpp