@@ -389,3 +389,75 @@ TEST(PropertyExpression, WithinExpression) {
389389 EXPECT_FALSE (evaluatedResult);
390390 }
391391}
392+
393+ TEST (PropertyExpression, WithinExpressionAntiMeridain) {
394+ CanonicalTileID canonicalTileID (0 , 0 , 0 );
395+
396+ // evaluation test with line geometries
397+ {
398+ static const std::string polygon1 = R"data(
399+ {
400+ "type": "Polygon",
401+ "coordinates": [[[-190, 0], [-178, 0], [-178, 10], [-190, 10], [-190, 0]]]
402+ })data" ;
403+ // evaluation test with valid geojson source
404+ std::stringstream ss;
405+ ss << std::string (R"( ["within", )" ) << polygon1 << std::string (R"( ])" );
406+ auto expression = createExpression (ss.str ().c_str ());
407+ ASSERT_TRUE (expression);
408+ PropertyExpression<bool > propExpr (std::move (expression));
409+
410+ LineString<double > testLine0{{-183 , 5 }, {-179 , 1 }};
411+ auto geoLine0 = convertGeometry (testLine0, canonicalTileID);
412+ StubGeometryTileFeature lineFeature0 (FeatureType::LineString, geoLine0);
413+
414+ LineString<double > testLine1{{183 , 5 }, {181 , 1 }};
415+ auto geoLine1 = convertGeometry (testLine1, canonicalTileID);
416+ StubGeometryTileFeature lineFeature1 (FeatureType::LineString, geoLine1);
417+
418+ auto evaluatedResult =
419+ propExpr.evaluate (EvaluationContext (&lineFeature0).withCanonicalTileID (&canonicalTileID));
420+ EXPECT_TRUE (evaluatedResult);
421+ evaluatedResult = propExpr.evaluate (EvaluationContext (&lineFeature1).withCanonicalTileID (&canonicalTileID));
422+ EXPECT_FALSE (evaluatedResult);
423+ }
424+
425+ // evaluation test with point geometries
426+ {
427+ static const std::string polygon2 = R"data(
428+ {
429+ "type": "Polygon",
430+ "coordinates": [[[-185.0, 60.0], [-175.0, 60.0], [-175.0, 65.0], [-185.0, 65.0], [-185.0, 60.0]]]
431+ })data" ;
432+ // evaluation test with valid geojson source
433+ std::stringstream ss;
434+ ss << std::string (R"( ["within", )" ) << polygon2 << std::string (R"( ])" );
435+ auto expression = createExpression (ss.str ().c_str ());
436+ ASSERT_TRUE (expression);
437+ PropertyExpression<bool > propExpr (std::move (expression));
438+
439+ auto getPointFeature = [&canonicalTileID](const Point<double >& testPoint) -> StubGeometryTileFeature {
440+ auto geoPoint = convertGeometry (testPoint, canonicalTileID);
441+ StubGeometryTileFeature pointFeature (FeatureType::Point, geoPoint);
442+ return pointFeature;
443+ };
444+
445+ // check `within` algorithm
446+ auto pointFeature = getPointFeature (Point<double >(177 , 62.5 ));
447+ auto evaluatedResult =
448+ propExpr.evaluate (EvaluationContext (&pointFeature).withCanonicalTileID (&canonicalTileID));
449+ EXPECT_TRUE (evaluatedResult);
450+
451+ pointFeature = getPointFeature (Point<double >(180 , 62.5 ));
452+ evaluatedResult = propExpr.evaluate (EvaluationContext (&pointFeature).withCanonicalTileID (&canonicalTileID));
453+ EXPECT_TRUE (evaluatedResult);
454+
455+ pointFeature = getPointFeature (Point<double >(-180 , 62.5 ));
456+ evaluatedResult = propExpr.evaluate (EvaluationContext (&pointFeature).withCanonicalTileID (&canonicalTileID));
457+ EXPECT_TRUE (evaluatedResult);
458+
459+ pointFeature = getPointFeature (Point<double >(-190 , 62.5 ));
460+ evaluatedResult = propExpr.evaluate (EvaluationContext (&pointFeature).withCanonicalTileID (&canonicalTileID));
461+ EXPECT_FALSE (evaluatedResult);
462+ }
463+ }
0 commit comments