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