Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[symbology] Markerline does not crash on empty lines (Fix #8381)
  • Loading branch information
m-kuhn committed Jul 30, 2013
1 parent f350de6 commit b54b31e
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -812,47 +812,50 @@ double QgsMarkerLineSymbolLayerV2::markerAngle( const QPolygonF& points, bool is

void QgsMarkerLineSymbolLayerV2::renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
// calc length
qreal length = 0;
QPolygonF::const_iterator it = points.constBegin();
QPointF last = *it;
for ( ++it; it != points.constEnd(); ++it )
if ( points.size() > 0 )
{
length += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
( last.y() - it->y() ) * ( last.y() - it->y() ) );
last = *it;
}
// calc length
qreal length = 0;
QPolygonF::const_iterator it = points.constBegin();
QPointF last = *it;
for ( ++it; it != points.constEnd(); ++it )
{
length += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
( last.y() - it->y() ) * ( last.y() - it->y() ) );
last = *it;
}

// find the segment where the central point lies
it = points.constBegin();
last = *it;
qreal last_at = 0, next_at = 0;
QPointF next;
int segment = 0;
for ( ++it; it != points.constEnd(); ++it )
{
next = *it;
next_at += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
( last.y() - it->y() ) * ( last.y() - it->y() ) );
if ( next_at >= length / 2 )
break; // we have reached the center
// find the segment where the central point lies
it = points.constBegin();
last = *it;
last_at = next_at;
segment++;
}
qreal last_at = 0, next_at = 0;
QPointF next;
int segment = 0;
for ( ++it; it != points.constEnd(); ++it )
{
next = *it;
next_at += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
( last.y() - it->y() ) * ( last.y() - it->y() ) );
if ( next_at >= length / 2 )
break; // we have reached the center
last = *it;
last_at = next_at;
segment++;
}

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

// draw the marker
double origAngle = mMarker->angle();
if ( mRotateMarker )
mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
if ( mRotateMarker )
mMarker->setAngle( origAngle );
// draw the marker
double origAngle = mMarker->angle();
if ( mRotateMarker )
mMarker->setAngle( origAngle + l.angle() * 180 / M_PI );
mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() );
if ( mRotateMarker )
mMarker->setAngle( origAngle );
}
}


Expand Down

0 comments on commit b54b31e

Please sign in to comment.