• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 6108416385

07 Sep 2023 10:14AM UTC coverage: 11.858%. Remained the same
6108416385

push

github

alex-w
Fix proper motion

1 of 1 new or added line in 1 file covered. (100.0%)

14815 of 124937 relevant lines covered (11.86%)

21627.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.66
/plugins/MissingStars/src/MissingStar.cpp
1
/*
2
 * Copyright (C) 2023 Alexander Wolf
3
 *
4
 * This program is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU General Public License
6
 * as published by the Free Software Foundation; either version 2
7
 * of the License, or (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
17
 */
18

19
#include "MissingStar.hpp"
20
#include "StelObject.hpp"
21
#include "StelPainter.hpp"
22
#include "StelApp.hpp"
23
#include "StelCore.hpp"
24
#include "StelUtils.hpp"
25
#include "StelTranslator.hpp"
26
#include "StelModuleMgr.hpp"
27
#include "StelSkyDrawer.hpp"
28
#include "StelLocaleMgr.hpp"
29
#include "Planet.hpp"
30

31
#include <QTextStream>
32
#include <QDebug>
33
#include <QVariant>
34
#include <QVariantMap>
35
#include <QVariant>
36
#include <QList>
37

38
const QString MissingStar::MISSINGSTAR_TYPE = QStringLiteral("MissingStar");
15✔
39
bool MissingStar::flagShowLabels = true;
40

41
MissingStar::MissingStar(const QVariantMap& map)
×
42
        : initialized(false)
×
43
        , designation("")
×
44
        , RA(0.)
×
45
        , DEC(0.)
×
46
        , pmRA(0.f)
×
47
        , pmDEC(0.f)
×
48
        , bMag(-99.f)
×
49
        , vMag(-99.f)
×
50
        , parallax(0.f)
×
51
        , parallaxErr(0.f)
×
52
        , spType("")
×
53
        , bvFlag(false)
×
54
{
55
        if (!map.contains("designation") || !map.contains("RA") || !map.contains("DEC") || !map.contains("vMag"))
×
56
        {
57
                qWarning() << "MissingStar: INVALID star!" << map.value("designation").toString();
×
58
                return;
×
59
        }
60

61
        designation = map.value("designation").toString();
×
62
        RA          = StelUtils::getDecAngle(map.value("RA").toString());
×
63
        DEC         = StelUtils::getDecAngle(map.value("DEC").toString());
×
64
        pmRA        = map.value("pmRA", 0.f).toFloat();
×
65
        pmDEC       = map.value("pmDEC", 0.f).toFloat();
×
66
        bMag        = map.value("bMag", -99.f).toFloat();
×
67
        vMag        = map.value("vMag", -99.f).toFloat();
×
68
        parallax    = map.value("parallax", 0.f).toFloat();
×
69
        parallaxErr = map.value("parallaxErr", 0.f).toFloat();
×
70
        spType      = map.value("SpType", "").toString();
×
71

72
        double b_v = 0.;
×
73
        if (bMag>-99.f && vMag>-99.f)
×
74
        {
75
                b_v = (bMag-vMag)*1000.0;
×
76
                if (b_v < -500.) {
×
77
                        b_v = -500.;
×
78
                } else if (b_v > 3499.) {
×
79
                        b_v = 3499.;
×
80
                }
81
                bvFlag = true;
×
82
        }
83
        colorIndex = (unsigned int)floor(0.5+127.0*((500.0+b_v)/4000.0));
×
84

85
        initialized = true;
×
86
}
×
87

88
MissingStar::~MissingStar()
×
89
{
90
        //
91
}
×
92

93
QVariantMap MissingStar::getMap(void) const
×
94
{
95
        const QVariantMap map = {
96
                {"designation", designation},
×
97
                {"RA", RA},
×
98
                {"DEC", DEC},
×
99
                {"pmRA", pmRA},
×
100
                {"pmDEC", pmDEC},
×
101
                {"bMag", bMag},
×
102
                {"vMag", vMag},
×
103
                {"parallax", parallax},
×
104
                {"parallaxErr", parallaxErr},
×
105
                {"SpType", spType}
×
106
        };
×
107

108
        return map;
×
109
}
110

