Skip to content

Commit dbdb697

Browse files
committed
loxodrome_inverse: correct singularity handling
1 parent 8f21a46 commit dbdb697

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/pymap3d/latitude.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ def geodetic2isometric(
209209
# isometric_lat = log(tan(a2)) + e/2 * log((1-e*sin(geodetic_lat)) / (1+e*sin(geodetic_lat)))
210210

211211
try:
212-
isometric_lat[abs(geodetic_lat - pi / 2) <= 1e-9] = inf
213-
isometric_lat[abs(-geodetic_lat - pi / 2) <= 1e-9] = -inf
212+
isometric_lat[abs(geodetic_lat - pi / 2) <= 1e-9] = inf # type: ignore
213+
isometric_lat[abs(-geodetic_lat - pi / 2) <= 1e-9] = -inf # type: ignore
214214
except TypeError:
215-
if abs(geodetic_lat - pi / 2) <= 1e-9:
215+
if abs(geodetic_lat - pi / 2) <= 1e-9: # type: ignore
216216
isometric_lat = inf
217-
elif abs(-geodetic_lat - pi / 2) <= 1e-9:
217+
elif abs(-geodetic_lat - pi / 2) <= 1e-9: # type: ignore
218218
isometric_lat = -inf
219219

220220
return degrees(isometric_lat) if deg else isometric_lat

src/pymap3d/lox.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def loxodrome_inverse(
9797
9898
like Matlab distance('rh',...) and azimuth('rh',...)
9999
100+
If any of inputs lat1,lon1,lat2,lon2 are arrays, all must be arrays of same shape
101+
100102
Parameters
101103
----------
102104
@@ -153,11 +155,11 @@ def loxodrome_inverse(
153155
dist = meridian_arc(lat2, lat1, deg=False, ell=ell) / aux
154156

155157
# straight east or west
158+
i = aux < 1e-9
156159
try:
157-
if (aux < 1e-9).any():
158-
dist[aux < 1e-9] = departure(lon2, lon1, lat1, ell, deg=False)
160+
dist[i] = departure(lon2[i], lon1[i], lat1[i], ell, deg=False)
159161
except (AttributeError, TypeError):
160-
if aux < 1e-9:
162+
if i:
161163
dist = departure(lon2, lon1, lat1, ell, deg=False)
162164

163165
if deg:
@@ -180,6 +182,8 @@ def loxodrome_direct(
180182
like Matlab reckon('rh', ...)
181183
except that "rng" in meters instead of "arclen" degrees of arc
182184
185+
If any of inputs lat,lon1,rng are arrays, all must be arrays of same shape
186+
183187
Parameters
184188
----------
185189
lat1 : float
@@ -231,7 +235,7 @@ def loxodrome_direct(
231235
iso = geodetic2isometric(lat1, ell, deg=False)
232236

233237
# stability near singularities
234-
i = abs(cos(a12)) < 1e-6
238+
i = abs(cos(a12)) < 1e-9
235239
dlon = tan(a12) * (newiso - iso)
236240

237241
try:

src/pymap3d/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def sanitize(
7171
lat = radians(lat)
7272

7373
if asarray is not None:
74-
if (abs(lat) > pi / 2).any():
74+
if (abs(lat) > pi / 2).any(): # type: ignore
7575
raise ValueError("-pi/2 <= latitude <= pi/2")
7676
else:
77-
if abs(lat) > pi / 2:
77+
if abs(lat) > pi / 2: # type: ignore
7878
raise ValueError("-pi/2 <= latitude <= pi/2")
7979

8080
return lat, ell

0 commit comments

Comments
 (0)