Skip to content

Commit 5b4ed16

Browse files
committed
Fix line pattern fill offsets are always treated as positive,
even when offset is negative
1 parent d6a863b commit 5b4ed16

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/core/symbology/qgsfillsymbollayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &
25802580

25812581
// Round offset to correspond to one pixel height, otherwise lines may
25822582
// be shifted on tile border if offset falls close to pixel center
2583-
int offsetHeight = std::round( std::fabs( outputPixelOffset / std::cos( lineAngle * M_PI / 180 ) ) );
2583+
int offsetHeight = static_cast< int >( std::round( outputPixelOffset / std::cos( lineAngle * M_PI / 180 ) ) );
25842584
outputPixelOffset = offsetHeight * std::cos( lineAngle * M_PI / 180 );
25852585
}
25862586

tests/src/core/testqgslinefillsymbol.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class TestQgsLineFillSymbol : public QObject
5454
void cleanup() {} // will be called after every testfunction.
5555

5656
void lineFillSymbol();
57+
void lineFillSymbolOffset();
58+
5759
void dataDefinedSubSymbol();
5860

5961
private:
@@ -79,7 +81,7 @@ void TestQgsLineFillSymbol::initTestCase()
7981
QgsApplication::showSettings();
8082

8183
//create some objects that will be used in all tests...
82-
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
84+
QString myDataDir( QStringLiteral( TEST_DATA_DIR ) ); //defined in CmakeLists.txt
8385
mTestDataDir = myDataDir + '/';
8486

8587
//
@@ -136,7 +138,19 @@ void TestQgsLineFillSymbol::lineFillSymbol()
136138
QgsLineSymbol *lineSymbol = QgsLineSymbol::createSimple( properties );
137139

138140
mLineFill->setSubSymbol( lineSymbol );
139-
QVERIFY( imageCheck( "symbol_linefill" ) );
141+
QVERIFY( imageCheck( QStringLiteral( "symbol_linefill" ) ) );
142+
}
143+
144+
void TestQgsLineFillSymbol::lineFillSymbolOffset()
145+
{
146+
mReport += QLatin1String( "<h2>Line fill symbol renderer test</h2>\n" );
147+
148+
mLineFill->setOffset( 0.5 );
149+
QVERIFY( imageCheck( QStringLiteral( "symbol_linefill_posoffset" ) ) );
150+
151+
mLineFill->setOffset( -0.5 );
152+
QVERIFY( imageCheck( QStringLiteral( "symbol_linefill_negoffset" ) ) );
153+
mLineFill->setOffset( 0 );
140154
}
141155

142156
void TestQgsLineFillSymbol::dataDefinedSubSymbol()
@@ -150,7 +164,7 @@ void TestQgsLineFillSymbol::dataDefinedSubSymbol()
150164
QgsLineSymbol *lineSymbol = QgsLineSymbol::createSimple( properties );
151165
lineSymbol->symbolLayer( 0 )->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromExpression( QStringLiteral( "if(\"Name\" ='Lake','#ff0000','#ff00ff')" ) ) );
152166
mLineFill->setSubSymbol( lineSymbol );
153-
QVERIFY( imageCheck( "datadefined_subsymbol" ) );
167+
QVERIFY( imageCheck( QStringLiteral( "datadefined_subsymbol" ) ) );
154168
}
155169

156170
//

0 commit comments

Comments
 (0)