[Kstars-devel] KDE/kdeedu/kstars/kstars

Jason Harris kstars at 30doradus.org
Sat Dec 15 02:29:24 CET 2007


SVN commit 748622 by harris:

It's amazing how long it can take to notice terrible design.  
fromScreen() is supposed to convert a position given in pixel 
coordinates to sky coordinates ( (RA,Dec) or (Az,Alt) ).  Somehow, all 
this time, it's been taking dX, dY arguments, which are the *angular* 
offset from the focus position, in radians.  In other words, before 
calling fromScreen(), you first had to do half the work of conversion!  
Wow.  

Anyway, it's fixed now.  fromScreen() now takes a QPointF: the screen 
position to be converted.

Also fixed bizarre behavior of Equirectangular projection.  Still to do: 
get all parts of the sky to be drawn in that projection system.

CCMAIL: kstars-devel at kde.org



 M  +18 -13    skymap.cpp  
 M  +5 -7      skymap.h  
 M  +9 -30     skymapevents.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/skymap.cpp #748621:748622
@@ -872,7 +872,6 @@
 
     float Width = width() * m_Scale;
     float Height = height() * m_Scale;
-
     double zoomscale = Options::zoomFactor() * m_Scale;
 
     //oRefract = true means listen to Options::useRefraction()
@@ -1294,27 +1293,32 @@
 // 	return toScreen( line, scale, oRefract, doClipLines ).toLine();
 // }
 
