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

Stellarium / stellarium / 15291801018

28 May 2025 04:52AM UTC coverage: 11.931% (-0.02%) from 11.951%
15291801018

push

github

alex-w
Added new set of navigational stars (XIX century)

0 of 6 new or added lines in 2 files covered. (0.0%)

14124 existing lines in 74 files now uncovered.

14635 of 122664 relevant lines covered (11.93%)

18291.42 hits per line

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

0.0
/src/core/StelHealpix.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2017 Guillaume Chereau
4
 * Copyright (C) 2024 Henry Leung
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 */
20

21
#include "StelHealpix.hpp"
22
#include <cmath>
23

24
// Position of the healpix faces.
25
static const int FACES[12][2] = {{1,  0}, {3,  0}, {5,  0}, {7,  0},
26
                                 {0, -1}, {2, -1}, {4, -1}, {6, -1},
27
                                 {1, -2}, {3, -2}, {5, -2}, {7, -2}};
28

29
// Position for poles
30
double healpix_sigma(double z)
×
31
{
32
    if (z < 0)
×
33
    {
34
        return -healpix_sigma(-z);
×
35
    }
36
    else
37
    {
38
        return 2 - sqrt(3 * (1 - z));
×
39
    }
40
}
41

42
double healpix_clip(double Z, double A, double B)
×
43
{
44
    if (Z < A)
×
45
    {
46
        return A;
×
47
    }
48
    else if (Z > B)
×
49
    {
50
        return B;
×
51
    }
52
    else
53
    {
54
        return Z;
×
55
    }
56
}
57

58
double healpix_wrap(double A, double B)
×
59
{
60
    if (A < 0)
×
61
    {
62
        return B - fmod(-A, B);
×
63
    }
64
    else
65
    {
66
        return fmod(A, B);
×
67
    }
68
}
69

70
int healpix_xyf2nest(int nside, int ix, int iy, int face_num)
×
71
{
72
  return (face_num*nside*nside) +
×
73
      (utab[ix&0xff] | (utab[ix>>8]<<16)
×
74
    | (utab[iy&0xff]<<1) | (utab[iy>>8]<<17));
×
75
}
76

77
static void nest2xyf(int nside, int pix, int *ix, int *iy, int *face_num)
×
78
{
79
    int npface_ = nside * nside, raw;
×
80
    *face_num = pix / npface_;
×
81
    pix &= (npface_ - 1);
×
82
    raw = (pix & 0x5555) | ((pix & 0x55550000) >> 15);
×
83
    *ix = ctab[raw & 0xff] | (ctab[raw >> 8] << 4);
×
84
    pix >>= 1;
×
85
    raw = (pix & 0x5555) | ((pix & 0x55550000) >> 15);
×
86
    *iy = ctab[raw & 0xff] | (ctab[raw >> 8] << 4);
×
87
}
×
88

89
// Create a 3x3 mat that transforms uv texture position to healpix xy
90
// coordinates.
91
void healpix_get_mat3(int nside, int pix, double out[3][3])
×
92
{
93
    int ix, iy, face;
94
    nest2xyf(nside, pix, &ix, &iy, &face);
×
95
    out[0][0] = +M_PI / 4 / nside;
×
96
    out[0][1] = +M_PI / 4 / nside;
×
97
    out[0][2] = 0;
×
98
    out[1][0] = -M_PI / 4 / nside;
×
99
    out[1][1] = +M_PI / 4 / nside;
×
100
    out[1][2] = 0;
×
101
    out[2][0] = (FACES[face][0] + (ix - iy + 0.0) / nside) * M_PI / 4;
×
102
    out[2][1] = (FACES[face][1] + (ix + iy + 0.0) / nside) * M_PI / 4;
×
103
    out[2][2] = 1;
×
104
}
×
105

106
static void healpix_xy2_z_phi(const double xy[2], double *z, double *phi)
×
107
{
108
    double x = xy[0], y = xy[1];
×
109

UNCOV
110
    if (fabs(y) > M_PI / 4) {
×
111
        // Polar
UNCOV
112
        double sigma = 2 - fabs(y * 4) / M_PI;
×
113
        *z = (y > 0 ? 1 : -1) * (1 - sigma * sigma / 3);
×
114
        double xc = -M_PI + (2 * std::floor((x + M_PI) * 4 / (2 * M_PI)) + 1) * M_PI / 4;
×
115
        *phi = sigma ? (xc + (x - xc) / sigma) : x;
×
116
    } else {
117
        // Equatorial
UNCOV
118
        *phi = x;
×
119
        *z = y * 8 / (M_PI * 3);
×
120
    }
UNCOV
121
}
×
122

UNCOV
123
void healpix_xy2ang(const double xy[2], double *theta, double *phi)
×
124
{
125
    double z;
UNCOV
126
    healpix_xy2_z_phi(xy, &z, phi);
×
127
    *theta = acos(z);
×
128
}
×
129

