Skip to content

Commit 17a8e38

Browse files
committed
#10195: avoid calculate the GeometryType in offsetline
1 parent 3ca5706 commit 17a8e38

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/core/symbology-ng/qgslinesymbollayerv2.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
273273
else
274274
{
275275
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale );
276-
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
276+
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset, context.feature() ? context.feature()->geometry()->type() : QGis::Line );
277277
for ( int part = 0; part < mline.count(); ++part )
278278
p->drawPolyline( mline[ part ] );
279279
}
@@ -765,7 +765,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
765765
}
766766
else
767767
{
768-
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );
768+
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ), context.feature() ? context.feature()->geometry()->type() : QGis::Line );
769769

770770
for ( int part = 0; part < mline.count(); ++part )
771771
{

src/core/symbology-ng/qgssymbollayerv2utils.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,7 @@ static QList<QPolygonF> makeOffsetGeometry( const QgsPolygon& polygon )
682682
}
683683
#endif
684684

685-
686-
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
685+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType )
687686
{
688687
QList<QPolygonF> resultLine;
689688

@@ -701,19 +700,16 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
701700

702701
unsigned int i, pointCount = polyline.count();
703702

704-
bool isaLinearRing = false;
705-
if ( polyline[0].x() == polyline[ pointCount - 1 ].x() && polyline[0].y() == polyline[ pointCount - 1 ].y() ) isaLinearRing = true;
706-
707703
QgsPolyline tempPolyline( pointCount );
708704
QPointF* tempPtr = polyline.data();
709705
for ( i = 0; i < pointCount; ++i, tempPtr++ )
710706
tempPolyline[i] = QgsPoint( tempPtr->rx(), tempPtr->ry() );
711707

712-
QgsGeometry* tempGeometry = isaLinearRing ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
708+
QgsGeometry * tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
713709
if ( tempGeometry )
714710
{
715711
const GEOSGeometry* geosGeom = tempGeometry->asGeos();
716-
GEOSGeometry* offsetGeom = isaLinearRing ? GEOSBuffer( geosGeom, -dist, 8 /*quadSegments*/ ) : GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
712+
GEOSGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? GEOSBuffer( geosGeom, -dist, 8 /*quadSegments*/ ) : GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
717713

718714
if ( offsetGeom )
719715
{
@@ -803,6 +799,21 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
803799

804800
#endif
805801
}
802+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
803+
{
804+
QGis::GeometryType geometryType = QGis::Point;
805+
int pointCount = polyline.count();
806+
807+
if ( pointCount > 3 && polyline[ 0 ].x() == polyline[ pointCount - 1 ].x() && polyline[ 0 ].y() == polyline[ pointCount - 1 ].y() )
808+
{
809+
geometryType = QGis::Polygon;
810+
}
811+
else if ( pointCount > 1 )
812+
{
813+
geometryType = QGis::Line;
814+
}
815+
return offsetLine( polyline, dist, geometryType );
816+
}
806817

807818
/////
808819

src/core/symbology-ng/qgssymbollayerv2utils.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
312312

313313
class QPolygonF;
314314

315-
//! calculate line shifted by a specified distance
315+
//! @deprecated since 2.4 - calculate line shifted by a specified distance
316316
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist );
317-
317+
//! calculate geometry shifted by a specified distance
318+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType );
318319

319320
#endif
320321

0 commit comments

Comments
 (0)