From 5ff12f41e79de071221410bcbb373f2f23e9427b Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 15 Apr 2022 09:22:52 +1000 Subject: [PATCH] Account for non-equal axis scaling during snapping --- python/core/auto_generated/elevation/qgsprofilesnapping.sip.in | 2 +- src/core/elevation/qgsprofilerenderer.cpp | 2 +- src/core/elevation/qgsprofilesnapping.h | 2 +- src/gui/elevation/qgselevationprofilecanvas.cpp | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/python/core/auto_generated/elevation/qgsprofilesnapping.sip.in b/python/core/auto_generated/elevation/qgsprofilesnapping.sip.in index 502d2c5cfe5..bba3d795741 100644 --- a/python/core/auto_generated/elevation/qgsprofilesnapping.sip.in +++ b/python/core/auto_generated/elevation/qgsprofilesnapping.sip.in @@ -25,7 +25,7 @@ Encapsulates the context of snapping a profile point. double maximumElevationDelta; - double displayRationElevationVsDistance; + double displayRatioElevationVsDistance; }; diff --git a/src/core/elevation/qgsprofilerenderer.cpp b/src/core/elevation/qgsprofilerenderer.cpp index fea387c450f..2cc08206041 100644 --- a/src/core/elevation/qgsprofilerenderer.cpp +++ b/src/core/elevation/qgsprofilerenderer.cpp @@ -197,7 +197,7 @@ QgsProfileSnapResult QgsProfilePlotRenderer::snapPoint( const QgsProfilePoint &p if ( jobSnapResult.isValid() ) { const double snapDistance = std::pow( point.distance() - jobSnapResult.snappedPoint.distance(), 2 ) - + std::pow( point.elevation() - jobSnapResult.snappedPoint.elevation(), 2 ); + + std::pow( ( point.elevation() - jobSnapResult.snappedPoint.elevation() ) * context.displayRatioElevationVsDistance, 2 ); if ( snapDistance < bestSnapDistance ) { diff --git a/src/core/elevation/qgsprofilesnapping.h b/src/core/elevation/qgsprofilesnapping.h index 207328bb442..40826c7b0bf 100644 --- a/src/core/elevation/qgsprofilesnapping.h +++ b/src/core/elevation/qgsprofilesnapping.h @@ -38,7 +38,7 @@ class CORE_EXPORT QgsProfileSnapContext double maximumElevationDelta = 0; //! Display ratio of elevation vs distance units - double displayRationElevationVsDistance = 1; + double displayRatioElevationVsDistance = 1; }; diff --git a/src/gui/elevation/qgselevationprofilecanvas.cpp b/src/gui/elevation/qgselevationprofilecanvas.cpp index 822fd61ee5a..cf50146fd08 100644 --- a/src/gui/elevation/qgselevationprofilecanvas.cpp +++ b/src/gui/elevation/qgselevationprofilecanvas.cpp @@ -355,6 +355,8 @@ QgsProfileSnapContext QgsElevationProfileCanvas::snapContext() const QgsProfileSnapContext context; context.maximumDistanceDelta = xToleranceInPlotUnits; context.maximumElevationDelta = yToleranceInPlotUnits; + context.displayRatioElevationVsDistance = ( ( mPlotItem->yMaximum() - mPlotItem->yMinimum() ) / ( mPlotItem->plotArea().height() ) ) + / ( ( mPlotItem->xMaximum() - mPlotItem->xMinimum() ) / ( mPlotItem->plotArea().width() ) ); return context; }