Skip to content

Commit

Permalink
#10195: avoid calculate the GeometryType in offsetline
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Jun 11, 2014
1 parent 3ca5706 commit 17a8e38
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -273,7 +273,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
else
{
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale );
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset, context.feature() ? context.feature()->geometry()->type() : QGis::Line );
for ( int part = 0; part < mline.count(); ++part )
p->drawPolyline( mline[ part ] );
}
Expand Down Expand Up @@ -765,7 +765,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
}
else
{
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ), context.feature() ? context.feature()->geometry()->type() : QGis::Line );

for ( int part = 0; part < mline.count(); ++part )
{
Expand Down
25 changes: 18 additions & 7 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -682,8 +682,7 @@ static QList<QPolygonF> makeOffsetGeometry( const QgsPolygon& polygon )
}
#endif


QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType )
{
QList<QPolygonF> resultLine;

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

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

bool isaLinearRing = false;
if ( polyline[0].x() == polyline[ pointCount - 1 ].x() && polyline[0].y() == polyline[ pointCount - 1 ].y() ) isaLinearRing = true;

QgsPolyline tempPolyline( pointCount );
QPointF* tempPtr = polyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr++ )
tempPolyline[i] = QgsPoint( tempPtr->rx(), tempPtr->ry() );

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

if ( offsetGeom )
{
Expand Down Expand Up @@ -803,6 +799,21 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )

#endif
}
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
{
QGis::GeometryType geometryType = QGis::Point;
int pointCount = polyline.count();

if ( pointCount > 3 && polyline[ 0 ].x() == polyline[ pointCount - 1 ].x() && polyline[ 0 ].y() == polyline[ pointCount - 1 ].y() )
{
geometryType = QGis::Polygon;
}
else if ( pointCount > 1 )
{
geometryType = QGis::Line;
}
return offsetLine( polyline, dist, geometryType );
}

/////

Expand Down
5 changes: 3 additions & 2 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -312,9 +312,10 @@ class CORE_EXPORT QgsSymbolLayerV2Utils

class QPolygonF;

//! calculate line shifted by a specified distance
//! @deprecated since 2.4 - calculate line shifted by a specified distance
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist );

//! calculate geometry shifted by a specified distance
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType );

#endif

Expand Down

0 comments on commit 17a8e38

Please sign in to comment.