Skip to content

Commit

Permalink
Fix line pattern fill offsets are always treated as positive,
Browse files Browse the repository at this point in the history
even when offset is negative
  • Loading branch information
nyalldawson committed Oct 12, 2018
1 parent d6a863b commit 5b4ed16
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/symbology/qgsfillsymbollayer.cpp
Expand Up @@ -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 );
}

Expand Down
20 changes: 17 additions & 3 deletions tests/src/core/testqgslinefillsymbol.cpp
Expand Up @@ -54,6 +54,8 @@ class TestQgsLineFillSymbol : public QObject
void cleanup() {} // will be called after every testfunction.

void lineFillSymbol();
void lineFillSymbolOffset();

void dataDefinedSubSymbol();

private:
Expand All @@ -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 + '/';

//
Expand Down Expand Up @@ -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()
Expand All @@ -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" ) ) );
}

//
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5b4ed16

Please sign in to comment.