Skip to content

Commit c96f551

Browse files
committed
track2() coerce asarray required for clarity
1 parent aedfc07 commit c96f551

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/pymap3d/tests/test_vincenty.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
import pytest
44
from pytest import approx
55

6+
from math import radians
7+
68

79
@pytest.mark.parametrize("deg", [True, False])
810
def test_track2_unit(deg):
911
np = pytest.importorskip("numpy")
1012

1113
lat1, lon1 = 0.0, 80.0
1214
lat2, lon2 = 0.0, 81.0
13-
lat0 = np.array([0.0, 0.0, 0.0, 0.0])
14-
lon0 = np.array([80.0, 80.33333, 80.66666, 81.0])
15+
lat0 = [0.0, 0.0, 0.0, 0.0]
16+
lon0 = [80.0, 80.33333, 80.66666, 81.0]
1517
if not deg:
16-
lat1, lon1, lat2, lon2 = np.radians((lat1, lon1, lat2, lon2))
17-
lat0 = np.radians(lat0)
18-
lon0 = np.radians(lon0)
18+
lat1 = radians(lat1)
19+
lon1 = radians(lon1)
20+
lat2 = radians(lat2)
21+
lon2 = radians(lon2)
22+
lon0 = list(map(radians, lon0))
1923

2024
lats, lons = vincenty.track2(lat1, lon1, lat2, lon2, npts=4, deg=deg)
2125

src/pymap3d/vincenty.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66

77
import warnings
88

9-
from ._typing import FloatArray, FloatLike
109
import logging
1110
from copy import copy
1211

1312
from .ellipsoid import Ellipsoid, resolve_ellipsoid
1413
from .mathfun import isnan, linspace, degrees, radians, sign, sqrt, atan2, cos, sin, tan, asin, atan
1514
from math import pi, tau, nan
1615

16+
try:
17+
from numpy import asarray
18+
except ImportError:
19+
pass
20+
21+
1722
__all__ = ["vdist", "vreckon", "track2"]
1823

1924

@@ -447,7 +452,8 @@ def track2(
447452
deg: bool = True,
448453
) -> tuple:
449454
"""
450-
computes great circle tracks starting at the point lat1, lon1 and ending at lat2, lon2
455+
computes great circle tracks starting at the point lat1, lon1 and ending at lat2, lon2.
456+
track2() REQUIRES NumPy.
451457
452458
Parameters
453459
----------
@@ -501,7 +507,7 @@ def track2(
501507
distance, azimuth = vdist(lat1, lon1, lat2, lon2, ell, deg=False)
502508
dists = linspace(0, distance, npts)
503509

504-
lats, lons = vreckon(lat1, lon1, dists, azimuth, ell, deg=False)
510+
lats, lons = vreckon(lat1, lon1, asarray(dists), azimuth, ell, deg=False)
505511

506512
if deg:
507513
lats = degrees(lats)

0 commit comments

Comments
 (0)