111
QString MissingStar::getNameI18n(void) const
×
112
{
113
        return designation;
×
114
}
115

116
QString MissingStar::getEnglishName(void) const
×
117
{
118
        return designation;
×
119
}
120

121
QString MissingStar::getInfoString(const StelCore* core, const InfoStringGroup& flags) const
×
122
{
123
        QString str;
×
124
        QTextStream oss(&str);
×
125

126
        if (flags&Name)
×
127
                oss << "<h2>" << getNameI18n() << "</h2>";
×
128

129
        if (flags&ObjectType)
×
130
                oss << QString("%1: <b>%2</b>").arg(q_("Type"), getObjectTypeI18n()) << "<br />";
×
131

132
        if (flags&Magnitude)
×
133
                oss << getMagnitudeInfoString(core, flags, 2);
×
134

135
        if (flags&AbsoluteMagnitude)
×
136
        {
137
                if (parallax>0.f)
×
138
                        oss << QString("%1: %2").arg(q_("Absolute Magnitude")).arg(getVMagnitude(core)+5.*(1.+std::log10(0.001*parallax)), 0, 'f', 2) << "<br />";
×
139
                oss << getExtraInfoStrings(AbsoluteMagnitude).join("");
×
140
        }
141

142
        if (flags&Extra && bvFlag)
×
143
                oss << QString("%1: <b>%2</b>").arg(q_("Color Index (B-V)"), QString::number(bMag-vMag, 'f', 2)) << "<br />";
×
144

145
        // Ra/Dec etc.
146
        oss << getCommonInfoString(core, flags);
×
147

148
        if (flags&Distance)
×
149
        {
150
                if (parallax>0.f)
×
151
                {
152
                        //TRANSLATORS: Unit of measure for distance - Light Years
153
                        QString ly = qc_("ly", "distance");
×
154
                        double k = AU/(SPEED_OF_LIGHT*86400*365.25);
×
155
                        double d = ((0.001/3600.)*(M_PI/180));
×
156
                        double distance = k/(parallax*d);
×
157
                        if (parallaxErr>0.f && parallax>parallaxErr) // No distance when error of parallax is bigger than parallax!
×
158
                                oss << QString("%1: %2%3%4 %5").arg(q_("Distance"), QString::number(distance, 'f', 2), QChar(0x00B1), QString::number(qAbs(k/((parallaxErr + parallax)*d) - distance), 'f', 2), ly) << "<br />";
×
159
                        else
160
                                oss << QString("%1: %2 %3").arg(q_("Distance"), QString::number(distance, 'f', 2), ly) << "<br />";
×
161
                }
×
162
                oss << getExtraInfoStrings(Distance).join("");
×
163
        }
164

165
        if (flags&ProperMotion && (pmRA!=0.0 && pmDEC!=0.0))
×
166
        {
167
                double pa = std::atan2(pmRA, pmDEC)*M_180_PI;
×
168
                if (pa<0)
×
169
                        pa += 360.;
×
170
                oss << QString("%1: %2 %3 %4 %5&deg;<br />").arg(q_("Proper motion"),
×
171
                               QString::number(std::sqrt(pmRA*pmRA + pmDEC*pmDEC), 'f', 1), qc_("mas/yr", "milliarc second per year"),
×
172
                               qc_("towards", "into the direction of"), QString::number(pa, 'f', 1));
×
173
                oss << QString("%1: %2 %3 (%4)<br />").arg(q_("Proper motions by axes"), QString::number(pmRA, 'f', 1), QString::number(pmDEC, 'f', 1), qc_("mas/yr", "milliarc second per year"));
×
174
        }
175

176
        if (flags&Extra)
×
177
        {
178
                if (parallax>0.f)
×
179
                {
180
                        QString plx = q_("Parallax");
×
181
                        if (parallaxErr>0.f)
×
182
                                oss <<  QString("%1: %2%3%4 ").arg(plx, QString::number(parallax, 'f', 3), QChar(0x00B1), QString::number(parallaxErr, 'f', 3));
×
183
                        else
184
                                oss << QString("%1: %2 ").arg(plx, QString::number(parallax, 'f', 3));
×
185
                        oss  << qc_("mas", "parallax") << "<br />";
×
186
                }
×
187

188
                if (!spType.isEmpty())
×
189
                        oss << QString("%1: %2").arg(q_("Spectral Type"), spType) << "<br />";
×
190
        }
191

192
        oss << getSolarLunarInfoString(core, flags);
×
193
        postProcessInfoString(str, flags);
×
194
        return str;
×
195
}
×
196

