Skip to content

Commit

Permalink
line fill angle and direction, fixes #9647
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Feb 26, 2014
1 parent 1d3ae87 commit 74ef8f3
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,11 +1643,19 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
}
else
{
height = qAbs( outputPixelDist / cos( lineAngle * M_PI / 180 ) ); //keep perpendicular distance between lines constant
width = qAbs( height / tan( lineAngle * M_PI / 180 ) );
height = outputPixelDist / cos( lineAngle * M_PI / 180 ); //keep perpendicular distance between lines constant
width = outputPixelDist / sin( lineAngle * M_PI / 180 );

// recalculate real angle and distance after rounding to pixels
lineAngle = 180 * qAbs( atan2(( double ) height, ( double ) width ) ) / M_PI;
lineAngle = 180 * atan2(( double ) height, ( double ) width ) / M_PI;
if ( lineAngle < 0 )
{
lineAngle += 360.;
}

height = qAbs( height );
width = qAbs( width );

outputPixelDist = height * cos( lineAngle * M_PI / 180 );

// Round offset to correspond to one pixel height, otherwise lines may
Expand Down Expand Up @@ -1698,27 +1706,49 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
p3 = QPointF( xBuffer + innerWidth, height );
p4 = QPointF( xBuffer + innerWidth, 0 );
}
else if (( lineAngle > 0 && lineAngle < 90 ) || ( lineAngle > 180 && lineAngle < 270 ) )
else if ( lineAngle > 0 && lineAngle < 90 )
{
dx = outputPixelDist * cos(( 90 - lineAngle ) * M_PI / 180.0 );
dy = outputPixelDist * sin(( 90 - lineAngle ) * M_PI / 180.0 );
p1 = QPointF( 0, height );
p2 = QPointF( width, 0 );
p3 = QPointF( -dx, height - dy );
p4 = QPointF( width - dx, -dy ); //p4 = QPoint( p3.x() + width, p3.y() - height );
p4 = QPointF( width - dx, -dy );
p5 = QPointF( dx, height + dy );
p6 = QPointF( width + dx, dy ); //p6 = QPoint( p5.x() + width, p5.y() - height );
p6 = QPointF( width + dx, dy );
}
else if ( lineAngle > 180 && lineAngle < 270 )
{
dx = outputPixelDist * cos(( 90 - lineAngle ) * M_PI / 180.0 );
dy = outputPixelDist * sin(( 90 - lineAngle ) * M_PI / 180.0 );
p1 = QPointF( width, 0 );
p2 = QPointF( 0, height );
p3 = QPointF( width - dx, -dy );
p4 = QPointF( -dx, height - dy );
p5 = QPointF( width + dx, dy );
p6 = QPointF( dx, height + dy );
}
else if ( lineAngle > 90 && lineAngle < 180 )
{
dy = outputPixelDist * cos(( 180 - lineAngle ) * M_PI / 180 );
dx = outputPixelDist * sin(( 180 - lineAngle ) * M_PI / 180 );
p1 = QPointF( 0, 0 );
p2 = QPointF( width, height );
p5 = QPointF( dx, -dy );
p6 = QPointF( width + dx, height - dy );
p3 = QPointF( -dx, dy );
p4 = QPointF( width - dx, height + dy );
}
else if (( lineAngle < 180 ) || ( lineAngle > 270 && lineAngle < 360 ) )
else if ( lineAngle > 270 && lineAngle < 360 )
{
dy = outputPixelDist * cos(( 180 - lineAngle ) * M_PI / 180 );
dx = outputPixelDist * sin(( 180 - lineAngle ) * M_PI / 180 );
p1 = QPointF( width, height );
p2 = QPointF( 0, 0 );
p5 = QPointF( width + dx, height - dy );
p6 = QPointF( p5.x() - width, p5.y() - height ); //p6 = QPoint( dx, -dy );
p6 = QPointF( dx, -dy );
p3 = QPointF( width - dx, height + dy );
p4 = QPointF( p3.x() - width, p3.y() - height ); //p4 = QPoint( -dx, dy );
p4 = QPointF( -dx, dy );
}

if ( !qgsDoubleNear( mOffset, 0.0 ) ) //shift everything
Expand Down

2 comments on commit 74ef8f3

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this commit be pushed to the release-2_2 branch also?

@blazek
Copy link
Member Author

@blazek blazek commented on 74ef8f3 Mar 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Once, after the 2.0, I asked if the branch 2.0 is open for bugfix backports but never got any reply...

Please sign in to comment.