diff options
author | zmiao <miao.zhao@mapbox.com> | 2020-03-24 14:29:35 +0200 |
---|---|---|
committer | zmiao <miao.zhao@mapbox.com> | 2020-03-26 14:13:59 +0200 |
commit | e9b99a52334d4bd6bf6fc8d259fc59c4d1b03166 (patch) | |
tree | 10090e9a85c0d1728cd8ce37b51f28646a96084c | |
parent | 25ad9d184de1b093a51e5a5302477bc2fae25431 (diff) | |
download | qtlocation-mapboxgl-e9b99a52334d4bd6bf6fc8d259fc59c4d1b03166.tar.gz |
Address review finding
Remove unncessary condition check
-rw-r--r-- | src/mbgl/style/expression/within.cpp | 20 | ||||
-rw-r--r-- | test/style/property_expression.test.cpp | 2 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/mbgl/style/expression/within.cpp b/src/mbgl/style/expression/within.cpp index 271bf8f175..99449a50bd 100644 --- a/src/mbgl/style/expression/within.cpp +++ b/src/mbgl/style/expression/within.cpp @@ -68,13 +68,19 @@ MultiPolygon<int64_t> getTilePolygons(const Feature::geometry_type& polygonGeoSe } void updatePoint(Point<int64_t>& p, WithinBBox& bbox, const WithinBBox& polyBBox, const int64_t worldSize) { - if (p.x <= polyBBox[0] || p.x >= polyBBox[2]) { - int64_t shift = 0; - shift = (p.x - polyBBox[0] > worldSize / 2) ? -worldSize : (polyBBox[0] - p.x > worldSize / 2) ? worldSize : 0; - if (shift == 0) { - shift = - (p.x - polyBBox[2] > worldSize / 2) ? -worldSize : (polyBBox[2] - p.x > worldSize / 2) ? worldSize : 0; - } + if (p.x < polyBBox[0] || p.x > polyBBox[2]) { + const auto getShift = [](Point<int64_t>& point, const int64_t polygonSide, const int64_t size) -> int64_t { + if (point.x - polygonSide > size / 2) { + return -size; + } + if (polygonSide - point.x > size / 2) { + return size; + } + return 0; + }; + + int64_t shift = getShift(p, polyBBox[0], worldSize); + if (shift == 0) shift = getShift(p, polyBBox[2], worldSize); p.x += shift; } updateBBox(bbox, p); diff --git a/test/style/property_expression.test.cpp b/test/style/property_expression.test.cpp index 558ce4e685..570ba4a6f3 100644 --- a/test/style/property_expression.test.cpp +++ b/test/style/property_expression.test.cpp @@ -390,7 +390,7 @@ TEST(PropertyExpression, WithinExpression) { } } -TEST(PropertyExpression, WithinExpressionAntiMeridain) { +TEST(PropertyExpression, WithinExpressionAntiMeridian) { CanonicalTileID canonicalTileID(0, 0, 0); // evaluation test with line geometries |