[Marble-commits] branches/KDE/4.3/kdeedu/marble/src/lib

Torsten Rahn tackat at kde.org
Tue Jul 28 15:55:37 CEST 2009


SVN commit 1003635 by rahn:

- Backport possible division by zero and loop fixes.



 M  +9 -1      MarbleMap.cpp  
 M  +11 -0     MarbleWidget.cpp  


--- branches/KDE/4.3/kdeedu/marble/src/lib/MarbleMap.cpp #1003634:1003635
@@ -497,7 +497,7 @@
     // (about 800 pixels) equals the viewing angle of a human being.
 
     const qreal VIEW_ANGLE = 110.0;
-
+    
     return ( model()->planet()->radius() * 0.4
             / (qreal)( radius() )
             / tan( 0.5 * VIEW_ANGLE * DEG2RAD ) );
@@ -505,6 +505,13 @@
 
 void MarbleMap::setDistance( qreal distance )
 {
+    qreal minDistance = 0.001;
+
+    if ( distance <= minDistance ) {
+        qDebug() << "Invalid distance: 0 m";
+        distance = minDistance;
+    }
+    
     const qreal VIEW_ANGLE = 110.0;
 
     setRadius( (int)( model()->planet()->radius() * 0.4
@@ -1203,6 +1210,7 @@
     // reality. Therefore we assume that the average window width
     // (about 800 pixels) equals the viewing angle of a human being.
     //
+
     qreal distance = ( model()->planet()->radius() * 0.4
 			/ (qreal)( radius() )
 			/ tan( 0.5 * VIEW_ANGLE * DEG2RAD ) );
--- branches/KDE/4.3/kdeedu/marble/src/lib/MarbleWidget.cpp #1003634:1003635
@@ -251,6 +251,10 @@
 
 void MarbleWidget::setRadius(int radius)
 {
+    if ( radius == d->m_map->radius() ) {
+        return;
+    }
+        
     d->m_map->setRadius( radius );
 
     // We only have to repaint the background every time if the earth
@@ -557,6 +561,13 @@
         GeoDataCoordinates targetPosition = position;
         targetPosition.setAltitude( distance() );
 
+        // Avoid zero distance
+        qreal minDistance = 0.001;
+        
+        if ( targetPosition.altitude() <= minDistance ) {
+            targetPosition.setAltitude( minDistance );
+        }
+        
         d->m_physics->jumpTo( targetPosition );
     } else {
         qreal  lon, lat;


More information about the Marble-commits mailing list