@@ -812,47 +812,50 @@ double QgsMarkerLineSymbolLayerV2::markerAngle( const QPolygonF& points, bool is
812
812
813
813
void QgsMarkerLineSymbolLayerV2::renderPolylineCentral ( const QPolygonF& points, QgsSymbolV2RenderContext& context )
814
814
{
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 )
820
816
{
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
+ }
825
827
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 ();
839
830
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
+ }
843
845
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;
848
850
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
+ }
856
859
}
857
860
858
861
0 commit comments