[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.3/kdeedu/marble/src/lib
From:       Torsten Rahn <tackat () kde ! org>
Date:       2009-07-21 0:26:39
Message-ID: 1248135999.329990.20506.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1000190 by rahn:

BUG: 166168
BUG: 190446

Fixed the repeatX feature for Polylines and Polygons.



 M  +1 -1      HttpDownloadManager.cpp  
 M  +91 -2     Projections/AbstractProjection.cpp  
 M  +7 -0      Projections/AbstractProjection_p.h  
 M  +15 -3     geodata/data/GeoDataLineString.cpp  
 M  +12 -2     geodata/data/GeoDataLinearRing.cpp  


--- branches/KDE/4.3/kdeedu/marble/src/lib/HttpDownloadManager.cpp #1000189:1000190
@@ -152,7 +152,7 @@
     iEnd = m_activatedJobList.end();
     for (; i != iEnd; ++i ) {
         if ( job->destinationFileName() == (*i)->destinationFileName() ) {
-            qDebug() << "Download rejected: It's being downloaded already.";
+            qDebug() << "Download rejected: It's being downloaded already:" << \
job->destinationFileName();  (*i)->setInitiatorId( job->initiatorId() );
             return false;
         }
--- branches/KDE/4.3/kdeedu/marble/src/lib/Projections/AbstractProjection.cpp \
#1000189:1000190 @@ -131,7 +131,6 @@
         return false;
     }
 
-
     QVector<GeoDataLineString*> lineStrings;
 
     if (
@@ -139,7 +138,6 @@
          ( lineString.latLonAltBox().crossesDateLine() )
        ) {
         // We correct for Poles and DateLines:
-
         lineStrings = lineString.toRangeCorrected();
 
         foreach ( GeoDataLineString * itLineString, lineStrings ) {
@@ -351,9 +349,100 @@
         delete polygon; // Clean up "unused" empty polygon instances
     }
 
+    d->repeatPolygons( viewport, polygons );
+
     return polygons.isEmpty();
 }
 
+
+void AbstractProjectionPrivate::repeatPolygons( const ViewportParams *viewport,
+                                                QVector<QPolygonF *> &polygons ) {
+    if ( !q->repeatX() ) {
+        // The projection doesn't allow repeats in direction of the x-axis
+        return;
+    }
+    
+    bool globeHidesPoint = false;
+
+    qreal xEast = 0;
+    qreal xWest = 0;
+    qreal y = 0;
+
+    // Choose a latitude that is inside the viewport.
+    qreal centerLatitude = viewport->viewLatLonAltBox().center().latitude();
+    
+    GeoDataCoordinates westCoords( -M_PI, centerLatitude );
+    GeoDataCoordinates eastCoords( +M_PI, centerLatitude );
+
+    q->screenCoordinates( westCoords, viewport, xWest, y, globeHidesPoint );
+    q->screenCoordinates( eastCoords, viewport, xEast, y, globeHidesPoint );
+
+    if ( xWest <= 0 && xEast >= viewport->width() - 1 ) {
+//        qDebug() << "No repeats";
+        return;
+    }
+
+    qreal repeatXInterval = xEast - xWest;
+
+    qreal repeatsLeft  = 0;
+    qreal repeatsRight = 0;
+
+    if ( xWest > 0 ) {
+        repeatsLeft = (int)( xWest / repeatXInterval ) + 1;
+    }
+    if ( xEast < viewport->width() ) {
+        repeatsRight = (int)( ( viewport->width() - xEast ) / repeatXInterval ) + 1;
+    }
+
+    QVector<QPolygonF *> repeatedPolygons;
+    QVector<QPolygonF *> translatedPolygons;
+
+    qreal xOffset = 0;
+    qreal it = repeatsLeft;
+    
+    while ( it > 0 ) {
+        xOffset = -it * repeatXInterval;
+        translatePolygons( polygons, translatedPolygons, xOffset );
+        repeatedPolygons << translatedPolygons;
+        translatedPolygons.clear();
+        --it;
+    }
+
+    repeatedPolygons << polygons;
+
+    it = 1;
+
+    while ( it <= repeatsRight ) {
+        xOffset = +it * repeatXInterval;
+        translatePolygons( polygons, translatedPolygons, xOffset );
+        repeatedPolygons << translatedPolygons;
+        translatedPolygons.clear();
+        ++it;
+    }
+
+    polygons = repeatedPolygons;
+
+//    qDebug() << Q_FUNC_INFO << "Coordinates: " << xWest << xEast
+//             << "Repeats: " << repeatsLeft << repeatsRight;
+}
+
+void AbstractProjectionPrivate::translatePolygons( const QVector<QPolygonF *> \
&polygons, +                                                   QVector<QPolygonF *> \
&translatedPolygons, +                                                   qreal \
xOffset ) { +//    qDebug() << "Translation: " << xOffset;
+
+    QVector<QPolygonF *>::const_iterator itPolygon = polygons.constBegin();
+    QVector<QPolygonF *>::const_iterator itEnd = polygons.constEnd();
+    
+    for( ; itPolygon != itEnd; ++itPolygon ) {
+        QPolygonF * polygon = new QPolygonF;
+        *polygon = **itPolygon;
+        polygon->translate( xOffset, 0 );
+        translatedPolygons.append( polygon );
+    }
+}
+
+
 void AbstractProjectionPrivate::manageHorizonCrossing( bool globeHidesPoint,
                                                 const GeoDataCoordinates& \
horizonCoords,  bool& horizonPair,
--- branches/KDE/4.3/kdeedu/marble/src/lib/Projections/AbstractProjection_p.h \
#1000189:1000190 @@ -49,6 +49,13 @@
                                     const GeoDataCoordinates &currentCoords,
                                     int count, const ViewportParams *viewport,
                                     TessellationFlags f = 0 );
+
+    void repeatPolygons( const ViewportParams *viewport,
+                         QVector<QPolygonF *> &polygons );
+
+    void translatePolygons( const QVector<QPolygonF *> &polygons,
+                            QVector<QPolygonF *> &translatedPolygons,
+                            qreal xOffset );
 };
 
 } // namespace Marble
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataLineString.cpp \
#1000189:1000190 @@ -279,6 +279,8 @@
     qreal lon;
     qreal lat;
 
