1 /*
2     SPDX-FileCopyrightText: Vipul Kumar Singh <vipulkrsingh@gmail.com>
3     SPDX-FileCopyrightText: Médéric Boquien <mboquien@free.fr>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 #include <QString>
11 #include <QVector>
12 
13 class KSNumbers;
14 class KSPlanetBase;
15 class KSSun;
16 class TrailObject;
17 class dms;
18 
19 /**
20  * @class PlanetMoons
21  *
22  * Implements the moons of a planet.
23  *
24  * TODO: make the moons SkyObjects, rather than just points.
25  *
26  * @author Vipul Kumar Singh
27  * @version 1.0
28  */
29 class PlanetMoons
30 {
31   public:
32     /**
33      * Constructor.  Assign the name of each moon,
34      * and initialize their XYZ positions to zero.
35      */
36     PlanetMoons() = default;
37 
38     /** Destructor.  Delete moon objects */
39     virtual ~PlanetMoons();
40 
41     /**
42      * @return pointer to a moon given the ID number.
43      * @param id which moon?
44      */
moon(int id)45     inline TrailObject *moon(int id) { return Moon[id]; }
46 
47     /**
48      * @return the name of a moon.
49      * @param id which moon?
50      */
51     QString name(int id) const;
52 
53     /**
54      * Convert the RA,Dec coordinates of each moon to Az,Alt
55      *
56      * @param LSTh pointer to the current local sidereal time
57      * @param lat pointer to the geographic latitude
58      */
59     void EquatorialToHorizontal(const dms *LSTh, const dms *lat);
60 
61     /**
62      * @short Find the positions of each Moon, relative to the planet.
63      *
64      * We use an XYZ coordinate system, centered on the planet,
65      * where the X-axis corresponds to the planet's Equator,
66      * the Y-Axis is parallel to the planet's Poles, and the
67      * Z-axis points along the line joining the Earth and
68      * the planet. Once the XYZ positions are known, this
69      * function also computes the RA, Dec positions of each
70      * Moon, and sets the inFront bool variable to indicate
71      * whether the Moon is nearer to us than the planet or not
72      * (this information is used to determine whether the
73      * Moon should be drawn on top of the planet, or vice versa).
74      *
75      * @param num pointer to the KSNumbers object describing
76      * the date/time at which to find the positions.
77      * @param pla pointer to the planet object
78      * @param sunptr pointer to the Sun object
79      */
80     virtual void findPosition(const KSNumbers *num, const KSPlanetBase *pla, const KSSun *sunptr) = 0;
81 
82     /**
83      * @return true if the Moon is nearer to Earth than Saturn.
84      * @param id which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
85      */
inFront(int id)86     inline bool inFront(int id) const { return InFront[id]; }
87 
88     /**
89      * @return the X-coordinate in the planet-centered coord. system.
90      * @param i which moon?
91      */
x(int i)92     double x(int i) const { return XP[i]; }
93 
94     /**
95      * @return the Y-coordinate in the planet-centered coord. system.
96      * @param i which moon?
97      */
y(int i)98     double y(int i) const { return YP[i]; }
99 
100     /**
101      * @return the Z-coordinate in the Planet-centered coord. system.
102      * @param i which moon?
103      */
z(int i)104     double z(int i) const { return ZP[i]; }
105 
106     /** @return the number of moons around the planet */
nMoons()107     int nMoons() const { return Moon.size(); }
108 
109   protected:
110     QVector<TrailObject *> Moon;
111     QVector<bool> InFront;
112     //the rectangular position, relative to the planet. X-axis is equator of the planet; units are planet Radius
113     QVector<double> XP, YP, ZP;
114 
115   private:
116     PlanetMoons(const PlanetMoons &);
117     PlanetMoons &operator=(const PlanetMoons &);
118 };
119