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 @@ -22,7 +22,7 @@ class ClipPainterPrivate { - public: +public: explicit ClipPainterPrivate( ClipPainter * parent ); ClipPainter * q; @@ -43,9 +43,24 @@ // int m_debugNodeCount; QPointF m_currentPoint; - QPointF m_previousPoint; + QPointF m_previousPoint; + + // + QPointF m_currentCrossing; + QPointF m_previousCrossing; + + int m_currentCrossingSector; + int m_previousCrossingSector; + + qreal m_currentCrossingAngle; + qreal m_previousCrossingAngle; + + bool m_hasCrossingPoint; 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,16 +69,20 @@ inline void initClipRect(); - inline void clipPolyObject ( const QPolygonF & sourcePolygon, + inline void clipPolyObject ( const QPolygonF & sourcePolygon, QVector & clippedPolyObjects, bool isClosed ); + inline void clipPolygon( QPolygonF & clippedPolyObject, + QVector & clippedPolyObjects, + bool isClosed ); + inline void clipMultiple( QPolygonF & clippedPolyObject, 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 +93,16 @@ const QPointF& point, bool isClosed ) const; + inline void closePolygon( 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 +158,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 +216,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 +268,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 +339,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 +359,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 +372,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 +388,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 +396,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 +430,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 +439,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 +452,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 +510,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 +557,8 @@ { // 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. QPolygonF clippedPolyObject = QPolygonF(); const QVector::const_iterator itStartPoint = polygon.constBegin(); @@ -510,6 +571,15 @@ bool processingLastNode = false; + m_previousCrossing = QPointF(0,0); + m_previousCrossingSector = -1; + m_currentCrossingSector = -1; + m_previousCrossingAngle = 0; + m_currentCrossingAngle = 0; + m_hasCrossingPoint = 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(); @@ -537,12 +607,18 @@ // screen but not both. Hence we only need to clip once and require // only one interpolation for both cases. - clipOnce( clippedPolyObject, clippedPolyObjects, isClosed ); - } - else { + m_hasCrossingPoint = true; + + if(!isClosed) { + clipOnce( clippedPolyObject, clippedPolyObjects, isClosed ); + } else { + clipPolygon( clippedPolyObject, clippedPolyObjects, isClosed ); + } + + } else if (!isClosed/* || m_hasCrossingPoint */) { // 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 ); } @@ -569,18 +645,397 @@ } ++itPoint; - if ( itPoint == itEndPoint && isClosed ) { + if ( itPoint == itEndPoint && isClosed ) { + itPoint = itStartPoint; processingLastNode = true; } } + if(isClosed) { + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + } + // Only add the pointer if there's node data available. if ( !clippedPolyObject.isEmpty() ) { clippedPolyObjects << clippedPolyObject; } } +void ClipPainterPrivate::clipPolygon( QPolygonF & clippedPolyObject, + QVector & clippedPolyObjects, + bool isClosed ) +{ + clipOnce(clippedPolyObject, clippedPolyObjects, isClosed); + + if (isClosed && clippedPolyObject.size() > 1) { + if (m_currentSector != 4 && m_previousSector == 4) { + // Disappearing + + if(m_currentCrossingSector != -1) { + m_previousCrossing = m_currentCrossing; + m_currentCrossing = clippedPolyObject.last(); + + m_previousCrossingSector = m_currentCrossingSector; + m_currentCrossingSector = borderSector(m_currentCrossing); + + m_previousCrossingAngle = m_currentCrossingAngle; + m_currentCrossingAngle = calculateAngle(m_currentCrossing); + + switch (m_currentCrossingSector) { + case 1: + switch(m_previousCrossingSector) { + case 1: + break; + case 5: + if(borderSector(clippedPolyObject.at(clippedPolyObject.size() - 2)) != 4) { + clippedPolyObject << QPointF(m_right, m_top); + } + break; + case 7: + break; + case 3: + break; + default: + break; + } + break; + case 5: + switch(m_previousCrossingSector) { + case 1: + break; + case 5: + break; + case 7: + break; + case 3: + break; + default: + break; + } + + break; + case 7: + switch(m_previousCrossingSector) { + case 1: + break; + case 5: + if(borderSector(clippedPolyObject.at(clippedPolyObject.size() - 2)) != 4) { + clippedPolyObject << QPointF(m_right, m_bottom); + } + break; + case 7: + break; + case 3: + break; + default: + break; + } + + break; + case 3: + switch(m_previousCrossingSector) { + case 1: + if(borderSector(clippedPolyObject.at(clippedPolyObject.size() - 2)) != 4) { + clippedPolyObject << QPointF(m_left, m_top); + } + break; + case 5: + break; + case 7: + break; + case 3: + break; + default: + break; + } + + break; + default: + break; + } + } else { + m_currentCrossing = clippedPolyObject.last(); + m_currentCrossingSector = borderSector(m_currentCrossing); + m_currentCrossingAngle = calculateAngle(m_currentCrossing); + if( m_currentCrossingSector == borderSector(clippedPolyObject.first()) && + !isClockwise(clippedPolyObject.first(), m_currentCrossing)) { + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + } + } + + mDebug() << "Disappearing"; + mDebug() << "m_currentCrossingSector:" << m_currentCrossingSector; + mDebug() << "m_previousCrossingSector:" << m_previousCrossingSector; + mDebug() << "m_currentCrossingAngle:" << m_currentCrossingAngle; + mDebug() << "m_previousCrossingAngle:" << m_previousCrossingAngle; + mDebug() << "Angle delta:" << m_currentCrossingAngle - m_previousCrossingAngle; + } else if (m_currentSector == 4 && m_previousSector != 4) { + // Appearing + + if(m_currentCrossingSector != -1) { + m_previousCrossing = m_currentCrossing; + m_currentCrossing = clippedPolyObject.last(); + + m_previousCrossingSector = m_currentCrossingSector; + m_currentCrossingSector = borderSector(m_currentCrossing); + + m_previousCrossingAngle = m_currentCrossingAngle; + m_currentCrossingAngle = calculateAngle(m_currentCrossing); + + switch (m_currentCrossingSector) { + case 1: + switch(m_previousCrossingSector) { + case 1: + if(!isClockwise(m_previousCrossing, m_currentCrossing)) { + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + } + break; + case 5: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + case 7: + break; + case 3: + clippedPolyObject.removeLast(); + clippedPolyObject << QPointF(m_left, m_top); + clippedPolyObject << m_currentCrossing; + break; + default: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + } + break; + case 5: + switch(m_previousCrossingSector) { + case 1: + break; + case 5: + if(!isClockwise(m_previousCrossing, m_currentCrossing)) { + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + } + break; + case 7: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + case 3: + break; + default: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + } + + break; + case 7: + switch(m_previousCrossingSector) { + case 1: + break; + case 5: + clippedPolyObject.removeLast(); + clippedPolyObject << QPointF(m_right, m_bottom); + clippedPolyObject << m_currentCrossing; + break; + case 7: + if(!isClockwise(m_previousCrossing, m_currentCrossing)) { + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + } + break; + case 3: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + default: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + } + + break; + case 3: + switch(m_previousCrossingSector) { + case 1: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + case 5: + clippedPolyObject.removeLast(); + clippedPolyObject << QPointF(m_right, m_bottom); + clippedPolyObject << QPointF(m_left, m_bottom); + clippedPolyObject << m_currentCrossing; + break; + case 7: + clippedPolyObject.removeLast(); + clippedPolyObject << QPointF(m_left, m_bottom); + clippedPolyObject << m_currentCrossing; + break; + case 3: + if(!isClockwise(m_previousCrossing, m_currentCrossing)) { + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + } + break; + default: + clippedPolyObject.removeLast(); + closePolygon(clippedPolyObject, clippedPolyObjects, isClosed); + clippedPolyObject << m_currentCrossing; + break; + } + + break; + default: + break; + } + + } else { + m_currentCrossing = clippedPolyObject.last(); + m_currentCrossingSector = borderSector(m_currentCrossing); + m_currentCrossingAngle = calculateAngle(m_currentCrossing); + } + + mDebug() << "Appearing"; + mDebug() << "m_currentCrossingSector:" << m_currentCrossingSector; + mDebug() << "m_previousCrossingSector:" << m_previousCrossingSector; + mDebug() << "m_currentCrossingAngle:" << m_currentCrossingAngle; + mDebug() << "m_previousCrossingAngle:" << m_previousCrossingAngle; + mDebug() << "Angle delta:" << m_currentCrossingAngle - m_previousCrossingAngle; + } + } +} + +void ClipPainterPrivate::closePolygon( QPolygonF & clippedPolyObject, + QVector & clippedPolyObjects, + bool isClosed ) +{ + Q_UNUSED(isClosed) + Q_UNUSED(clippedPolyObjects) + + if(!clippedPolyObject.isEmpty()) { + + int firstPointSector = borderSector(clippedPolyObject.first()); + + mDebug() << "firstPointSector:" << firstPointSector; + mDebug() << " "; + + switch (m_currentCrossingSector) { + case 1: + switch(firstPointSector) { + case 1: + break; + case 5: + clippedPolyObject << QPointF(m_right, m_top); + break; + case 7: + clippedPolyObject << QPointF(m_right, m_top); + clippedPolyObject << QPointF(m_right, m_bottom); + break; + case 3: + break; + case -1: + break; + default: + break; + } + break; + case 5: + switch(firstPointSector) { + case 1: + clippedPolyObject << QPointF(m_right, m_bottom); + clippedPolyObject << QPointF(m_left, m_bottom); + clippedPolyObject << QPointF(m_left, m_top); + break; + case 5: + break; + case 7: + clippedPolyObject << QPointF(m_right, m_bottom); + break; + case 3: + clippedPolyObject << QPointF(m_right, m_bottom); + clippedPolyObject << QPointF(m_left, m_bottom); + break; + case -1: + break; + default: + break; + } + + break; + case 7: + switch(firstPointSector) { + case 1: + clippedPolyObject << QPointF(m_left, m_bottom); + clippedPolyObject << QPointF(m_left, m_top); + break; + case 5: + clippedPolyObject << QPointF(m_left, m_bottom); + clippedPolyObject << QPointF(m_left, m_top); + clippedPolyObject << QPointF(m_right, m_top); + break; + case 7: + break; + case 3: + clippedPolyObject << QPointF(m_left, m_bottom); + break; + default: + break; + } + + break; + case 3: + switch(firstPointSector) { + case 1: + clippedPolyObject << QPointF(m_left, m_top); + break; + case 5: + clippedPolyObject << QPointF(m_left, m_top); + clippedPolyObject << QPointF(m_right, m_top); + break; + case 7: + clippedPolyObject << QPointF(m_left, m_top); + clippedPolyObject << QPointF(m_right, m_top); + clippedPolyObject << QPointF(m_right, m_bottom); + break; + case 3: + break; + default: + break; + } + + break; + default: + break; + } + + clippedPolyObjects << clippedPolyObject; + clippedPolyObject = QPolygonF(); + + if (m_currentSector == 4 && m_previousSector != 4) { + m_previousCrossingSector = -1; + } else { + m_currentCrossingSector = -1; + m_previousCrossingSector = -1; + } + } +} + + void ClipPainterPrivate::clipMultiple( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, @@ -589,7 +1044,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 +1063,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 +1076,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 +1089,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 +1137,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 +1156,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 +1179,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 +1192,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 +1205,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 +1251,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 +1270,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 +1312,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 +1331,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 +1356,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 +1369,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 +1380,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 +1430,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 +1449,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 +1472,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 +1485,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 +1496,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 +1515,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 +1555,8 @@ // Disappearing clippedPolyObject << point; if ( !isClosed ) { - clippedPolyObjects << clippedPolyObject; + clippedPolyObjects << clippedPolyObject; + clippedPolyObject = QPolygonF(); } } } @@ -1115,7 +1571,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 +1621,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); }