Skip to content

Commit b54b31e

Browse files
committedJul 30, 2013
[symbology] Markerline does not crash on empty lines (Fix #8381)
1 parent f350de6 commit b54b31e

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed
 

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -812,47 +812,50 @@ double QgsMarkerLineSymbolLayerV2::markerAngle( const QPolygonF& points, bool is
812812

813813
void QgsMarkerLineSymbolLayerV2::renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context )
814814
{
815-
// calc length
816-
qreal length = 0;
817-
QPolygonF::const_iterator it = points.constBegin();
818-
QPointF last = *it;
819-
for ( ++it; it != points.constEnd(); ++it )
815+
if ( points.size() > 0 )
820816
{
821-
length += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
822-
( last.y() - it->y() ) * ( last.y() - it->y() ) );
823-
last = *it;
824-
}
817+
// calc length
818+
qreal length = 0;
819+
QPolygonF::const_iterator it = points.constBegin();
820+
QPointF last = *it;
821+
for ( ++it; it != points.constEnd(); ++it )
822+
{
823+
length += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
824+
( last.y() - it->y() ) * ( last.y() - it->y() ) );
825+
last = *it;
826+
}
825827

826-
// find the segment where the central point lies
827-
it = points.constBegin();
828-
last = *it;
829-
qreal last_at = 0, next_at = 0;
830-
QPointF next;
831-
int segment = 0;
832-
for ( ++it; it != points.constEnd(); ++it )
833-
{
834-
next = *it;
835-
next_at += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
836-
( last.y() - it->y() ) * ( last.y() - it->y() ) );
837-
if ( next_at >= length / 2 )
838-
break; // we have reached the center
828+
// find the segment where the central point lies
829+
it = points.constBegin();
839830
last = *it;
840-
last_at = next_at;
841-
segment++;
842-
}
831+
qreal last_at = 0, next_at = 0;
832+
QPointF next;
833+
int segment = 0;
834+
for ( ++it; it != points.constEnd(); ++it )
835+
{
836+
next = *it;
837+
next_at += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
838+
( last.y() - it->y() ) * ( last.y() - it->y() ) );
839+
if ( next_at >= length / 2 )
840+
break; // we have reached the center
841+
last = *it;
842+
last_at = next_at;
843+
segment++;
844+
}
843845

844-
// find out the central point on segment
845-
MyLine l( last, next ); // for line angle
846-
qreal k = ( length * 0.5 - last_at ) / ( next_at - last_at );
847-
QPointF pt = last + ( next - last ) * k;
846+
// find out the central point on segment
847+
MyLine l( last, next ); // for line angle
848+
qreal k = ( length * 0.5 - last_at ) / ( next_at - last_at );
849+
QPointF pt = last + ( next - last ) * k;
848850

849-
// draw the marker
850-
double origAngle = mMarker->angle();
851-
if ( mRotateMarker )
852-
mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
853-
mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
854-
if ( mRotateMarker )
855-
mMarker->setAngle( origAngle );
851+
// draw the marker
852+
double origAngle = mMarker->angle();
853+
if ( mRotateMarker )
854+
mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
855+
mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
856+
if ( mRotateMarker )
857+
mMarker->setAngle( origAngle );
858+
}
856859
}
857860

858861

0 commit comments

Comments
 (0)
Please sign in to comment.