Skip to content

Commit 45bfa50

Browse files
committed
[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
1 parent cad45c0 commit 45bfa50

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/app/qgsmaptooloffsetcurve.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,15 @@ double QgsMapToolOffsetCurve::calculateOffset( QgsPointXY mapPoint )
367367
int beforeVertex;
368368
int leftOf = 0;
369369

370-
offset = std::sqrt( mOriginalGeometry.closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex, &leftOf ) );
371-
offset = leftOf < 0 ? offset : -offset;
370+
offset = std::sqrt( mManipulatedGeometry.closestSegmentWithContext( layerCoords, minDistPoint, beforeVertex, &leftOf ) );
371+
if ( QgsWkbTypes::geometryType( mManipulatedGeometry.wkbType() ) == QgsWkbTypes::LineGeometry )
372+
{
373+
offset = leftOf < 0 ? offset : -offset;
374+
}
375+
else
376+
{
377+
offset = mManipulatedGeometry.contains( &layerCoords ) ? -offset : offset;
378+
}
372379
}
373380
return offset;
374381
}
@@ -573,7 +580,7 @@ void QgsMapToolOffsetCurve::updateGeometryAndRubberBand( double offset )
573580
}
574581
else
575582
{
576-
offsetGeom = mManipulatedGeometry.buffer( -offset, quadSegments, capStyle, joinStyle, miterLimit );
583+
offsetGeom = mManipulatedGeometry.buffer( offset, quadSegments, capStyle, joinStyle, miterLimit );
577584
}
578585

579586
if ( !offsetGeom )

0 commit comments

Comments
 (0)