-SkyPoint SkyMap::fromScreen( double dx, double dy, dms *LST, const dms *lat ) {
-    //Determine RA and Dec of a point, given (dx, dy): it's pixel
+SkyPoint SkyMap::fromScreen( const QPointF &p, dms *LST, const dms *lat ) {
+    //Determine RA and Dec of a point, given (dx, dy): its pixel
     //coordinates in the SkyMap with the center of the map as the origin.
     SkyPoint result;
     double sinY0, cosY0, sinc, cosc;
 
+    //Convert pixel position to x and y offsets in radians
+    double dx = ( 0.5*width()  - p.x() )/Options::zoomFactor();
+    double dy = ( 0.5*height() - p.y() )/Options::zoomFactor();
+
     //Special case: Equirectangular
     if ( Options::projection() == Equirectangular ) {
         if ( Options::useAltAz() ) {
             dms az, alt;
             dx = -1.0*dx;  //Azimuth goes in opposite direction compared to RA
-            az.setRadians( Options::zoomFactor()*dx + focus()->az()->radians() );
-            alt.setRadians( Options::zoomFactor()*dy + focus()->alt()->radians() );
+            az.setRadians( dx + focus()->az()->radians() );
+            alt.setRadians( dy + focus()->alt()->radians() );
             result.setAz( az.reduce() );
             result.setAlt( alt );
             result.HorizontalToEquatorial( LST, lat );
             return result;
         } else {
             dms ra, dec;
-            ra.setRadians( Options::zoomFactor()*dx + focus()->ra()->radians() );
-            dec.setRadians( Options::zoomFactor()*dy + focus()->dec()->radians() );
+	    
+            ra.setRadians( dx + focus()->ra()->radians() );
+            dec.setRadians( dy + focus()->dec()->radians() );
             result.set( ra.reduce(), dec );
             result.EquatorialToHorizontal( LST, lat );
             return result;
@@ -1413,12 +1417,9 @@
 void SkyMap::forceUpdate( bool now )
 {
     QPoint mp( mapFromGlobal( QCursor::pos() ) );
-    double dx = ( 0.5*width()  - mp.x() )/Options::zoomFactor();
-    double dy = ( 0.5*height() - mp.y() )/Options::zoomFactor();
-
-    if (! unusablePoint (dx, dy)) {
+    if (! unusablePoint ( mp )) {
         //determine RA, Dec of mouse pointer
-        setMousePoint( fromScreen( dx, dy, data->LST, data->geo()->lat() ) );
+        setMousePoint( fromScreen( mp, data->LST, data->geo()->lat() ) );
     }
 
     computeSkymap = true;
@@ -1481,8 +1482,12 @@
     }
 }
 
-bool SkyMap::unusablePoint (double dx, double dy)
+bool SkyMap::unusablePoint ( const QPointF &p )
 {
+    //Convert pixel position to x and y offsets in radians
+    double dx = ( 0.5*width()  - p.x() )/Options::zoomFactor();
+    double dy = ( 0.5*height() - p.y() )/Options::zoomFactor();
+
     if (dx >= 1.41 || dx <= -1.41 || dy >= 1.41 || dy <= -1.41)
         return true;
     else
--- trunk/KDE/kdeedu/kstars/kstars/skymap.h #748621:748622
@@ -451,12 +451,11 @@
 
     /**Determine RA, Dec coordinates of the pixel at (dx, dy), which are the
     	*screen pixel coordinate offsets from the center of the Sky pixmap.
-    	*@param dx horizontal pixel offset from center of SkyMap.
-    	*@param dy vertical pixel offset from center of SkyMap.
-    	*@param LSTh pointer to the local sidereal time, as a dms object.
+    	*@param the screen pixel position to convert
+    	*@param LST pointer to the local sidereal time, as a dms object.
     	*@param lat pointer to the current geographic laitude, as a dms object
     	*/
-    SkyPoint fromScreen( double dx, double dy, dms *LST, const dms *lat );
+    SkyPoint fromScreen( const QPointF &p, dms *LST, const dms *lat );
 
     /**@short Determine if the skypoint p is likely to be visible in the display
     	*window.
@@ -830,10 +829,9 @@
     /**Check if the current point on screen is a valid point on the sky. This is needed
     	*to avoid a crash of the program if the user clicks on a point outside the sky (the
     	*corners of the sky map at the lowest zoom level are the invalid points).  
-    	*@param dx the screen pixel X-coordinate, relative to the screen center
-    	*@param dy the screen pixel Y-coordinate, relative to the screen center
+    	*@param p the screen pixel position
     	*/
-    bool unusablePoint (double dx, double dy);
+    bool unusablePoint ( const QPointF &p );
 
     bool mouseButtonDown, midMouseButtonDown;
     bool mouseMoveCursor;  // true if mouseMoveEvent; needed by setMouseMoveCursor
--- trunk/KDE/kdeedu/kstars/kstars/skymapevents.cpp #748621:748622
@@ -492,17 +492,13 @@
         }
     }
 
-    double dx = ( 0.5*width()  - e->x() )/Options::zoomFactor();
-    double dy = ( 0.5*height() - e->y() )/Options::zoomFactor();
-    double dyPix = 0.5*height() - e->y();
+    if ( unusablePoint( e->pos() ) ) return;  // break if point is unusable
 
-    if (unusablePoint (dx, dy)) return;	// break if point is unusable
-
     //determine RA, Dec of mouse pointer
-    setMousePoint( fromScreen( dx, dy, data->LST, data->geo()->lat() ) );
+    setMousePoint( fromScreen( e->pos(), data->LST, data->geo()->lat() ) );
     mousePoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
 
-
+    double dyPix = 0.5*height() - e->y();
     if ( midMouseButtonDown ) { //zoom according to y-offset
         float yoff = dyPix - y0;
 
@@ -563,7 +559,7 @@
         data->HourAngle->setH( dHA );
 
         //redetermine RA, Dec of mouse pointer, using new focus
-        setMousePoint( fromScreen( dx, dy, data->LST, data->geo()->lat() ) );
+        setMousePoint( fromScreen( e->pos(), data->LST, data->geo()->lat() ) );
         mousePoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
         setClickedPoint( mousePoint() );
 
@@ -610,13 +606,10 @@
         //of the sky pixmap's width to the Zoom Circle's diameter
         float factor = float(width()) / float(ZoomRect.width());
 
-        double dx = ( 0.5*width()  - ZoomRect.center().x() )/Options::zoomFactor();
-        double dy = ( 0.5*height() - ZoomRect.center().y() )/Options::zoomFactor();
-
         infoBoxes()->focusObjChanged( i18n( "nothing" ) );
         stopTracking();
 
-        SkyPoint newcenter = fromScreen( dx, dy, data->LST, data->geo()->lat() );
+        SkyPoint newcenter = fromScreen( ZoomRect.center(), data->LST, data->geo()->lat() );
 
         setFocus( &newcenter );
         setDestination( &newcenter );
@@ -668,9 +661,7 @@
     QTimer t;
     t.singleShot (500, this, SLOT (setMouseMoveCursor()));
 
-    double dx = ( 0.5*width()  - e->x() )/Options::zoomFactor();
-    double dy = ( 0.5*height() - e->y() )/Options::zoomFactor();
-    if (unusablePoint (dx, dy)) return;	// break if point is unusable
+    if ( unusablePoint( e->pos() ) ) return;  // break if point is unusable
 
     if ( !midMouseButtonDown && e->button() == Qt::MidButton ) {
         y0 = 0.5*height() - e->y();  //record y pixel coordinate for middle-button zooming
@@ -684,21 +675,11 @@
         }
 
         //determine RA, Dec of mouse pointer
-        setMousePoint( fromScreen( dx, dy, data->LST, data->geo()->lat() ) );
+        setMousePoint( fromScreen( e->pos(), data->LST, data->geo()->lat() ) );
         mousePoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
         setClickedPoint( mousePoint() );
         clickedPoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
 
-//         //DEBUG_REFRACTION_CHECK
-//         QPointF p = toScreen( clickedPoint() ); 
-//         double dx2 = (width()/2.0 - p.x())/Options::zoomFactor();
-//         double dy2 = (height()/2.0 - p.y())/Options::zoomFactor();
-//         SkyPoint sp = fromScreen( dx2, dy2, data->LST, data->geo()->lat() );
-//         kDebug() << "SP1: " << clickedPoint()->az()->toDMSString() 
-//                 << clickedPoint()->alt()->toDMSString() << endl;
-//         kDebug() << "SP2: " << sp.az()->toDMSString() 
-//                 << sp.alt()->toDMSString() << endl;
-
         //Find object nearest to clickedPoint()
         double maxrad = 1000.0/Options::zoomFactor();
         setClickedObject( data->skyComposite()->objectNearest( clickedPoint(), maxrad ) );
@@ -747,12 +728,10 @@
             return;
         }
 
-        double dx = ( 0.5*width()  - e->x() )/Options::zoomFactor();
-        double dy = ( 0.5*height() - e->y() )/Options::zoomFactor();
-        if (unusablePoint (dx, dy)) return;	// break if point is unusable
+        if ( unusablePoint( e->pos() ) ) return;  // break if point is unusable
 
         if (mouseButtonDown ) mouseButtonDown = false;
-        if ( dx != 0.0 || dy != 0.0 )  slotCenter();
+        if ( e->x() != width()/2 || e->y() != height()/2 ) slotCenter();
     }
 }
 


More information about the Kstars-devel mailing list