Skip to content

Commit 74ef8f3

Browse files
committedFeb 26, 2014
line fill angle and direction, fixes #9647
1 parent 1d3ae87 commit 74ef8f3

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed
 

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,11 +1643,19 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
16431643
}
16441644
else
16451645
{
1646-
height = qAbs( outputPixelDist / cos( lineAngle * M_PI / 180 ) ); //keep perpendicular distance between lines constant
1647-
width = qAbs( height / tan( lineAngle * M_PI / 180 ) );
1646+
height = outputPixelDist / cos( lineAngle * M_PI / 180 ); //keep perpendicular distance between lines constant
1647+
width = outputPixelDist / sin( lineAngle * M_PI / 180 );
16481648

16491649
// recalculate real angle and distance after rounding to pixels
1650-
lineAngle = 180 * qAbs( atan2(( double ) height, ( double ) width ) ) / M_PI;
1650+
lineAngle = 180 * atan2(( double ) height, ( double ) width ) / M_PI;
1651+
if ( lineAngle < 0 )
1652+
{
1653+
lineAngle += 360.;
1654+
}
1655+
1656+
height = qAbs( height );
1657+
width = qAbs( width );
1658+
16511659
outputPixelDist = height * cos( lineAngle * M_PI / 180 );
16521660

16531661
// Round offset to correspond to one pixel height, otherwise lines may
@@ -1698,27 +1706,49 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
16981706
p3 = QPointF( xBuffer + innerWidth, height );
16991707
p4 = QPointF( xBuffer + innerWidth, 0 );
17001708
}
1701-
else if (( lineAngle > 0 && lineAngle < 90 ) || ( lineAngle > 180 && lineAngle < 270 ) )
1709+
else if ( lineAngle > 0 && lineAngle < 90 )
17021710
{
17031711
dx = outputPixelDist * cos(( 90 - lineAngle ) * M_PI / 180.0 );
17041712
dy = outputPixelDist * sin(( 90 - lineAngle ) * M_PI / 180.0 );
17051713
p1 = QPointF( 0, height );
17061714
p2 = QPointF( width, 0 );
17071715
p3 = QPointF( -dx, height - dy );
1708-
p4 = QPointF( width - dx, -dy ); //p4 = QPoint( p3.x() + width, p3.y() - height );
1716+
p4 = QPointF( width - dx, -dy );
17091717
p5 = QPointF( dx, height + dy );
1710-
p6 = QPointF( width + dx, dy ); //p6 = QPoint( p5.x() + width, p5.y() - height );
1718+
p6 = QPointF( width + dx, dy );
1719+
}
1720+
else if ( lineAngle > 180 && lineAngle < 270 )
1721+
{
1722+
dx = outputPixelDist * cos(( 90 - lineAngle ) * M_PI / 180.0 );
1723+
dy = outputPixelDist * sin(( 90 - lineAngle ) * M_PI / 180.0 );
1724+
p1 = QPointF( width, 0 );
1725+
p2 = QPointF( 0, height );
1726+
p3 = QPointF( width - dx, -dy );
1727+
p4 = QPointF( -dx, height - dy );
1728+
p5 = QPointF( width + dx, dy );
1729+
p6 = QPointF( dx, height + dy );
1730+
}
1731+
else if ( lineAngle > 90 && lineAngle < 180 )
1732+
{
1733+
dy = outputPixelDist * cos(( 180 - lineAngle ) * M_PI / 180 );
1734+
dx = outputPixelDist * sin(( 180 - lineAngle ) * M_PI / 180 );
1735+
p1 = QPointF( 0, 0 );
1736+
p2 = QPointF( width, height );
1737+
p5 = QPointF( dx, -dy );
1738+
p6 = QPointF( width + dx, height - dy );
1739+
p3 = QPointF( -dx, dy );
1740+
p4 = QPointF( width - dx, height + dy );
17111741
}
1712-
else if (( lineAngle < 180 ) || ( lineAngle > 270 && lineAngle < 360 ) )
1742+
else if ( lineAngle > 270 && lineAngle < 360 )
17131743
{
17141744
dy = outputPixelDist * cos(( 180 - lineAngle ) * M_PI / 180 );
17151745
dx = outputPixelDist * sin(( 180 - lineAngle ) * M_PI / 180 );
17161746
p1 = QPointF( width, height );
17171747
p2 = QPointF( 0, 0 );
17181748
p5 = QPointF( width + dx, height - dy );
1719-
p6 = QPointF( p5.x() - width, p5.y() - height ); //p6 = QPoint( dx, -dy );
1749+
p6 = QPointF( dx, -dy );
17201750
p3 = QPointF( width - dx, height + dy );
1721-
p4 = QPointF( p3.x() - width, p3.y() - height ); //p4 = QPoint( -dx, dy );
1751+
p4 = QPointF( -dx, dy );
17221752
}
17231753

17241754
if ( !qgsDoubleNear( mOffset, 0.0 ) ) //shift everything

2 commit comments

Comments
 (2)

nyalldawson commented on Mar 1, 2014

@nyalldawson
Collaborator

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

blazek commented on Mar 3, 2014

@blazek
MemberAuthor

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.