diff --git a/src/lib/marble/ClipPainter.cpp b/src/lib/marble/ClipPainter.cpp --- a/src/lib/marble/ClipPainter.cpp +++ b/src/lib/marble/ClipPainter.cpp @@ -16,13 +16,14 @@ #include "MarbleDebug.h" +#include namespace Marble { class ClipPainterPrivate { - public: +public: explicit ClipPainterPrivate( ClipPainter * parent ); ClipPainter * q; @@ -43,9 +44,13 @@ // int m_debugNodeCount; QPointF m_currentPoint; - QPointF m_previousPoint; + QPointF m_previousPoint; + inline int sector( const QPointF & point ) const; + inline int borderSector( const QPointF & point ) const; + inline bool isClockwise(const QPointF& pointA, const QPointF& pointB) const; + inline qreal calculateAngle(const QPointF& point) const ; inline QPointF clipTop( qreal m, const QPointF & point ) const; inline QPointF clipLeft( qreal m, const QPointF & point ) const; @@ -54,7 +59,7 @@ inline void initClipRect(); - inline void clipPolyObject ( const QPolygonF & sourcePolygon, + inline void clipPolyObject ( const QPolygonF & sourcePolygon, QVector & clippedPolyObjects, bool isClosed ); @@ -62,8 +67,8 @@ QVector & clippedPolyObjects, bool isClosed ); inline void clipOnce( QPolygonF & clippedPolyObject, - QVector & clippedPolyObjects, - bool isClosed ); + QVector & clippedPolyObjects, + bool isClosed ); inline void clipOnceCorner( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, const QPointF& corner, @@ -74,12 +79,15 @@ const QPointF& point, bool isClosed ) const; + inline void clipPolygon( QPolygonF & clippedPolyObject, + QVector & clippedPolyObjects, + bool isClosed ); - void labelPosition( const QPolygonF & polygon, QVector& labelNodes, - LabelPositionFlags labelPositionFlags); + void labelPosition( const QPolygonF & polygon, QVector& labelNodes, + LabelPositionFlags labelPositionFlags); bool pointAllowsLabel( const QPointF& point ); - QPointF interpolateLabelPoint( const QPointF& previousPoint, + QPointF interpolateLabelPoint( const QPointF& previousPoint, const QPointF& currentPoint, LabelPositionFlags labelPositionFlags ); @@ -92,6 +100,82 @@ int m_debugPolygonsLevel; }; +class Point { +public: + Point(const QPointF& point) : m_point(point), + m_isEntering(false), m_isLeaving(false), + m_nextBasePolygonPoint(nullptr), m_nextClipPolygonPoint(nullptr), + m_processed(false) + {} + + Point(const QPointF& point, bool isEntering, bool isLeaving) : m_point(point), + m_isEntering(isEntering), m_isLeaving(isLeaving), + m_nextBasePolygonPoint(nullptr), m_nextClipPolygonPoint(nullptr), + m_processed(false) + {} + + bool isIntersection() const + { + return m_isEntering || m_isLeaving; + } + + bool isEntering() const + { + return m_isEntering; + } + + bool isLeaving() const + { + return m_isLeaving; + } + + bool isProcessed() const + { + return m_processed; + } + + const QPointF& point() const + { + return m_point; + } + + const QSharedPointer& nextClipPolygonPoint() const + { + return m_nextClipPolygonPoint; + } + + const QSharedPointer& nextBasePolygonPoint() const + { + return m_nextBasePolygonPoint; + } + + void setNextClipPolygonPoint(QSharedPointer& nextPoint) + { + this->m_nextClipPolygonPoint = nextPoint; + } + + void setNextBasePolygonPoint(QSharedPointer& nextPoint) + { + this->m_nextBasePolygonPoint = nextPoint; + } + + void setProcessed(bool processed) + { + this->m_processed = processed; + } + +private: + + QPointF m_point; + bool m_isEntering; + bool m_isLeaving; + + QSharedPointer m_nextBasePolygonPoint; + QSharedPointer m_nextClipPolygonPoint; + + bool m_processed; +}; + } using namespace Marble; @@ -135,13 +219,13 @@ void ClipPainter::drawPolygon ( const QPolygonF & polygon, Qt::FillRule fillRule ) { - if ( d->m_doClip ) { + if ( d->m_doClip ) { d->initClipRect(); QVector clippedPolyObjects; d->clipPolyObject( polygon, clippedPolyObjects, true ); - foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { + foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { if ( clippedPolyObject.size() > 2 ) { // mDebug() << "Size: " << clippedPolyObject.size(); if (d->m_debugPolygonsLevel) { @@ -193,7 +277,7 @@ d->clipPolyObject( polygon, clippedPolyObjects, false ); - foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { + foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { if ( clippedPolyObject.size() > 1 ) { if (d->m_debugPolygonsLevel) { QPen pen = QPainter::pen(); @@ -245,7 +329,7 @@ d->clipPolyObject( polygon, clippedPolyObjects, false ); - foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { + foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { if (d->m_debugPolygonsLevel) { QPen pen = QPainter::pen(); QPen originalPen = pen; @@ -316,7 +400,7 @@ if ( currentAllowsLabel ) { // As polygon.size() > 0 it's ensured that it-1 exists. QPointF node = interpolateLabelPoint( polygon.at( it -1 ), polygon.at( it ), - labelPositionFlags ); + labelPositionFlags ); if ( node != QPointF( -1.0, -1.0 ) ) { labelNodes << node; } @@ -336,7 +420,7 @@ if ( currentAllowsLabel ) { QPointF node = interpolateLabelPoint( polygon.at( it + 1 ), polygon.at( it ), - labelPositionFlags ); + labelPositionFlags ); if ( node != QPointF( -1.0, -1.0 ) ) { labelNodes << node; } @@ -349,7 +433,7 @@ bool ClipPainterPrivate::pointAllowsLabel( const QPointF& point ) { - if ( point.x() > m_labelAreaMargin && point.x() < q->viewport().width() - m_labelAreaMargin + if ( point.x() > m_labelAreaMargin && point.x() < q->viewport().width() - m_labelAreaMargin && point.y() > m_labelAreaMargin && point.y() < q->viewport().height() - m_labelAreaMargin ) { return true; } @@ -365,7 +449,7 @@ if ( labelPositionFlags.testFlag( IgnoreXMargin ) ) { return QPointF( -1.0, -1.0 ); } - return QPointF( m_labelAreaMargin, + return QPointF( m_labelAreaMargin, previousPoint.y() + ( m_labelAreaMargin - previousPoint.x() ) * m ); } else if ( previousPoint.x() >= q->viewport().width() - m_labelAreaMargin ) { @@ -373,27 +457,27 @@ return QPointF( -1.0, -1.0 ); } return QPointF( q->viewport().width() - m_labelAreaMargin, - previousPoint.y() - - ( previousPoint.x() - q->viewport().width() + m_labelAreaMargin ) * m ); + previousPoint.y() - + ( previousPoint.x() - q->viewport().width() + m_labelAreaMargin ) * m ); } if ( previousPoint.y() <= m_labelAreaMargin ) { if ( labelPositionFlags.testFlag( IgnoreYMargin ) ) { return QPointF( -1.0, -1.0 ); } - return QPointF( previousPoint.x() + ( m_labelAreaMargin - previousPoint.y() ) / m, + return QPointF( previousPoint.x() + ( m_labelAreaMargin - previousPoint.y() ) / m, m_labelAreaMargin ); - } + } else if ( previousPoint.y() >= q->viewport().height() - m_labelAreaMargin ) { if ( labelPositionFlags.testFlag( IgnoreYMargin ) ) { return QPointF( -1.0, -1.0 ); } - return QPointF( previousPoint.x() - - ( previousPoint.y() - q->viewport().height() + m_labelAreaMargin ) / m, - q->viewport().height() - m_labelAreaMargin ); + return QPointF( previousPoint.x() - + ( previousPoint.y() - q->viewport().height() + m_labelAreaMargin ) / m, + q->viewport().height() - m_labelAreaMargin ); } -// mDebug() << Q_FUNC_INFO << "Previous and current node position are allowed!"; + // mDebug() << Q_FUNC_INFO << "Previous and current node position are allowed!"; return QPointF( -1.0, -1.0 ); } @@ -407,7 +491,7 @@ m_currentSector(4), m_previousSector(4), m_currentPoint(QPointF()), - m_previousPoint(QPointF()), + m_previousPoint(QPointF()), m_labelAreaMargin(10.0), m_debugPolygonsLevel(0) { @@ -416,12 +500,12 @@ void ClipPainterPrivate::initClipRect () { - qreal penHalfWidth = q->pen().widthF() / 2.0 + 1.0; + // qreal penHalfWidth = q->pen().widthF() / 2.0 + 1.0; - m_left = -penHalfWidth; - m_right = (qreal)(q->device()->width()) + penHalfWidth; - m_top = -penHalfWidth; - m_bottom = (qreal)(q->device()->height()) + penHalfWidth; + m_left = 20; + m_right = (qreal)(q->device()->width()) - 20; + m_top = 20; + m_bottom = (qreal)(q->device()->height()) - 20; } qreal ClipPainterPrivate::_m( const QPointF & start, const QPointF & end ) @@ -429,12 +513,12 @@ qreal divisor = end.x() - start.x(); if ( std::fabs( divisor ) < 0.000001 ) { // this is in screencoordinates so the difference - // between 0, 0.000001 and -0.000001 isn't visible at all + // between 0, 0.000001 and -0.000001 isn't visible at all divisor = 0.000001; } - return ( end.y() - start.y() ) - / divisor; + return ( end.y() - start.y() ) + / divisor; } @@ -487,17 +571,53 @@ // By adding xSector and ySector we get a // sector number of the values shown in the ASCII-art graph above. return ySector + xSector; +} +// Determines that the point on which border or corner is exactly on, 4 otherwise. +int ClipPainterPrivate::borderSector( const QPointF & point ) const +{ + if(point.x() == m_left) { + return 3; + } else if (point.x() == m_right) { + return 5; + } else if (point.y() == m_top) { + return 1; + } else if (point.y() == m_bottom) { + return 7; + } else { + return sector(point); + } +} + +bool ClipPainterPrivate::isClockwise(const QPointF& pointA, const QPointF& pointB) const +{ + QPointF middlePoint((m_left + m_right)/2.0, -(m_top + m_bottom)/2.0); + + QPointF vecA(QPointF(pointA.x(), -pointA.y()) - middlePoint); + QPointF vecB(QPointF(pointB.x(), -pointB.y()) - middlePoint); + + qreal angle = atan2(vecA.x()*vecB.y() - vecB.x()*vecA.y(), vecA.x()*vecB.x() + vecA.y()*vecB.y()) * RAD2DEG; + mDebug() << "isClockwise angle:" << angle; + return angle < 0; } void ClipPainterPrivate::clipPolyObject ( const QPolygonF & polygon, QVector & clippedPolyObjects, bool isClosed ) { - // mDebug() << "ClipPainter enabled." ; + QList> basePolygon; + QList> clipPolygon; + QList> intersections; + + QList> intersectionsTop; + QList> intersectionsRight; + QList> intersectionsBottom; + QList> intersectionsLeft; + + bool intersectionAdded = false; - // Only create a new polyObject as soon as we know for sure that - // the current point is on the screen. + // Only create a new polyObject as soon as we know for sure that + // the current point is on the screen. QPolygonF clippedPolyObject = QPolygonF(); const QVector::const_iterator itStartPoint = polygon.constBegin(); @@ -510,6 +630,9 @@ bool processingLastNode = false; + mDebug() << "\n"; + mDebug() << "New polygon"; + while ( itPoint != itEndPoint ) { m_currentPoint = (*itPoint); // mDebug() << "m_currentPoint.x()" << m_currentPoint.x() << "m_currentPOint.y()" << m_currentPoint.y(); @@ -522,6 +645,9 @@ if ( isClosed ) { m_previousPoint = polygon.last(); + QSharedPointer firstPoint = QSharedPointer(new Point(m_currentPoint)); + basePolygon << firstPoint; + // Figure out the sector of the previous point. m_previousSector = sector( m_previousPoint ); } @@ -538,11 +664,43 @@ // only one interpolation for both cases. clipOnce( clippedPolyObject, clippedPolyObjects, isClosed ); - } - else { + + if(isClosed) { + + if(!clippedPolyObject.isEmpty()) { + + QSharedPointer intersection = QSharedPointer(new Point(clippedPolyObject.last(), m_currentSector == 4, m_previousSector == 4)); + intersections << intersection; + basePolygon.last()->setNextBasePolygonPoint(intersection); + + QSharedPointer nextPoint = QSharedPointer(new Point(m_currentPoint)); + basePolygon << nextPoint; + intersections.last()->setNextBasePolygonPoint(nextPoint); + + switch(borderSector(intersection->point())) { + case 1: + intersectionsTop << intersection; + break; + case 3: + intersectionsLeft << intersection; + break; + case 5: + intersectionsRight << intersection; + break; + case 7: + intersectionsBottom << intersection; + break; + default: break; + } + + intersectionAdded = true; + + } + } + } else { // This case mostly deals with lines that reach from one // sector that is located off screen to another one that - // is located off screen. In this situation the line + // is located off screen. In this situation the line // can get clipped once, twice, or not at all. clipMultiple( clippedPolyObject, clippedPolyObjects, isClosed ); } @@ -550,16 +708,20 @@ m_previousSector = m_currentSector; } - // If the current point is onscreen, just add it to our final polygon. - if ( m_currentSector == 4 ) { - - clippedPolyObject << m_currentPoint; -#ifdef MARBLE_DEBUG - ++(m_debugNodeCount); -#endif + if (isClosed) { + if(!intersectionAdded) { + QSharedPointer nextPoint = QSharedPointer(new Point(m_currentPoint)); + if(!basePolygon.isEmpty()) { + basePolygon.last()->setNextBasePolygonPoint(nextPoint); + } + basePolygon << nextPoint; + } else { + intersectionAdded = false; + } } m_previousPoint = m_currentPoint; + clippedPolyObject << m_currentPoint; // Now let's handle the case where we have a (closed) polygon and where the // last point of the polyline is outside the viewport and the start point @@ -575,10 +737,114 @@ } } - // Only add the pointer if there's node data available. - if ( !clippedPolyObject.isEmpty() ) { + if(isClosed) { + if(!basePolygon.isEmpty()) { + basePolygon.last()->setNextBasePolygonPoint(basePolygon.first()); + } + + if(!intersections.isEmpty()) { + + clippedPolyObjects.clear(); + clippedPolyObject = QPolygonF(); + + std::sort(intersectionsTop.begin(), intersectionsTop.end(), [](QSharedPointer& A, QSharedPointer& B) { + return A->point().x() < B->point().x(); + }); + + std::sort(intersectionsRight.begin(), intersectionsRight.end(), [](QSharedPointer& A, QSharedPointer& B) { + return A->point().y() < B->point().y(); + }); + + std::sort(intersectionsBottom.begin(), intersectionsBottom.end(), [](QSharedPointer& A, QSharedPointer& B) { + return B->point().x() < A->point().x(); + }); + + std::sort(intersectionsLeft.begin(), intersectionsLeft.end(), [](QSharedPointer& A, QSharedPointer& B) { + return B->point().y() < A->point().y(); + }); + + clipPolygon << QSharedPointer(new Point(QPointF(m_left, m_top))) << intersectionsTop << + QSharedPointer(new Point(QPointF(m_right, m_top))) << intersectionsRight << + QSharedPointer(new Point(QPointF(m_right, m_bottom))) << intersectionsBottom << + QSharedPointer(new Point(QPointF(m_left, m_bottom))) << intersectionsLeft; + + for(int i = 0; i < clipPolygon.size() - 1; ++i) { + clipPolygon[i]->setNextClipPolygonPoint(clipPolygon[i+1]); + } + clipPolygon.last()->setNextClipPolygonPoint(clipPolygon.first()); + + bool iterateBasePolygon = false; + + for(auto& intersection : intersections) { + if(intersection->isEntering() && !intersection->isProcessed()) { + iterateBasePolygon = true; + + QSharedPointer it = intersection; + clippedPolyObject << it->point(); + it->setProcessed(true); + + do { + if(iterateBasePolygon) { + it = it->nextBasePolygonPoint(); + if(it->isLeaving()) { + iterateBasePolygon = false; + it->setProcessed(true); + } else if(it->isEntering()) { + it->setProcessed(true); + } + } else { + it = it->nextClipPolygonPoint(); + if(it->isEntering()) { + iterateBasePolygon = true; + it->setProcessed(true); + } else if(it->isLeaving()) { + it->setProcessed(true); + } + } + clippedPolyObject << it->point(); + + // To avoid crashes. + // Needs to be investigated + if(clippedPolyObject.size() > basePolygon.size()) { + mDebug() << "Something went wrong, exiting current clipping loop..."; + break; + } + + } while(clippedPolyObject.first() != clippedPolyObject.last()); + + clippedPolyObjects << clippedPolyObject; + clippedPolyObject = QPolygonF(); + } + } + + + } + else { + QPolygonF viewport; + viewport << QPointF(m_left, m_top) << QPointF(m_right, m_top) << + QPointF(m_right, m_bottom) << QPointF(m_left, m_bottom); + if(viewport.subtracted(polygon).isEmpty()) { + clippedPolyObjects.clear(); + clippedPolyObject = QPolygonF(); + clippedPolyObject << viewport; + } + } + } + + + if(!clippedPolyObject.isEmpty()) { clippedPolyObjects << clippedPolyObject; } + +} + +void ClipPainterPrivate::clipPolygon( QPolygonF & clippedPolyObject, + QVector & clippedPolyObjects, + bool isClosed ) +{ + Q_UNUSED(clippedPolyObject) + Q_UNUSED(clippedPolyObjects) + Q_UNUSED(isClosed) } @@ -589,7 +855,7 @@ Q_UNUSED( clippedPolyObjects ) Q_UNUSED( isClosed ) - // Take care of adding nodes in the image corners if the iterator + // Take care of adding nodes in the image corners if the iterator // traverses off screen sections. qreal m = _m( m_previousPoint, m_currentPoint ); @@ -608,7 +874,7 @@ } if ( pointTop.x() >= m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; - if ( pointLeft.y() > m_top ) + if ( pointLeft.y() > m_top ) clippedPolyObject << pointLeft; } else if ( m_previousSector == 7 ) { @@ -621,7 +887,7 @@ } else { clippedPolyObject << QPointF( m_left, m_bottom ); } - if ( pointLeft.y() >= m_top && pointLeft.y() < m_bottom ) + if ( pointLeft.y() >= m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointTop.x() > m_left ) clippedPolyObject << pointTop; @@ -634,13 +900,13 @@ if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; - if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) + if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; - if ( pointTop.x() > m_left && pointTop.x() < m_right ) + if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; - if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) + if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; - + if ( pointBottom.x() <= m_left && pointLeft.y() >= m_bottom ) clippedPolyObject << QPointF( m_left, m_bottom ); if ( pointTop.x() >= m_right && pointRight.y() <= m_top ) @@ -682,7 +948,7 @@ if ( pointBottom.x() > m_left ) clippedPolyObject << pointBottom; - if ( pointLeft.y() > m_top && pointLeft.y() <= m_bottom ) + if ( pointLeft.y() > m_top && pointLeft.y() <= m_bottom ) clippedPolyObject << pointLeft; if ( pointTop.x() > m_left ) { clippedPolyObject << pointTop; @@ -701,7 +967,7 @@ if ( pointBottom.x() < m_right ) clippedPolyObject << pointBottom; - if ( pointRight.y() > m_top && pointRight.y() <= m_bottom ) + if ( pointRight.y() > m_top && pointRight.y() <= m_bottom ) clippedPolyObject << pointRight; if ( pointTop.x() < m_right ) { clippedPolyObject << pointTop; @@ -724,7 +990,7 @@ } if ( pointTop.x() > m_left && pointTop.x() <= m_right ) clippedPolyObject << pointTop; - if ( pointRight.y() > m_top ) + if ( pointRight.y() > m_top ) clippedPolyObject << pointRight; } else if ( m_previousSector == 7 ) { @@ -737,7 +1003,7 @@ } else { clippedPolyObject << QPointF( m_right, m_bottom ); } - if ( pointRight.y() >= m_top && pointRight.y() < m_bottom ) + if ( pointRight.y() >= m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointTop.x() < m_right ) clippedPolyObject << pointTop; @@ -750,13 +1016,13 @@ if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; - if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) + if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; - if ( pointTop.x() > m_left && pointTop.x() < m_right ) + if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; - if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) + if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; - + if ( pointBottom.x() >= m_right && pointRight.y() >= m_bottom ) clippedPolyObject << QPointF( m_right, m_bottom ); if ( pointTop.x() <= m_left && pointLeft.y() <= m_top ) @@ -796,7 +1062,7 @@ QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); - if ( pointRight.y() < m_bottom ) + if ( pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() > m_left && pointBottom.x() <= m_right ) clippedPolyObject << pointBottom; @@ -815,7 +1081,7 @@ QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); - if ( pointRight.y() > m_top ) + if ( pointRight.y() > m_top ) clippedPolyObject << pointRight; if ( pointTop.x() > m_left && pointTop.x() <= m_right ) clippedPolyObject << pointTop; @@ -857,7 +1123,7 @@ QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); - if ( pointLeft.y() < m_bottom ) + if ( pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() >= m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; @@ -876,7 +1142,7 @@ QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); - if ( pointLeft.y() > m_top ) + if ( pointLeft.y() > m_top ) clippedPolyObject << pointLeft; if ( pointTop.x() >= m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; @@ -901,7 +1167,7 @@ } if ( pointBottom.x() >= m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; - if ( pointLeft.y() < m_bottom ) + if ( pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; } else if ( m_previousSector == 1 ) { @@ -914,7 +1180,7 @@ } else { clippedPolyObject << QPointF( m_left, m_top ); } - if ( pointLeft.y() > m_top && pointLeft.y() <= m_bottom ) + if ( pointLeft.y() > m_top && pointLeft.y() <= m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() > m_left ) clippedPolyObject << pointBottom; @@ -925,15 +1191,15 @@ QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); - if ( pointTop.x() > m_left && pointTop.x() < m_right ) + if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; - if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) + if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; - if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) + if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; - + if ( pointBottom.x() >= m_right && pointRight.y() >= m_bottom ) clippedPolyObject << QPointF( m_right, m_bottom ); if ( pointTop.x() <= m_left && pointLeft.y() <= m_top ) @@ -975,7 +1241,7 @@ if ( pointTop.x() > m_left ) clippedPolyObject << pointTop; - if ( pointLeft.y() >= m_top && pointLeft.y() < m_bottom ) + if ( pointLeft.y() >= m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() > m_left ) { clippedPolyObject << pointBottom; @@ -994,7 +1260,7 @@ if ( pointTop.x() < m_right ) clippedPolyObject << pointTop; - if ( pointRight.y() >= m_top && pointRight.y() < m_bottom ) + if ( pointRight.y() >= m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() < m_right ) { clippedPolyObject << pointBottom; @@ -1017,7 +1283,7 @@ } if ( pointBottom.x() > m_left && pointBottom.x() <= m_right ) clippedPolyObject << pointBottom; - if ( pointRight.y() < m_bottom ) + if ( pointRight.y() < m_bottom ) clippedPolyObject << pointRight; } else if ( m_previousSector == 1 ) { @@ -1030,7 +1296,7 @@ } else { clippedPolyObject << QPointF( m_right, m_top ); } - if ( pointRight.y() > m_top && pointRight.y() <= m_bottom ) + if ( pointRight.y() > m_top && pointRight.y() <= m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() < m_right ) clippedPolyObject << pointBottom; @@ -1041,15 +1307,15 @@ QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); - if ( pointTop.x() > m_left && pointTop.x() < m_right ) + if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; - if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) + if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; - if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) + if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; - + if ( pointBottom.x() <= m_left && pointLeft.y() >= m_bottom ) clippedPolyObject << QPointF( m_left, m_bottom ); if ( pointTop.x() >= m_right && pointRight.y() <= m_top ) @@ -1060,14 +1326,14 @@ break; default: - break; + break; } } void ClipPainterPrivate::clipOnceCorner( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, const QPointF& corner, - const QPointF& point, + const QPointF& point, bool isClosed ) const { Q_UNUSED( clippedPolyObjects ) @@ -1100,7 +1366,8 @@ // Disappearing clippedPolyObject << point; if ( !isClosed ) { - clippedPolyObjects << clippedPolyObject; + clippedPolyObjects << clippedPolyObject; + clippedPolyObject = QPolygonF(); } } } @@ -1115,7 +1382,7 @@ // Calculating the slope. qreal m = _m( m_previousPoint, m_currentPoint ); - // Calculate in which sector the end of the line is located that is off screen + // Calculate in which sector the end of the line is located that is off screen int offscreenpos = ( m_currentSector == 4 ) ? m_previousSector : m_currentSector; // "Rise over run" for all possible situations . @@ -1165,7 +1432,7 @@ clipOnceCorner( clippedPolyObject, clippedPolyObjects, QPointF( m_right, m_bottom ), point, isClosed ); break; default: - break; + break; } } diff --git a/src/lib/marble/GeoPainter.cpp b/src/lib/marble/GeoPainter.cpp --- a/src/lib/marble/GeoPainter.cpp +++ b/src/lib/marble/GeoPainter.cpp @@ -202,7 +202,7 @@ { const bool antialiased = mapQuality == HighQuality || mapQuality == PrintQuality; setRenderHint( QPainter::Antialiasing, antialiased ); - ClipPainter::setScreenClip(false); + ClipPainter::setScreenClip(true); }