Skip to content
Permalink
Browse files

[symbology] Markerline does not crash on empty lines (Fix #8381)

  • Loading branch information
m-kuhn committed Jul 30, 2013
1 parent f350de6 commit b54b31e98b5a99bafd3d2b386e14e4ca94f2b42a
Showing with 39 additions and 36 deletions.
  1. +39 −36 src/core/symbology-ng/qgslinesymbollayerv2.cpp
@@ -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 );
}
}


0 comments on commit b54b31e

Please sign in to comment.
You can’t perform that action at this time.