Skip to content

Commit 03f9e8c

Browse files
authored
Add checks for θ in ang2pix* functions (#84)
* Add checks for θ in ang2pix* functions * Update CHANGELOG
1 parent 08b5f2d commit 03f9e8c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# HEAD
22

3+
- Add checks for colatitude θ in functions that take angles as input [#84](https://github.com/ziotom78/Healpix.jl/pull/84)
4+
35
# Version 4.0.0
46

57
- **Breaking change**: `udgrade` now always assumes `pess = false` [#72](https://github.com/ziotom78/Healpix.jl/pull/72)

src/pixelfunc.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ pixel indexes are 1-based (this is Julia)!
150150
"""
151151
function ang2pixNest(resol::Resolution, theta, phi)
152152

153+
(0 theta π) || throw(DomainError(theta, "Invalid value of theta"))
154+
153155
nside = resol.nside
154156
local ix, iy, face_num
155157

@@ -284,6 +286,8 @@ indexes are 1-based (this is Julia)!
284286
"""
285287
function ang2pixRing(resol::Resolution, theta, phi)
286288

289+
(0 theta π) || throw(DomainError(theta, "Invalid value of theta"))
290+
287291
z = cos(theta)
288292
z_abs = abs(z)
289293

test/test_pixelfunctions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ x, y, z = Healpix.ang2vec(0.637907993514304, 4.877925523463614)
5050
@test y -0.587375491097860 atol = eps
5151
@test z 0.803343338527719 atol = eps
5252

53+
@test_throws DomainError(-1.0, "Invalid value of theta") Healpix.ang2vec(-1.0, 0.0)
54+
@test_throws DomainError(4.0, "Invalid value of theta") Healpix.ang2vec(4.0, 0.0)
55+
5356
# vec2ang
5457

5558
theta, phi = Healpix.vec2ang(2.479973695958578, 2.540405094768749, 1.360043653263107)
@@ -148,6 +151,8 @@ highresol = Healpix.Resolution(2^29)
148151
@test Healpix.ang2pixNest(resol, 3.1415926535897931, 5.0265482457436690) == 720897
149152
@test Healpix.ang2pixNest(resol, 3.1415926535897931, 6.2831853071795862) == 720897
150153

154+
@test_throws DomainError(-1.0, "Invalid value of theta") Healpix.ang2pixNest(resol, -1.0, 0.0)
155+
@test_throws DomainError(4.0, "Invalid value of theta") Healpix.ang2pixNest(resol, 4.0, 0.0)
151156

152157
@test Healpix.ang2pixNest(highresol, 1.570796325553133199, 0.785398163397448279) == 1
153158
@test Healpix.ang2pixNest(highresol, 1.570796324311369840, 0.785398164860366288) == 2
@@ -239,6 +244,9 @@ highresol = Healpix.Resolution(2^29)
239244
@test Healpix.ang2pixRing(resol, 3.1415926535897931, 5.0265482457436690) == 786432
240245
@test Healpix.ang2pixRing(resol, 3.1415926535897931, 6.2831853071795862) == 786429
241246

247+
@test_throws DomainError(-1.0, "Invalid value of theta") Healpix.ang2pixNest(resol, -1.0, 0.0)
248+
@test_throws DomainError(4.0, "Invalid value of theta") Healpix.ang2pixNest(resol, 4.0, 0.0)
249+
242250
@test Healpix.ang2pixRing(highresol, 0.000000001520843396, 0.785398163397448279) == 1
243251
@test Healpix.ang2pixRing(highresol, 0.000000001520843396, 2.356194490192344837) == 2
244252
@test Healpix.ang2pixRing(highresol, 0.000000001520843396, 3.926990816987241395) == 3

0 commit comments

Comments
 (0)