diff --git a/app/inpututils.cpp b/app/inpututils.cpp index b5573eb39..02a874e8d 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -330,13 +330,12 @@ QPointF InputUtils::relevantGeometryCenterToScreenCoordinates( const QgsGeometry const QgsRectangle currentExtent = mapSettings->mapSettings().visibleExtent(); - // Cut the geometry to current extent - const QgsGeometry currentExtentAsGeom = QgsGeometry::fromRect( currentExtent ); - const QgsGeometry intersectedGeom = geom.intersection( currentExtentAsGeom ); + // Cut the geometry extent to current extent + const QgsRectangle intersectedExtent = currentExtent.intersect( geom.boundingBox() ); - if ( !intersectedGeom.isEmpty() ) + if ( !intersectedExtent.isEmpty() ) { - target = QgsPoint( intersectedGeom.boundingBox().center() ); + target = QgsPoint( intersectedExtent.center() ); } else { diff --git a/app/test/testutilsfunctions.cpp b/app/test/testutilsfunctions.cpp index 7ac5d6302..376852341 100644 --- a/app/test/testutilsfunctions.cpp +++ b/app/test/testutilsfunctions.cpp @@ -968,7 +968,7 @@ void TestUtilsFunctions::testRelevantGeometryCenterToScreenCoordinates() // Case when we cut the geometry to current extent ms.setExtent( QgsRectangle( 599032, 5.40671e+06, 619818, 5.43961e+06 ) ); - QCOMPARE( InputUtils::equals( mUtils->relevantGeometryCenterToScreenCoordinates( geom, &ms ), QPointF( 286.257, 274.5 ), epsilon ), true ); + QCOMPARE( InputUtils::equals( mUtils->relevantGeometryCenterToScreenCoordinates( geom, &ms ), QPointF( 286.261, 304.496 ), epsilon ), true ); } void TestUtilsFunctions::testIsValidEmail()