@@ -67,24 +67,41 @@ MultiPolygon<int64_t> getTilePolygons(const Feature::geometry_type& polygonGeoSe
6767 [](const auto &) { return MultiPolygon<int64_t >(); });
6868}
6969
70+ void updatePoint (Point<int64_t >& p, WithinBBox& bbox, const WithinBBox& polyBBox, const int64_t worldSize) {
71+ if (p.x <= polyBBox[0 ] || p.x >= polyBBox[2 ]) {
72+ int64_t shift = 0 ;
73+ shift = (p.x - polyBBox[0 ] > worldSize / 2 ) ? -worldSize : (polyBBox[0 ] - p.x > worldSize / 2 ) ? worldSize : 0 ;
74+ if (shift == 0 ) {
75+ shift =
76+ (p.x - polyBBox[2 ] > worldSize / 2 ) ? -worldSize : (polyBBox[2 ] - p.x > worldSize / 2 ) ? worldSize : 0 ;
77+ }
78+ p.x += shift;
79+ }
80+ updateBBox (bbox, p);
81+ }
82+
7083MultiPoint<int64_t > getTilePoints (const GeometryCoordinates& points,
7184 const mbgl::CanonicalTileID& canonical,
72- WithinBBox& bbox) {
85+ WithinBBox& bbox,
86+ const WithinBBox& polyBBox) {
7387 const int64_t xShift = util::EXTENT * canonical.x ;
7488 const int64_t yShift = util::EXTENT * canonical.y ;
89+ const auto worldSize = util::EXTENT * std::pow (2 , canonical.z );
7590 MultiPoint<int64_t > results;
7691 results.reserve (points.size ());
7792 for (const auto & p : points) {
78- const auto point = Point<int64_t >(p.x + xShift, p.y + yShift);
79- updateBBox ( bbox, point );
93+ auto point = Point<int64_t >(p.x + xShift, p.y + yShift);
94+ updatePoint (point, bbox, polyBBox, worldSize );
8095 results.push_back (point);
8196 }
97+
8298 return results;
8399}
84100
85101MultiLineString<int64_t > getTileLines (const GeometryCollection& lines,
86102 const mbgl::CanonicalTileID& canonical,
87- WithinBBox& bbox) {
103+ WithinBBox& bbox,
104+ const WithinBBox& polyBBox) {
88105 const int64_t xShift = util::EXTENT * canonical.x ;
89106 const int64_t yShift = util::EXTENT * canonical.y ;
90107 MultiLineString<int64_t > results;
@@ -99,6 +116,16 @@ MultiLineString<int64_t> getTileLines(const GeometryCollection& lines,
99116 }
100117 results.push_back (std::move (lineString));
101118 }
119+
120+ const auto worldSize = util::EXTENT * std::pow (2 , canonical.z );
121+ if (bbox[2 ] - bbox[0 ] <= worldSize / 2 ) {
122+ bbox = DefaultBBox;
123+ for (auto & line : results) {
124+ for (auto & p : line) {
125+ updatePoint (p, bbox, polyBBox, worldSize);
126+ }
127+ }
128+ }
102129 return results;
103130}
104131
@@ -113,15 +140,15 @@ bool featureWithinPolygons(const GeometryTileFeature& feature,
113140 case FeatureType::Point: {
114141 assert (!geometries.empty ());
115142 WithinBBox pointBBox = DefaultBBox;
116- MultiPoint<int64_t > points = getTilePoints (geometries.at (0 ), canonical, pointBBox);
143+ MultiPoint<int64_t > points = getTilePoints (geometries.at (0 ), canonical, pointBBox, polyBBox );
117144 if (!boxWithinBox (pointBBox, polyBBox)) return false ;
118145
119146 return std::all_of (
120147 points.begin (), points.end (), [&polygons](const auto & p) { return pointWithinPolygons (p, polygons); });
121148 }
122149 case FeatureType::LineString: {
123150 WithinBBox lineBBox = DefaultBBox;
124- MultiLineString<int64_t > multiLineString = getTileLines (geometries, canonical, lineBBox);
151+ MultiLineString<int64_t > multiLineString = getTileLines (geometries, canonical, lineBBox, polyBBox );
125152 if (!boxWithinBox (lineBBox, polyBBox)) return false ;
126153
127154 return std::all_of (multiLineString.begin (), multiLineString.end (), [&polygons](const auto & line) {
0 commit comments