197
float MissingStar::getVMagnitude(const StelCore* core) const
×
198
{
199
        Q_UNUSED(core)
200
        return vMag;
×
201
}
202

203
Vec3f MissingStar::getInfoColor(void) const
×
204
{
205
        return StelSkyDrawer::indexToColor(colorIndex);
×
206
}
207

208
void MissingStar::draw(StelCore* core, StelPainter *painter)
×
209
{
210
        Vec3d pos = getJ2000EquatorialPos(core);
×
211
        Vec3d win;
×
212
        // Check visibility of missing star
213
        if(!(painter->getProjector()->projectCheck(pos, win)))
×
214
                return;
×
215

216
        StelSkyDrawer* sd = core->getSkyDrawer();
×
217
        const float mlimit = sd->getLimitMagnitude();
×
218
        const bool mflag = sd->getFlagStarMagnitudeLimit();
×
219
        const float mag = getVMagnitudeWithExtinction(core);
×
220
        const float shift = 8.f;
×
221

222
        bool visibleStar = (mag <= mlimit);
×
223
        bool visibleHint = ((mag+5.f)<mlimit);
×
224
        if (mflag)
×
225
        {
226
                // custom magnitude limit for stars
227
                const double hmlimit = sd->getCustomStarMagnitudeLimit();
×
228
                visibleStar = (mag <= hmlimit);
×
229
                visibleHint = ((mag+5.f)<hmlimit);
×
230
        }
231
        
232
        if (visibleStar)
×
233
        {
234
                const Vec3f color = getInfoColor();
×
235
                Vec3f vf(pos.toVec3f());
×
236
                Vec3f altAz(vf);
×
237
                altAz.normalize();
×
238
                core->j2000ToAltAzInPlaceNoRefraction(&altAz);
×
239
                RCMag rcMag;
240
                sd->computeRCMag(mag, &rcMag);
×
241
                sd->preDrawPointSource(painter);
×
242
                // allow height-dependent twinkle and suppress twinkling in higher altitudes. Keep 0.1 twinkle amount in zenith.
243
                sd->drawPointSource(painter, vf.toVec3d(), rcMag, color, true, qMin(1.0f, 1.0f-0.9f*altAz[2]));
×
244
                sd->postDrawPointSource(painter);
×
245
                painter->setColor(color, 1.f);
×
246
                if (flagShowLabels && visibleHint)
×
247
                        painter->drawText(pos, designation, 0, shift, shift, false);
×
248
        }        
249
}
250

251
Vec3d MissingStar::getJ2000EquatorialPos(const StelCore* core) const
×
252
{
253
        Vec3d v;
×
254
        static const double d2000 = 2451545.0;
255
        const double movementFactor = (M_PI/180.)*(0.0001/3600.) * (core->getJDE()-d2000)/365.25;
×
256
        const double cRA = RA + movementFactor*pmRA/::cos(DEC*M_180_PI);
×
257
        const double cDE = DEC + movementFactor*pmDEC;
×
258
        StelUtils::spheToRect(cRA, cDE, v);
×
259

260
        //StelUtils::spheToRect(RA, DEC, v);
261

262
        if ((core) && (core->getUseAberration()) && (core->getCurrentPlanet()))
×
263
        {
264
                Vec3d vel=core->getCurrentPlanet()->getHeliocentricEclipticVelocity();
×
265
                vel=StelCore::matVsop87ToJ2000*vel*core->getAberrationFactor()*(AU/(86400.0*SPEED_OF_LIGHT));
×
266
                Vec3d pos=v+vel;
×
267
                pos.normalize();
×
268
                return pos;
×
269
        }
270
        else
271
                return v;
×
272
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc