diff --git a/python/core/qgsgeometrysimplifier.sip b/python/core/qgsgeometrysimplifier.sip index 97fabb6daad..f7c28655153 100644 --- a/python/core/qgsgeometrysimplifier.sip +++ b/python/core/qgsgeometrysimplifier.sip @@ -17,9 +17,9 @@ class QgsAbstractGeometrySimplifier // MapToPixel simplification helper methods public: //! Returns whether the device-envelope can be replaced by its BBOX when is applied the specified tolerance - static bool canbeGeneralizedByDeviceBoundingBox( const QgsRectangle& envelope, float mapToPixelTol = 1.0f ); + static bool isGeneralizableByDeviceBoundingBox( const QgsRectangle& envelope, float mapToPixelTol = 1.0f ); //! Returns whether the device-geometry can be replaced by its BBOX when is applied the specified tolerance - static bool canbeGeneralizedByDeviceBoundingBox( const QVector& points, float mapToPixelTol = 1.0f ); + static bool isGeneralizableByDeviceBoundingBox( const QVector& points, float mapToPixelTol = 1.0f ); }; /***************************************************************************/ diff --git a/src/core/qgsgeometrysimplifier.cpp b/src/core/qgsgeometrysimplifier.cpp index 5572addfbfa..b0d41cb8768 100644 --- a/src/core/qgsgeometrysimplifier.cpp +++ b/src/core/qgsgeometrysimplifier.cpp @@ -22,30 +22,22 @@ QgsAbstractGeometrySimplifier::~QgsAbstractGeometrySimplifier() } //! Returns whether the device-envelope can be replaced by its BBOX when is applied the specified tolerance -bool QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( const QgsRectangle& envelope, float mapToPixelTol ) +bool QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( const QgsRectangle& envelope, float mapToPixelTol ) { return ( envelope.xMaximum() - envelope.xMinimum() ) < mapToPixelTol && ( envelope.yMaximum() - envelope.yMinimum() ) < mapToPixelTol; } //! Returns whether the device-geometry can be replaced by its BBOX when is applied the specified tolerance -bool QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( const QVector& points, float mapToPixelTol ) +bool QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( const QVector& points, float mapToPixelTol ) { - double xmin = std::numeric_limits::max(), x, y; - double ymin = std::numeric_limits::max(); - double xmax = -std::numeric_limits::max(); - double ymax = -std::numeric_limits::max(); + QgsRectangle r; + r.setMinimal(); for ( int i = 0, numPoints = points.size(); i < numPoints; ++i ) { - x = points[i].x(); - y = points[i].y(); - - if ( xmin > x ) xmin = x; - if ( ymin > y ) ymin = y; - if ( xmax < x ) xmax = x; - if ( ymax < y ) ymax = y; + r.combineExtentWith( points[i].x(), points[i].y() ); } - return canbeGeneralizedByDeviceBoundingBox( QgsRectangle( xmin, ymin, xmax, ymax ), mapToPixelTol ); + return isGeneralizableByDeviceBoundingBox( r, mapToPixelTol ); } /***************************************************************************/ diff --git a/src/core/qgsgeometrysimplifier.h b/src/core/qgsgeometrysimplifier.h index 134ad36864f..687a922f441 100644 --- a/src/core/qgsgeometrysimplifier.h +++ b/src/core/qgsgeometrysimplifier.h @@ -35,9 +35,9 @@ class CORE_EXPORT QgsAbstractGeometrySimplifier // MapToPixel simplification helper methods public: //! Returns whether the device-envelope can be replaced by its BBOX when is applied the specified tolerance - static bool canbeGeneralizedByDeviceBoundingBox( const QgsRectangle& envelope, float mapToPixelTol = 1.0f ); + static bool isGeneralizableByDeviceBoundingBox( const QgsRectangle& envelope, float mapToPixelTol = 1.0f ); //! Returns whether the device-geometry can be replaced by its BBOX when is applied the specified tolerance - static bool canbeGeneralizedByDeviceBoundingBox( const QVector& points, float mapToPixelTol = 1.0f ); + static bool isGeneralizableByDeviceBoundingBox( const QVector& points, float mapToPixelTol = 1.0f ); }; /***************************************************************************/ diff --git a/src/core/symbology-ng/qgslinesymbollayerv2.cpp b/src/core/symbology-ng/qgslinesymbollayerv2.cpp index 44976a5fdc0..5a06f233226 100644 --- a/src/core/symbology-ng/qgslinesymbollayerv2.cpp +++ b/src/core/symbology-ng/qgslinesymbollayerv2.cpp @@ -258,7 +258,10 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym p->setPen( context.selected() ? mSelPen : mPen ); // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points). - if ( points.size() <= 2 && ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) ) + if ( points.size() <= 2 && + ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && + QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && + ( p->renderHints() & QPainter::Antialiasing ) ) { p->setRenderHint( QPainter::Antialiasing, false ); p->drawPolyline( points ); diff --git a/src/core/symbology-ng/qgssymbollayerv2.cpp b/src/core/symbology-ng/qgssymbollayerv2.cpp index 362b533473f..ef9a20955ec 100644 --- a/src/core/symbology-ng/qgssymbollayerv2.cpp +++ b/src/core/symbology-ng/qgssymbollayerv2.cpp @@ -427,7 +427,10 @@ void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points, } // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points). - if ( points.size() <= 5 && ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) ) + if ( points.size() <= 5 && + ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && + QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && + ( p->renderHints() & QPainter::Antialiasing ) ) { p->setRenderHint( QPainter::Antialiasing, false ); p->drawRect( points.boundingRect() ); diff --git a/src/providers/ogr/qgsogrgeometrysimplifier.cpp b/src/providers/ogr/qgsogrgeometrysimplifier.cpp index f9c1593994f..38c740d1e04 100644 --- a/src/providers/ogr/qgsogrgeometrysimplifier.cpp +++ b/src/providers/ogr/qgsogrgeometrysimplifier.cpp @@ -131,10 +131,12 @@ QgsPoint* QgsOgrMapToPixelSimplifier::getEnvelopePoints( const QgsRectangle& env //! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometryType, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount ) { - bool canbeGeneralizable = ( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry ); + bool isGeneralizable = ( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry ); pointSimplifiedCount = pointCount; - if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false; + if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) + return false; + pointSimplifiedCount = 0; double map2pixelTol = mTolerance * mTolerance; //-> Use mappixelTol for 'LengthSquare' calculations. @@ -150,7 +152,10 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometr memcpy( &x, xsourcePtr, sizeof( double ) ); xsourcePtr += xStride; memcpy( &y, ysourcePtr, sizeof( double ) ); ysourcePtr += yStride; - if ( i == 0 || !canbeGeneralizable || QgsMapToPixelSimplifier::calculateLengthSquared2D( x, y, lastX, lastY ) > map2pixelTol || ( geometryType == QGis::Line && ( i == 1 || i >= numPoints - 2 ) ) ) + if ( i == 0 || + !isGeneralizable || + calculateLengthSquared2D( x, y, lastX, lastY ) > map2pixelTol || + ( geometryType == QGis::Line && ( i == 1 || i >= numPoints - 2 ) ) ) { memcpy( xtargetPtr, &x, sizeof( double ) ); lastX = x; xtargetPtr += xStride; memcpy( ytargetPtr, &y, sizeof( double ) ); lastY = y; ytargetPtr += yStride; @@ -184,7 +189,7 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( OGRGeometryH geometry, boo QgsRectangle envelope( env.MinX, env.MinY, env.MaxX, env.MaxY ); // Can replace the geometry by its BBOX ? - if (( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope ) && canbeGeneralizedByMapBoundingBox( envelope ) ) + if (( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope ) && isGeneralizableByMapBoundingBox( envelope ) ) { QgsPoint* points = getEnvelopePoints( envelope, numPoints, isaLinearRing );