3434.diff

The attached patch is shorter, but I didn't test it - strk could you try it with your testcase, please? - Jürgen Fischer, 2011-01-24 04:52 PM

Download (1.23 KB)

View differences:

src/core/symbology-ng/qgslinesymbollayerv2.cpp (working copy)
622 622
{
623 623
}
624 624

  
625
static double _calculateAngle( double x1, double y1, double x2, double y2 )
626
{
627
  // return angle (in radians) between two points
628
  if ( x1 == x2 )
629
    return  M_PI *( y2 >= y1 ? 1 / 2 : 3 / 2 );  // angle is 90 or 270
630

  
631
  double t = ( y2 - y1 ) / ( x2 - x1 );
632
  if ( t >= 0 )
633
    return atan( t ) + ( y2 >= y1 ? 0 : M_PI );
634
  else // t < 0
635
    return atan( t ) + ( y2 >= y1 ? M_PI : 0 ); // atan is positive / negative
636
}
637

  
638 625
void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
639 626
{
640 627
  // draw arrow at the end of line
......
648 635
  int cnt = points.count();
649 636
  QPointF p1 = points.at( cnt - 2 );
650 637
  QPointF p2 = points.at( cnt - 1 );
651
  double angle = _calculateAngle( p1.x(), p1.y(), p2.x(), p2.y() );
652 638

  
639
  double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() );
653 640
  double size = context.outputLineWidth( mWidth * 8 );
654 641
  double angle1 = angle + M_PI / 6;
655 642
  double angle2 = angle - M_PI / 6;