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

Alexey Khudyakov alexey.skladnoy at gmail.com
Tue Jun 29 18:50:43 CEST 2010


SVN commit 1144326 by khudyakov:

* Make constructor dms(double) explicit. This disallows implicit construction
  from double and numberic literals. On one hand it adds verbosity to code
  on other hand in add some degree of type safety. Angle is angle not a
  number.

* Add + and - operators for dms. This allows to add and subtract angles
  directly without resorting to kludges like:
  > a.Degrees() + b.Degrees()

  Pattern above was spotted during change of contructor.

CCMAIL: kstars-devel at kde.org

 M  +1 -1      dialogs/locationdialog.cpp  
 M  +14 -1     dms.h  
 M  +3 -3      geolocation.cpp  
 M  +5 -5      kstarsdata.cpp  
 M  +1 -1      skycomponents/solarsystemsinglecomponent.cpp  
 M  +4 -4      skymapevents.cpp  
 M  +2 -2      skyobjects/ksplanet.cpp  
 M  +1 -1      skyobjects/ksplanetbase.h  
 M  +1 -1      skyobjects/skypoint.cpp  
 M  +3 -3      tools/ksconjunct.cpp  
 M  +1 -1      tools/modcalcaltaz.cpp  
 M  +2 -2      tools/modcalcgeodcoord.cpp  
 M  +1 -1      tools/modcalcplanets.cpp  
 M  +1 -1      tools/obslistwizard.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/dialogs/locationdialog.cpp #1144325:1144326
@@ -280,7 +280,7 @@
             file.close();
 
             //Add city to geoList...don't need to insert it alphabetically, since we always sort GeoList
-            GeoLocation *g = new GeoLocation( lng.Degrees(), lat.Degrees(),
+            GeoLocation *g = new GeoLocation( lng, lat,
                                               ui->NewCityName->text(), ui->NewProvinceName->text(), ui->NewCountryName->text(),
                                               TZ, &data->Rulebook[ TZrule ] );
             // FIXME: Uses friendship
--- trunk/KDE/kdeedu/kstars/kstars/dms.h #1144325:1144326
@@ -54,7 +54,7 @@
      * Creates an angle whose value in Degrees is equal to the argument.
      * @param x angle expressed as a floating-point number (in degrees)
      */
-    dms( const double &x ) : D(x) {}
+    explicit dms( const double &x ) : D(x) {}
 
     /**@short Construct an angle from a string representation.
      *
@@ -256,8 +256,21 @@
 
 private:
     double D;
+
+    friend dms operator+(dms, dms);
+    friend dms operator-(dms, dms); 
 };
 
+/// Add two angles
+inline dms operator + (dms a, dms b) {
+    return dms( a.D + b.D);
+}
+
+/// Subtract angles
+inline dms operator - (dms a, dms b) {
+    return dms( a.D - b.D);
+}
+
 // Inline sincos
 inline void dms::SinCos(double& s, double& c) const {
 #ifdef __GLIBC__
--- trunk/KDE/kdeedu/kstars/kstars/geolocation.cpp #1144325:1144326
@@ -21,9 +21,9 @@
 #include "timezonerule.h"
 
 
-GeoLocation::GeoLocation(){
-    GeoLocation( 0.0, 0.0 );
-}
+GeoLocation::GeoLocation()
+    // FIXME: Default contructor is wrong
+{}
 
 GeoLocation::GeoLocation( dms lng, dms lat,
                           const QString &name, const QString &province, const QString &country, double tz, TimeZoneRule *tzrule, int iEllips, double hght ) {
--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.cpp #1144325:1144326
@@ -324,15 +324,15 @@
 }
 
 void KStarsData::setLocationFromOptions() {
-    setLocation( GeoLocation ( Options::longitude(), Options::latitude(),
+    setLocation( GeoLocation ( dms(Options::longitude()), dms(Options::latitude()),
                                Options::cityName(), Options::provinceName(), Options::countryName(),
                                Options::timeZone(), &(Rulebook[ Options::dST() ]), 4, Options::elevation() ) );
 }
 
 void KStarsData::setLocation( const GeoLocation &l ) {
     m_Geo = GeoLocation(l);
-    if ( m_Geo.lat()->Degrees() >=  90.0 ) m_Geo.setLat( 89.99 );
-    if ( m_Geo.lat()->Degrees() <= -90.0 ) m_Geo.setLat( -89.99 );
+    if ( m_Geo.lat()->Degrees() >=  90.0 ) m_Geo.setLat( dms(89.99) );
+    if ( m_Geo.lat()->Degrees() <= -90.0 ) m_Geo.setLat( dms(-89.99) );
 
     //store data in the Options objects
     Options::setCityName( m_Geo.name() );
@@ -445,7 +445,7 @@
     if ( fields[11].isEmpty() || ('x' == fields[11].at(0)) ) {
         TZ = int(lng/15.0);
     } else {
-        bool doubleCheck = true;
+        bool doubleCheck;
         TZ = fields[11].toDouble( &doubleCheck);
         if ( !doubleCheck ) {
             kDebug() << fields[11] << i18n( "\nCities.dat: Bad time zone.  Line was:\n" ) << line;
@@ -458,7 +458,7 @@
     TZrule = &( Rulebook[ fields[12] ] );
 
     // appends city names to list
-    geoList.append ( new GeoLocation( lng, lat, name, province, country, TZ, TZrule ));
+    geoList.append ( new GeoLocation( dms(lng), dms(lat), name, province, country, TZ, TZrule ));
     return true;
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/solarsystemsinglecomponent.cpp #1144325:1144326
@@ -138,7 +138,7 @@
              !m_Planet->image()->isNull() &&  //image loaded ok,
              size < Width )  //and size isn't too big.
         {
-            dms pa = map->findPA( m_Planet, o.x(), o.y() );
+            dms pa( map->findPA( m_Planet, o.x(), o.y() ) );
 
             //FIXME: Need to figure out why the size is sometimes NaN.
             Q_ASSERT( !isnan( size ) && "Core dumps are good for you NaNs");
--- trunk/KDE/kdeedu/kstars/kstars/skymapevents.cpp #1144325:1144326
@@ -477,16 +477,16 @@
         if ( Options::useAltAz() ) {
             mousePoint()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
             clickedPoint()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
-            dms dAz = mousePoint()->az().Degrees() - clickedPoint()->az().Degrees();
-            dms dAlt = mousePoint()->alt().Degrees() - clickedPoint()->alt().Degrees();
+            dms dAz  = mousePoint()->az()  - clickedPoint()->az();
+            dms dAlt = mousePoint()->alt() - clickedPoint()->alt();
             focus()->setAz( focus()->az().Degrees() - dAz.Degrees() ); //move focus in opposite direction
             focus()->setAz( focus()->az().reduce() );
             focus()->setAlt(
                 KSUtils::clamp( focus()->alt().Degrees() - dAlt.Degrees() , -90.0 , 90.0 ) );
             focus()->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
         } else {
-            dms dRA = mousePoint()->ra().Degrees() - clickedPoint()->ra().Degrees();
-            dms dDec = mousePoint()->dec().Degrees() - clickedPoint()->dec().Degrees();
+            dms dRA  = mousePoint()->ra()  - clickedPoint()->ra();
+            dms dDec = mousePoint()->dec() - clickedPoint()->dec();
             focus()->setRA( focus()->ra().Hours() - dRA.Hours() ); //move focus in opposite direction
             focus()->setRA( focus()->ra().reduce() );
             focus()->setDec(
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanet.cpp #1144325:1144326
@@ -190,8 +190,8 @@
     }
 
     if ( ! odm.loadData( odc, untranslatedName() ) ) {
-        epret.longitude = 0.0;
-        epret.latitude = 0.0;
+        epret.longitude = dms(0.0);
+        epret.latitude  = dms(0.0);
         epret.radius = 0.0;
         kError() << "Could not get data for '" << name() << "'" << endl;
         return;
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanetbase.h #1144325:1144326
@@ -45,7 +45,7 @@
     double radius;
 
     /**Constructor. */
-    explicit EclipticPosition(dms plong = 0.0, dms plat = 0.0, double prad = 0.0) :
+    explicit EclipticPosition(dms plong = dms(), dms plat = dms(), double prad = 0.0) :
         longitude(plong), latitude(plat), radius(prad)
     {}
 };
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/skypoint.cpp #1144325:1144326
@@ -61,7 +61,7 @@
     double sindec, cosdec, sinlat, coslat, sinHA, cosHA;
     double sinAlt, cosAlt;
 