UNCOV
130
void healpix_xy2vec(const double xy[2], double out[3])
×
131
{
132
    double z, phi, stheta;
UNCOV
133
    healpix_xy2_z_phi(xy, &z, &phi);
×
134
    stheta = sqrt((1 - z) * (1 + z));
×
135
    out[0] = stheta * cos(phi);
×
136
    out[1] = stheta * sin(phi);
×
137
    out[2] = z;
×
138
}
×
139

UNCOV
140
void healpix_pix2vec(int nside, int pix, double out[3])
×
141
{
142
    int ix, iy, face;
143
    double xy[2];
UNCOV
144
    nest2xyf(nside, pix, &ix, &iy, &face);
×
145
    xy[0] = (FACES[face][0] + (ix - iy + 0.0) / nside) * M_PI / 4;
×
146
    xy[1] = (FACES[face][1] + (ix + iy + 1.0) / nside) * M_PI / 4;
×
147
    healpix_xy2vec(xy, out);
×
148
}
×
149

UNCOV
150
void healpix_pix2ang(int nside, int pix, double *theta, double *phi)
×
151
{
152
    int ix, iy, face;
153
    double xy[2];
UNCOV
154
    nest2xyf(nside, pix, &ix, &iy, &face);
×
155
    xy[0] = (FACES[face][0] + (ix - iy + 0.0) / nside) * M_PI / 4;
×
156
    xy[1] = (FACES[face][1] + (ix + iy + 1.0) / nside) * M_PI / 4;
×
157
    healpix_xy2ang(xy, theta, phi);
×
158
}
×
159

160
// HEALPix spherical projection
UNCOV
161
void za2tu(double z, double a, double *t, double *u)
×
162
{
UNCOV
163
    if (fabs(z) <= 2. / 3.)
×
164
    // equator
165
    {
UNCOV
166
        *t = a;
×
167
        *u = 3 * (M_PI / 8.) * z;
×
168
    }
169
    else
170
    // north/south poles
171
    {
172
        double sigma_z;
UNCOV
173
        sigma_z = healpix_sigma(z);
×
174
        *t = a - (fabs(sigma_z) - 1) * (fmod(a, M_PI / 2.) - (M_PI / 4.));
×
175
        *u = (M_PI / 4.) * sigma_z;
×
176
    }
UNCOV
177
}
×
178

179
// spherical projection to base pixel index
180
// f: base pixel index
181
// p: coord in north east axis of base pixel
182
// q: coord in north west axis of base pixel
UNCOV
183
void tu2fpq(double t, double u, long long int *f, double *p, double *q)
×
184
{
UNCOV
185
    t /= (M_PI / 4.);
×
UNCOV
186
    u /= (M_PI / 4.);
×
UNCOV
187
    t = healpix_wrap(t, 8.);
×
UNCOV
188
    t += -4.;
×
UNCOV
189
    u += 5.;
×
UNCOV
190
    const double pp = healpix_clip((u + t) / 2., 0., 5.);
×
191
    const int PP = floor(pp);
×
192
    const double qq = healpix_clip((u - t) / 2., 3. - PP, 6. - PP);
×
193
    const int QQ = floor(qq);
×
194
    const int V = 5 - (PP + QQ);
×
195
    if (V < 0)
×
196
    { // clip
197
        *f = 0;
×
198
        *p = 1.;
×
199
        *q = 1.;
×
200
    }
201
    else
202
    {
203
        *f = 4 * V + fmod(((PP - QQ + 4) >> 1), 4.);
×
204
        *p = fmod(pp, 1);
×
205
        *q = fmod(qq, 1);
×
206
    }
UNCOV
207
}
×
208

209
void tu2fxy(int nside, double t, double u, long long int *f, long long int *x, long long int *y)
×
210
{
211
    double p;
212
    double q;
213
    tu2fpq(t, u, f, &p, &q);
×
UNCOV
214
    *x = healpix_clip(floor(nside * p), 0, nside - 1);
×
215
    *y = healpix_clip(floor(nside * q), 0, nside - 1);
×
UNCOV
216
}
×
217

UNCOV
218
long long int za2pix_nest(int nside, double z, double a)
×
219
{
220
    double t;
221
    double u;
222
    long long int f;
223
    long long int x;
224
    long long int y;
UNCOV
225
    za2tu(z, a, &t, &u);
×
UNCOV
226
    tu2fxy(nside, t, u, &f, &x, &y);
×
UNCOV
227
    return healpix_xyf2nest(nside, x, y, f);
×
228
}
229

UNCOV
230
long long int healpix_ang2pix_nest(int nside, double theta, double phi)
×
231
{
232
    double z;
233
    // normalize coords
UNCOV
234
    z = cos(theta);
×
235

236
    return za2pix_nest(nside, z, phi);
×
237
}
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