+    // FIXME: Think about how we can avoid unnecessary copies
+    //        if the linestring stays the same.
     for( QVector<GeoDataCoordinates>::const_iterator itCoords
           = p()->m_vector.constBegin();
          itCoords != p()->m_vector.constEnd();
@@ -301,11 +303,21 @@
 
         qDeleteAll( p()->m_rangeCorrected ); // This shouldn't be needed
 
-        GeoDataLineString poleCorrected = toPoleCorrected();
-
+        GeoDataLineString poleCorrected;
+        
+        if ( latLonAltBox().crossesDateLine() )
+        {
+            GeoDataLineString normalizedLineString = toNormalized();
+            poleCorrected = normalizedLineString.toPoleCorrected();
+            p()->m_rangeCorrected = poleCorrected.toDateLineCorrected();
+        }
+        else {
+            poleCorrected = toPoleCorrected();
+        }
+        
         p()->m_rangeCorrected = poleCorrected.toDateLineCorrected();
     }
-    
+
     return p()->m_rangeCorrected;
 }
 
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataLinearRing.cpp \
#1000189:1000190 @@ -49,10 +49,20 @@
 {
     if ( p()->m_dirtyRange ) {
 
-        qDeleteAll( p()->m_rangeCorrected );
+        qDeleteAll( p()->m_rangeCorrected ); // This shouldn't be needed
 
-        GeoDataLinearRing poleCorrected = toPoleCorrected();
+        GeoDataLinearRing poleCorrected;
 
+        if ( latLonAltBox().crossesDateLine() )
+        {
+            GeoDataLinearRing normalizedLineString = toNormalized();
+            poleCorrected = normalizedLineString.toPoleCorrected();
+            p()->m_rangeCorrected = poleCorrected.toDateLineCorrected();
+        }
+        else {
+            poleCorrected = toPoleCorrected();
+        }
+
         p()->m_rangeCorrected = poleCorrected.toDateLineCorrected();
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic