File indexing completed on 2024-04-21 14:46:43

0001 /*
0002     SPDX-FileCopyrightText: 2001 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ksplanetbase.h"
0010 #include "dms.h"
0011 
0012 class KSSun;
0013 
0014 /**
0015  * @class KSMoon
0016  * @short Provides necessary information about the Moon.
0017  * A subclass of SkyObject that provides information
0018  * needed for the Moon.  Specifically, KSMoon provides a moon-specific
0019  * findPosition() function.  Also, there is a method findPhase(), which returns
0020  * the lunar phase as a floating-point number between 0.0 and 1.0.
0021  *
0022  * @author Jason Harris
0023  * @version 1.0
0024  */
0025 class KSMoon : public KSPlanetBase
0026 {
0027   public:
0028     using KSPlanetBase::findPhase;
0029 
0030     /** Default constructor. Set name="Moon". */
0031     KSMoon();
0032     /** Copy constructor */
0033     KSMoon(const KSMoon &o);
0034 
0035     ~KSMoon() override;
0036 
0037     KSMoon *clone() const override;
0038     SkyObject::UID getUID() const override;
0039 
0040     /**
0041      * Determine the phase angle of the moon, and assign the appropriate moon image
0042      * @param Sun a KSSun pointer with coordinates updated to the time of computation.
0043      * If not supplied, the sun is retrieved via KStarsData
0044      * @note Overrides KSPlanetBase::findPhase()
0045      */
0046     void findPhase(const KSSun *Sun = nullptr);
0047 
0048     /** @return the illuminated fraction of the Moon as seen from Earth */
0049     double illum() const { return 0.5 * (1.0 - cos(Phase * dms::PI / 180.0)); }
0050 
0051     /** @return a short string describing the moon's phase */
0052     QString phaseName() const;
0053 
0054     /** reimplemented from KSPlanetBase */
0055     bool loadData() override;
0056 
0057     /** @return iPhase, which is used as a key to find the right image file */
0058     inline short int getIPhase() const { return iPhase; }
0059 
0060     /**
0061      * Reimplemented from KSPlanetBase, this function employs unique algorithms for
0062      * estimating the lunar coordinates.  Finding the position of the moon is
0063      * much more difficult than the other planets.  For one thing, the Moon is
0064      * a lot closer, so we can detect smaller deviations in its orbit.  Also,
0065      * the Earth has a significant effect on the Moon's orbit, and their
0066      * interaction is complex and nonlinear.  As a result, the positions as
0067      * calculated by findPosition() are only accurate to about 10 arcseconds
0068      * (10 times less precise than the planets' positions!)
0069      * @short moon-specific coordinate finder
0070      * @param num KSNumbers pointer for the target date/time
0071      * @note we don't use the Earth pointer here
0072      */
0073     bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *) override;
0074 
0075     /**
0076      * @brief updateMag calls findMagnitude() to calculate current magnitude of moon
0077      * according to current phase. This function is required to perform findMagnitude()
0078      * from any where in Kstars
0079      */
0080     void updateMag() { findMagnitude(nullptr); }
0081 
0082     void initPopupMenu(KSPopupMenu *pmenu) override;
0083 
0084   private:
0085     void findMagnitude(const KSNumbers *) override;
0086 
0087     static bool data_loaded;
0088     static int instance_count;
0089 
0090     /**
0091      * @class MoonLRData
0092      * @short Moon Longitude and radius data object
0093      * Encapsulates the Longitude and radius terms of the sums
0094      * used to compute the moon's position.
0095      */
0096     struct MoonLRData
0097     {
0098         int nd { 0 };
0099         int nm { 0 };
0100         int nm1 { 0 };
0101         int nf { 0 };
0102         double Li { 0 };
0103         double Ri { 0 };
0104     };
0105 
0106     static QList<MoonLRData> LRData;
0107 
0108     /**
0109      * @class MoonBData
0110      * Encapsulates the Latitude terms of the sums used to compute the moon's position.
0111      * @short Moon Latitude data object
0112      */
0113     struct MoonBData
0114     {
0115         int nd { 0 };
0116         int nm { 0 };
0117         int nm1 { 0 };
0118         int nf { 0 };
0119         double Bi { 0 };
0120     };
0121 
0122     static QList<MoonBData> BData;
0123     unsigned int iPhase { 0 };
0124     KSSun *defaultSun=nullptr;
0125 };