From 45bfa50cbacb823901651679a98df9368da7fe1a Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Sat, 17 Feb 2018 13:28:10 -0400 Subject: [PATCH] [offset tool] fix #18115 improved offset calculation * use QgsGeometry::contains for polygons (contains => negative offset) * use the geometry part and not the whole geometry to find closest segment --- src/app/qgsmaptooloffsetcurve.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/qgsmaptooloffsetcurve.cpp b/src/app/qgsmaptooloffsetcurve.cpp index 30038a509f7..c3e6744fa67 100644 --- a/src/app/qgsmaptooloffsetcurve.cpp +++ b/src/app/qgsmaptooloffsetcurve.cpp @@ -367,8 +367,15 @@ double QgsMapToolOffsetCurve::calculateOffset( QgsPointXY mapPoint ) int beforeVertex; int leftOf = 0; - offset = std::sqrt( mOriginalGeometry.closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex, &leftOf ) ); - offset = leftOf < 0 ? offset : -offset; + offset = std::sqrt( mManipulatedGeometry.closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex, &leftOf ) ); + if ( QgsWkbTypes::geometryType( mManipulatedGeometry.wkbType() ) == QgsWkbTypes::LineGeometry ) + { + offset = leftOf < 0 ? offset : -offset; + } + else + { + offset = mManipulatedGeometry.contains( &layerCoords ) ? -offset : offset; + } } return offset; } @@ -573,7 +580,7 @@ void QgsMapToolOffsetCurve::updateGeometryAndRubberBand( double offset ) } else { - offsetGeom = mManipulatedGeometry.buffer( -offset, quadSegments, capStyle, joinStyle, miterLimit ); + offsetGeom = mManipulatedGeometry.buffer( offset, quadSegments, capStyle, joinStyle, miterLimit ); } if ( !offsetGeom )