Skip to content

Commit

Permalink
Only calculate total length when we actually need it
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2021
1 parent 618d575 commit f00419c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/symbology/qgslinesymbollayer.cpp
Expand Up @@ -1685,7 +1685,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval( const QPolygonF &p

if ( !qgsDoubleNear( offsetAlongLine, 0 ) )
{
totalLength = QgsSymbolLayerUtils::polylineLength( points );
switch ( offsetAlongLineUnit() )
{
case QgsUnitTypes::RenderMillimeters:
Expand All @@ -1698,6 +1697,7 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval( const QPolygonF &p
painterUnitOffsetAlongLine = rc.convertToPainterUnits( offsetAlongLine, offsetAlongLineUnit(), offsetAlongLineMapUnitScale() );
break;
case QgsUnitTypes::RenderPercentage:
totalLength = QgsSymbolLayerUtils::polylineLength( points );
painterUnitOffsetAlongLine = offsetAlongLine / 100 * totalLength;
break;
}
Expand All @@ -1706,10 +1706,14 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval( const QPolygonF &p
{
if ( painterUnitOffsetAlongLine > 0 )
{
if ( totalLength < 0 )
totalLength = QgsSymbolLayerUtils::polylineLength( points );
painterUnitOffsetAlongLine = std::fmod( painterUnitOffsetAlongLine, totalLength );
}
else if ( painterUnitOffsetAlongLine < 0 )
{
if ( totalLength < 0 )
totalLength = QgsSymbolLayerUtils::polylineLength( points );
painterUnitOffsetAlongLine = totalLength - std::fmod( -painterUnitOffsetAlongLine, totalLength );
}
}
Expand Down Expand Up @@ -1866,8 +1870,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
double totalLength = -1;
if ( !qgsDoubleNear( offsetAlongLine, 0.0 ) )
{
totalLength = QgsSymbolLayerUtils::polylineLength( points );

//scale offset along line
switch ( offsetAlongLineUnit() )
{
Expand All @@ -1881,17 +1883,22 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
offsetAlongLine = rc.convertToPainterUnits( offsetAlongLine, offsetAlongLineUnit(), offsetAlongLineMapUnitScale() );
break;
case QgsUnitTypes::RenderPercentage:
totalLength = QgsSymbolLayerUtils::polylineLength( points );
offsetAlongLine = offsetAlongLine / 100 * totalLength;
break;
}
if ( points.isClosed() )
{
if ( offsetAlongLine > 0 )
{
if ( totalLength < 0 )
totalLength = QgsSymbolLayerUtils::polylineLength( points );
offsetAlongLine = std::fmod( offsetAlongLine, totalLength );
}
else if ( offsetAlongLine < 0 )
{
if ( totalLength < 0 )
totalLength = QgsSymbolLayerUtils::polylineLength( points );
offsetAlongLine = totalLength - std::fmod( -offsetAlongLine, totalLength );
}
}
Expand Down

0 comments on commit f00419c

Please sign in to comment.