Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _transit(lon1, lon2):
"""Count crossings of prime meridian for AddPoint."""
# Return 1 or -1 if crossing prime meridian in east or west direction.
# Otherwise return zero.
# Compute lon12 the same way as Geodesic::Inverse.
lon1 = Math.AngNormalize(lon1)
lon2 = Math.AngNormalize(lon2)
lon12, _ = Math.AngDiff(lon1, lon2)
cross = (1 if lon1 <= 0 and lon2 > 0 and lon12 > 0
else (-1 if lon2 <= 0 and lon1 > 0 and lon12 < 0 else 0))
return cross
_transit = staticmethod(_transit)
def _transit(lon1, lon2):
"""Count crossings of prime meridian for AddPoint."""
# Return 1 or -1 if crossing prime meridian in east or west direction.
# Otherwise return zero.
# Compute lon12 the same way as Geodesic::Inverse.
lon1 = Math.AngNormalize(lon1)
lon2 = Math.AngNormalize(lon2)
lon12, _ = Math.AngDiff(lon1, lon2)
cross = (1 if lon1 <= 0 and lon2 > 0 and lon12 > 0
else (-1 if lon2 <= 0 and lon1 > 0 and lon12 < 0 else 0))
return cross
_transit = staticmethod(_transit)
def GenInverse(self, lat1, lon1, lat2, lon2, outmask):
"""Private: General version of the inverse problem"""
a12 = s12 = azi1 = azi2 = m12 = M12 = M21 = S12 = Math.nan # return vals
outmask &= Geodesic.OUT_ALL
# Compute longitude difference (AngDiff does this carefully). Result is
# in [-180, 180] but -180 is only for west-going geodesics. 180 is for
# east-going and meridional geodesics.
lon12 = Math.AngDiff(Math.AngNormalize(lon1), Math.AngNormalize(lon2))
# If very close to being on the same half-meridian, then make it so.
lon12 = Geodesic.AngRound(lon12)
# Make longitude difference positive.
lonsign = 1 if lon12 >= 0 else -1
lon12 *= lonsign
# If really close to the equator, treat as on equator.
lat1 = Geodesic.AngRound(lat1)
lat2 = Geodesic.AngRound(lat2)
# Swap points so that point with higher (abs) latitude is point 1
swapp = 1 if abs(lat1) >= abs(lat2) else -1
if swapp < 0:
lonsign *= -1
lat2, lat1 = lat1, lat2
# Make lat1 <= 0
latsign = 1 if lat1 < 0 else -1
lat1 *= latsign
def _GenInverse(self, lat1, lon1, lat2, lon2, outmask):
"""Private: General version of the inverse problem"""
a12 = s12 = m12 = M12 = M21 = S12 = Math.nan # return vals
outmask &= Geodesic.OUT_MASK
# Compute longitude difference (AngDiff does this carefully). Result is
# in [-180, 180] but -180 is only for west-going geodesics. 180 is for
# east-going and meridional geodesics.
lon12, lon12s = Math.AngDiff(lon1, lon2)
# Make longitude difference positive.
lonsign = 1 if lon12 >= 0 else -1
# If very close to being on the same half-meridian, then make it so.
lon12 = lonsign * Math.AngRound(lon12)
lon12s = Math.AngRound((180 - lon12) - lonsign * lon12s)
lam12 = math.radians(lon12)
if lon12 > 90:
slam12, clam12 = Math.sincosd(lon12s); clam12 = -clam12
else:
slam12, clam12 = Math.sincosd(lon12)
# If really close to the equator, treat as on equator.
lat1 = Math.AngRound(Math.LatFix(lat1))
lat2 = Math.AngRound(Math.LatFix(lat2))
# Swap points so that point with higher (abs) latitude is point 1
# If one latitude is a nan, then it becomes lat1.
:param lon2: longitude of the second point in degrees
:param outmask: the :ref:`output mask `
:return: a :ref:`dict`
Compute geodesic between (*lat1*, *lon1*) and (*lat2*, *lon2*).
The default value of *outmask* is STANDARD, i.e., the *lat1*,
*lon1*, *azi1*, *lat2*, *lon2*, *azi2*, *s12*, *a12* entries are
returned.
"""
a12, s12, salp1,calp1, salp2,calp2, m12, M12, M21, S12 = self._GenInverse(
lat1, lon1, lat2, lon2, outmask)
outmask &= Geodesic.OUT_MASK
if outmask & Geodesic.LONG_UNROLL:
lon12, e = Math.AngDiff(lon1, lon2)
lon2 = (lon1 + lon12) + e
else:
lon2 = Math.AngNormalize(lon2)
result = {'lat1': Math.LatFix(lat1),
'lon1': lon1 if outmask & Geodesic.LONG_UNROLL else
Math.AngNormalize(lon1),
'lat2': Math.LatFix(lat2),
'lon2': lon2}
result['a12'] = a12
if outmask & Geodesic.DISTANCE: result['s12'] = s12
if outmask & Geodesic.AZIMUTH:
result['azi1'] = Math.atan2d(salp1, calp1)
result['azi2'] = Math.atan2d(salp2, calp2)
if outmask & Geodesic.REDUCEDLENGTH: result['m12'] = m12
if outmask & Geodesic.GEODESICSCALE:
result['M12'] = M12; result['M21'] = M21
def _GenInverse(self, lat1, lon1, lat2, lon2, outmask):
"""Private: General version of the inverse problem"""
a12 = s12 = m12 = M12 = M21 = S12 = Math.nan # return vals
outmask &= Geodesic.OUT_MASK
# Compute longitude difference (AngDiff does this carefully). Result is
# in [-180, 180] but -180 is only for west-going geodesics. 180 is for
# east-going and meridional geodesics.
lon12, lon12s = Math.AngDiff(lon1, lon2)
# Make longitude difference positive.
lonsign = 1 if lon12 >= 0 else -1
# If very close to being on the same half-meridian, then make it so.
lon12 = lonsign * Math.AngRound(lon12)
lon12s = Math.AngRound((180 - lon12) - lonsign * lon12s)
lam12 = math.radians(lon12)
if lon12 > 90:
slam12, clam12 = Math.sincosd(lon12s); clam12 = -clam12
else:
slam12, clam12 = Math.sincosd(lon12)
# If really close to the equator, treat as on equator.
lat1 = Math.AngRound(Math.LatFix(lat1))
lat2 = Math.AngRound(Math.LatFix(lat2))
# Swap points so that point with higher (abs) latitude is point 1
# If one latitude is a nan, then it becomes lat1.