Skip to content
Permalink
Browse files

Fix line pattern fill offsets are always treated as positive,

even when offset is negative
  • Loading branch information
nyalldawson committed Oct 12, 2018
1 parent d6a863b commit 5b4ed16cf90a28e73d8c09bec5a36ae0fa9f2056
@@ -2580,7 +2580,7 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &

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

@@ -54,6 +54,8 @@ class TestQgsLineFillSymbol : public QObject
void cleanup() {} // will be called after every testfunction.

void lineFillSymbol();
void lineFillSymbolOffset();

void dataDefinedSubSymbol();

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

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

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

mLineFill->setSubSymbol( lineSymbol );
QVERIFY( imageCheck( "symbol_linefill" ) );
QVERIFY( imageCheck( QStringLiteral( "symbol_linefill" ) ) );
}

void TestQgsLineFillSymbol::lineFillSymbolOffset()
{
mReport += QLatin1String( "<h2>Line fill symbol renderer test</h2>\n" );

mLineFill->setOffset( 0.5 );
QVERIFY( imageCheck( QStringLiteral( "symbol_linefill_posoffset" ) ) );

mLineFill->setOffset( -0.5 );
QVERIFY( imageCheck( QStringLiteral( "symbol_linefill_negoffset" ) ) );
mLineFill->setOffset( 0 );
}

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

//
Binary file not shown.
Binary file not shown.

0 comments on commit 5b4ed16

Please sign in to comment.
You can’t perform that action at this time.