Skip to content

Commit

Permalink
fix #19939: render mesh arrows also on the edge of the canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Oct 25, 2018
1 parent a1d6f29 commit b0bd629
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/core/mesh/qgsmeshvectorrenderer.cpp
Expand Up @@ -64,11 +64,21 @@ QgsMeshVectorRenderer::QgsMeshVectorRenderer( const QgsTriangularMesh &m,
, mCfg( settings )
, mDataOnVertices( dataIsOnVertices )
, mOutputSize( size )
, mBufferedExtent( context.extent() )
{
// should be checked in caller
Q_ASSERT( !mDatasetValuesMag.empty() );
Q_ASSERT( !std::isnan( mMinMag ) );
Q_ASSERT( !std::isnan( mMaxMag ) );

// we need to expand out the extent so that it includes
// arrows which start or end up outside of the
// actual visible extent
double extension = context.convertToMapUnits( mMaxMag, QgsUnitTypes::RenderPixels );
mBufferedExtent.setXMinimum( mBufferedExtent.xMinimum() - extension );
mBufferedExtent.setXMaximum( mBufferedExtent.xMaximum() + extension );
mBufferedExtent.setYMinimum( mBufferedExtent.yMinimum() - extension );
mBufferedExtent.setYMaximum( mBufferedExtent.yMaximum() + extension );
}

QgsMeshVectorRenderer::~QgsMeshVectorRenderer() = default;
Expand All @@ -91,7 +101,7 @@ void QgsMeshVectorRenderer::draw()
pen.setColor( mCfg.color() );
painter->setPen( pen );

const QList<int> trianglesInExtent = mTriangularMesh.faceIndexesForRectangle( mContext.extent() );
const QList<int> trianglesInExtent = mTriangularMesh.faceIndexesForRectangle( mBufferedExtent );

if ( mCfg.isOnUserDefinedGrid() )
drawVectorDataOnGrid( trianglesInExtent );
Expand Down Expand Up @@ -180,11 +190,11 @@ bool QgsMeshVectorRenderer::calcVectorLineEnd(

vectorLength = sqrt( xDist * xDist + yDist * yDist );

// Check to see if any of the coords are outside the QImage area, if so, skip the whole vector
if ( lineStart.x() < 0 || lineStart.x() > mOutputSize.width() ||
lineStart.y() < 0 || lineStart.y() > mOutputSize.height() ||
lineEnd.x() < 0 || lineEnd.x() > mOutputSize.width() ||
lineEnd.y() < 0 || lineEnd.y() > mOutputSize.height() )
// Check to see if both of the coords are outside the QImage area, if so, skip the whole vector
if ( ( lineStart.x() < 0 || lineStart.x() > mOutputSize.width() ||
lineStart.y() < 0 || lineStart.y() > mOutputSize.height() ) &&
( lineEnd.x() < 0 || lineEnd.x() > mOutputSize.width() ||
lineEnd.y() < 0 || lineEnd.y() > mOutputSize.height() ) )
return true;

return false; //success
Expand Down Expand Up @@ -213,7 +223,7 @@ void QgsMeshVectorRenderer::drawVectorDataOnVertices( const QList<int> &triangle
drawnVertices.insert( i );

const QgsMeshVertex &vertex = vertices.at( i );
if ( !mContext.extent().contains( vertex ) )
if ( !mBufferedExtent.contains( vertex ) )
continue;

double xVal = mDatasetValuesX[i];
Expand All @@ -240,7 +250,7 @@ void QgsMeshVectorRenderer::drawVectorDataOnFaces( const QList<int> &trianglesIn
break;

QgsPointXY center = centroids.at( i );
if ( !mContext.extent().contains( center ) )
if ( !mBufferedExtent.contains( center ) )
continue;

double xVal = mDatasetValuesX[i];
Expand Down
8 changes: 8 additions & 0 deletions src/core/mesh/qgsmeshvectorrenderer.h
Expand Up @@ -94,6 +94,14 @@ class QgsMeshVectorRenderer
const QgsMeshRendererVectorSettings &mCfg;
bool mDataOnVertices = true;
QSize mOutputSize;

/**
* Canvas extent buffered by vector maximum magnitude
* Needed to draw arrows which have
* start or end point outside the
* visible canvas extent
*/
QgsRectangle mBufferedExtent;
};

///@endcond
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 b0bd629

Please sign in to comment.