Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit e9b99a5

Browse files
committed
Address review finding
Remove unncessary condition check
1 parent 25ad9d1 commit e9b99a5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/mbgl/style/expression/within.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ MultiPolygon<int64_t> getTilePolygons(const Feature::geometry_type& polygonGeoSe
6868
}
6969

7070
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-
}
71+
if (p.x < polyBBox[0] || p.x > polyBBox[2]) {
72+
const auto getShift = [](Point<int64_t>& point, const int64_t polygonSide, const int64_t size) -> int64_t {
73+
if (point.x - polygonSide > size / 2) {
74+
return -size;
75+
}
76+
if (polygonSide - point.x > size / 2) {
77+
return size;
78+
}
79+
return 0;
80+
};
81+
82+
int64_t shift = getShift(p, polyBBox[0], worldSize);
83+
if (shift == 0) shift = getShift(p, polyBBox[2], worldSize);
7884
p.x += shift;
7985
}
8086
updateBBox(bbox, p);

test/style/property_expression.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ TEST(PropertyExpression, WithinExpression) {
390390
}
391391
}
392392

393-
TEST(PropertyExpression, WithinExpressionAntiMeridain) {
393+
TEST(PropertyExpression, WithinExpressionAntiMeridian) {
394394
CanonicalTileID canonicalTileID(0, 0, 0);
395395

396396
// evaluation test with line geometries

0 commit comments

Comments
 (0)