-    dms HourAngle = LST->Degrees() - ra().Degrees();
+    dms HourAngle = (*LST) - ra();
 
     lat->SinCos( sinlat, coslat );
     dec().SinCos( sindec, cosdec );
--- trunk/KDE/kdeedu/kstars/kstars/tools/ksconjunct.cpp #1144325:1144326
@@ -75,7 +75,7 @@
     emit madeProgress( progress );
     
     Dist = findDistance(jd, &Object1, &Object2);
-    Sign = sgn(Dist.Degrees() - prevDist.Degrees()); 
+    Sign = sgn(Dist - prevDist); 
     //	kDebug() << "Dist = " << Dist.toDMSString() << "; prevDist = " << prevDist.toDMSString() << "; Difference = " << (Dist.Degrees() - prevDist.Degrees()) << "; Step = " << step;
 
     //How close are we to a conjunction, and how fast are we approaching one?
@@ -94,7 +94,7 @@
             Sign = prevSign;
             while ( jd <= stopJD ) {
                 Dist = findDistance(jd, &Object1, &Object2);
-                Sign = sgn(Dist.Degrees() - prevDist.Degrees()); 
+                Sign = sgn(Dist - prevDist); 
                 //	kDebug() << "Dist=" << Dist.toDMSString() << "; prevDist=" << prevDist.toDMSString() << "; Diff=" << (Dist.Degrees() - prevDist.Degrees()) << "djd=" << (int)(jd - startJD);
                 if ( Sign != prevSign ) break;
                 
@@ -171,7 +171,7 @@
       else
         return false;
     }
-    Sign = sgn(Dist.Degrees() - prevDist.Degrees());
+    Sign = sgn(Dist - prevDist);
     if(Sign != prevSign) {
       step = -step / 2.0;
       Sign = -Sign;
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcaltaz.cpp #1144325:1144326
@@ -376,7 +376,7 @@
         jdf = KStarsDateTime(dtB,utB).djd();
         jd0 = dt.djd();
 
-        LST = KStarsDateTime(dtB,utB).gst().Degrees() + longB.Degrees();
+        LST = KStarsDateTime(dtB,utB).gst() + longB;
 
         // Equatorial coordinates are the input coords.
         if (!horInputCoords) {
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcgeodcoord.cpp #1144325:1144326
@@ -86,8 +86,8 @@
 void modCalcGeodCoord::slotClearGeoCoords (void)
 {
 
-    geoPlace->setLong( 0.0 );
-    geoPlace->setLat(  0.0 );
+    geoPlace->setLong( dms(0.0) );
+    geoPlace->setLat(  dms(0.0) );
     geoPlace->setHeight( 0.0 );
     LatGeoBox->clearFields();
     LongGeoBox->clearFields();
--- trunk/KDE/kdeedu/kstars/kstars/tools/modcalcplanets.cpp #1144325:1144326
@@ -367,7 +367,7 @@
 
 
         KStarsDateTime edt( dtB, utB );
-        dms LST = edt.gst().Degrees() + longB.Degrees();
+        dms LST = edt.gst() + longB;
 
         KSNumbers num( edt.djd() );
         KSPlanet Earth( I18N_NOOP( "Earth" ));
--- trunk/KDE/kdeedu/kstars/kstars/tools/obslistwizard.cpp #1144325:1144326
@@ -309,7 +309,7 @@
     } else if ( ! olw->RA->isEmpty() && ! olw->Dec->isEmpty() && ! olw->Radius->isEmpty() ) {
         bool circOk;
         dms ra = olw->RA->createDms( false, &circOk );
-        dms dc = 0.0;
+        dms dc;
         if ( circOk )
             dc = olw->Dec->createDms( true, &circOk );
         if ( circOk ) {


More information about the Kstars-devel mailing list