summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-07-16 22:29:40 +0300
committerAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-07-16 22:55:40 +0300
commitf5ecbc0d058a63bb2b29a0ef74d7b87c9ddced12 (patch)
tree02ea89ef78565fa9c965b65672aa54c2b9a81411
parentd2434d07517619d390e2e1f4b7952f6cf2c9e4ff (diff)
downloadqtlocation-mapboxgl-upstream/annotations-with-edgeinsets.tar.gz
[core] Fix collision with content insetsupstream/annotations-with-edgeinsets
Viewport center offset usage was wrongly submitted in #14664. It was part of alternative approach that used enlarged viewport. Existing and added tests were not sufficient to spot the regression, since the collision check padding is usually larger than the center offset x and y. Annotation picking has tolerance of only 10 pixels but no annotation integration test was using content insets. Usage of offset is not needed because `posMatrix` in e.g. `CollisionIndex::projectPoint(const mat4& posMatrix, const Point<float>& point)` already incorporates center offset (projection matrix) and the code in current master was just offsetting all by the value. Modified [ios] MGLAnnotationViewIntegrationTests.testSelectingAnnotationWithCenterOffset to use different insets. It verifies the fix. Fixes [iOS] Annotations are not selectable (added via iosapp menu) #15106: In case of #15106, view's original content insets is {top:88, bottom:34}, causing that center offset is {x:0, y:27} and selection with tolerance of 10 wouldn't select annotation. After tapping the view, so that the header gets removed, view's content insets get changed to {top:44, bottom:34}, center offset is {x:0, y:5} and annotation selection would work, as described in #15106. Fixes: #15106
-rw-r--r--platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m10
-rw-r--r--src/mbgl/map/transform_state.cpp8
-rw-r--r--src/mbgl/map/transform_state.hpp8
-rw-r--r--src/mbgl/text/collision_index.cpp10
4 files changed, 18 insertions, 18 deletions
diff --git a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m
index 162bfc5237..f129277e87 100644
--- a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m
+++ b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m
@@ -401,15 +401,17 @@ static const CGPoint kAnnotationRelativeScale = { 0.05f, 0.125f };
for (CGFloat dx = -100.0; dx <= 100.0; dx += 100.0 ) {
for (CGFloat dy = -100.0; dy <= 100.0; dy += 100.0 ) {
CGVector offset = CGVectorMake(dx, dy);
- [self internalTestSelectingAnnotationWithCenterOffsetWithOffset:offset];
+ UIEdgeInsets edgeInsets = UIEdgeInsetsMake(fmax(-dy, 0.0), fmax(-dy, 0.0), fmax(dy, 0.0), fmax(dx, 0.0));
+ [self internalTestSelectingAnnotationWithCenterOffsetWithOffset:offset edgeInsets:edgeInsets];
}
}
}
-- (void)internalTestSelectingAnnotationWithCenterOffsetWithOffset:(CGVector)offset {
+- (void)internalTestSelectingAnnotationWithCenterOffsetWithOffset:(CGVector)offset edgeInsets:(UIEdgeInsets)edgeInsets {
NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer";
+ self.mapView.contentInset = edgeInsets;
CGSize size = self.mapView.bounds.size;
CGSize annotationSize = CGSizeMake(40.0, 40.0);
@@ -449,8 +451,8 @@ static const CGPoint kAnnotationRelativeScale = { 0.05f, 0.125f };
// Check that the annotation is in the center of the view
CGPoint annotationPoint = [self.mapView convertCoordinate:point.coordinate toPointToView:self.mapView];
- XCTAssertEqualWithAccuracy(annotationPoint.x, size.width/2.0, 0.25);
- XCTAssertEqualWithAccuracy(annotationPoint.y, size.height/2.0, 0.25);
+ XCTAssertEqualWithAccuracy(annotationPoint.x, (size.width - edgeInsets.right + edgeInsets.left)/2.0, 0.25);
+ XCTAssertEqualWithAccuracy(annotationPoint.y, (size.height - edgeInsets.bottom + edgeInsets.top)/2.0, 0.25);
// Now test taps around the annotation
CGPoint tapPoint = CGPointMake(annotationPoint.x + offset.dx, annotationPoint.y + offset.dy);
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index f1d45c043c..92c02d0bc7 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -226,10 +226,6 @@ double TransformState::getMaxZoom() const {
return scaleZoom(max_scale);
}
-ScreenCoordinate TransformState::getCenterOffset() const {
- return { 0.5 * (edgeInsets.left() - edgeInsets.right()), 0.5 * (edgeInsets.top() - edgeInsets.bottom()) };
-}
-
#pragma mark - Rotation
float TransformState::getBearing() const {
@@ -377,6 +373,10 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const {
}
}
+ScreenCoordinate TransformState::getCenterOffset() const {
+ return { 0.5 * (edgeInsets.left() - edgeInsets.right()), 0.5 * (edgeInsets.top() - edgeInsets.bottom()) };
+}
+
void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& anchor) {
auto centerCoord = Projection::project(getLatLng(LatLng::Unwrapped), scale);
auto latLngCoord = Projection::project(latLng, scale);
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 187d266c8a..cca42db20f 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -65,10 +65,6 @@ public:
void setMaxZoom(double);
double getMaxZoom() const;
- // Viewport center offset, from [size.width / 2, size.height / 2], defined
- // by |edgeInsets| in screen coordinates, with top left origin.
- ScreenCoordinate getCenterOffset() const;
-
// Rotation
float getBearing() const;
float getFieldOfView() const;
@@ -100,6 +96,10 @@ private:
bool rotatedNorth() const;
void constrain(double& scale, double& x, double& y) const;
+ // Viewport center offset, from [size.width / 2, size.height / 2], defined
+ // by |edgeInsets| in screen coordinates, with top left origin.
+ ScreenCoordinate getCenterOffset() const;
+
LatLngBounds bounds;
// Limit the amount of zooming possible on the map.
diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp
index e3d832a854..74923312d5 100644
--- a/src/mbgl/text/collision_index.cpp
+++ b/src/mbgl/text/collision_index.cpp
@@ -348,12 +348,11 @@ std::pair<float,float> CollisionIndex::projectAnchor(const mat4& posMatrix, cons
std::pair<Point<float>,float> CollisionIndex::projectAndGetPerspectiveRatio(const mat4& posMatrix, const Point<float>& point) const {
vec4 p = {{ point.x, point.y, 0, 1 }};
matrix::transformMat4(p, p, posMatrix);
- auto offset = transformState.getCenterOffset();
auto size = transformState.getSize();
return std::make_pair(
Point<float>(
- (((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding + offset.x,
- (((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding + offset.y
+ (((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding,
+ (((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding
),
// See perspective ratio comment in symbol_sdf.vertex
// We're doing collision detection in viewport space so we need
@@ -365,11 +364,10 @@ std::pair<Point<float>,float> CollisionIndex::projectAndGetPerspectiveRatio(cons
Point<float> CollisionIndex::projectPoint(const mat4& posMatrix, const Point<float>& point) const {
vec4 p = {{ point.x, point.y, 0, 1 }};
matrix::transformMat4(p, p, posMatrix);
- auto offset = transformState.getCenterOffset();
auto size = transformState.getSize();
return Point<float> {
- static_cast<float>((((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding + offset.x),
- static_cast<float>((((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding + offset.y) };
+ static_cast<float>((((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding),
+ static_cast<float>((((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding) };
}
} // namespace mbgl