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 ); @@ -135,13 +143,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 +201,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 +253,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 +324,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 +344,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 +357,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 +373,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 +381,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 +415,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 +424,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 +437,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,7 +495,45 @@ // 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); + } +} + +qreal ClipPainterPrivate::calculateAngle(const QPointF& point) const +{ + QPointF middlePoint((m_left + m_right)/2.0, -(m_top + m_bottom)/2.0); + + qreal angle = atan2(-point.y() - middlePoint.y(), point.x() - middlePoint.x()) * RAD2DEG; + + //if(angle < 0) angle += 360.0; + + return angle; +} + +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, @@ -496,8 +542,38 @@ { // mDebug() << "ClipPainter enabled." ; - // 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. + + struct Point { + QPointF point; + bool isEntering; + bool isLeaving; + + bool operator==(const Point& other) + { + return this->point == other.point && + this->isEntering == other.isEntering && + this->isLeaving == other.isLeaving; + } + + bool operator!=(const Point& other) + { + return !(*this == other); + } + }; + + QList basePolygon; + QList intersectionsTop; + QList intersectionsRight; + QList intersectionsBottom; + QList intersectionsLeft; + QList clipPolygon; + + int indexOfFirstEnteringIntersection = -1; + + // 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 +586,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(); @@ -538,11 +617,35 @@ // only one interpolation for both cases. clipOnce( clippedPolyObject, clippedPolyObjects, isClosed ); + + Point intersection{clippedPolyObject.last(), m_currentSector == 4, m_previousSector == 4}; + + if( indexOfFirstEnteringIntersection == -1 && m_currentSector == 4) { + indexOfFirstEnteringIntersection = basePolygon.size(); + } + + basePolygon << intersection; + + 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; + } } 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 ); } @@ -560,6 +663,7 @@ } m_previousPoint = m_currentPoint; + basePolygon << Point{m_currentPoint, false, false}; // 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 +679,113 @@ } } - // Only add the pointer if there's node data available. - if ( !clippedPolyObject.isEmpty() ) { + if(indexOfFirstEnteringIntersection != -1) { + + std::sort(intersectionsTop.begin(), intersectionsTop.end(), [](Point& A, Point& B) { + return A.point.x() < B.point.x(); + }); + + std::sort(intersectionsRight.begin(), intersectionsRight.end(), [](Point& A, Point& B) { + return A.point.y() < B.point.y(); + }); + + std::sort(intersectionsBottom.begin(), intersectionsBottom.end(), [](Point& A, Point& B) { + return B.point.x() < A.point.x(); + }); + + std::sort(intersectionsLeft.begin(), intersectionsLeft.end(), [](Point& A, Point& B) { + return B.point.y() < A.point.y(); + }); + + clipPolygon << Point{QPointF(m_left, m_top), false, false} << intersectionsTop << + Point{QPointF(m_right, m_top), false, false} << intersectionsRight << + Point{QPointF(m_right, m_bottom), false, false} << intersectionsBottom << + Point{QPointF(m_left, m_bottom), false, false} << intersectionsLeft; + + clippedPolyObjects.clear(); + clippedPolyObject = QPolygonF(); + + bool findNextLeaving = true; + bool findNextEntering =false; + + int i = indexOfFirstEnteringIntersection; + int numCrossingPoints = clipPolygon.size() - 4; + + do { + + if(findNextLeaving) { + clippedPolyObject << basePolygon.at(i).point; + + if(basePolygon.at(i).isLeaving) { + numCrossingPoints--; + basePolygon.removeAt(i); + + int j = clipPolygon.indexOf(Point{clippedPolyObject.last(), false, true}); + + while(!clipPolygon.at(j).isEntering) { + ++j; + if(j == clipPolygon.size()) { + j = 0; + } + + clippedPolyObject << clipPolygon.at(j).point; + } + + if(clippedPolyObject.first() != clippedPolyObject.last()) { + i = basePolygon.indexOf(clipPolygon.at(j)); + clippedPolyObject << basePolygon.at(i).point; + + } else { + clippedPolyObjects << clippedPolyObject; + clippedPolyObject = QPolygonF(); + + findNextLeaving = false; + findNextEntering = true; + } + } + + if(basePolygon.at(i).isEntering || basePolygon.at(i).isLeaving) { + numCrossingPoints--; + } + basePolygon.removeAt(i--); + } + + ++i; + if(i == basePolygon.size()) { + i = 0; + } + + if(numCrossingPoints == 0) { + break; + } + + if(findNextEntering) { + if(basePolygon.at(i).isEntering) { + findNextLeaving = true; + findNextEntering = false; + clippedPolyObject << basePolygon.at(i).point; + } + } + } while(numCrossingPoints > 0); + + } else { + + } + + + 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 +796,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 +815,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 +828,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 +841,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 +889,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 +908,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 +931,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 +944,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 +957,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 +1003,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 +1022,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 +1064,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 +1083,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 +1108,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 +1121,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 +1132,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 +1182,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 +1201,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 +1224,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 +1237,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 +1248,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 +1267,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 +1307,8 @@ // Disappearing clippedPolyObject << point; if ( !isClosed ) { - clippedPolyObjects << clippedPolyObject; + clippedPolyObjects << clippedPolyObject; + clippedPolyObject = QPolygonF(); } } } @@ -1115,7 +1323,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 +1373,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); }