Coverage for pygeodesy/geodesicx/gxbases.py: 98%

40 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-04-21 13:14 -0400

1 

2# -*- coding: utf-8 -*- 

3 

4u'''(INTERNAL) Private L{geodesicx} base class, functions and constants. 

5 

6Copyright (C) U{Charles Karney<mailto:Charles@Karney.com>} (2008-2022) 

7and licensed under the MIT/X11 License. For more information, see the 

8U{GeographicLib<https://GeographicLib.SourceForge.io>} documentation. 

9''' 

10 

11# from pygeodesy.basics import isodd # from .karney 

12from pygeodesy.constants import _0_0, _2_0 

13from pygeodesy.errors import _not_, _or 

14# from pygeodesy.interns import _not_ # from .errors 

15from pygeodesy.karney import _CapsBase, GeodesicError, isodd, _hypot, _sum2_ 

16 

17from math import ldexp as _ldexp 

18 

19__all__ = () 

20__version__ = '23.03.25' 

21 

22# valid C{nC4}s and C{C4order}s, see _xnC4 below 

23_nC4s = {24: 2900, 27: 4032, 30: 5425} 

24 

25 

26class _GeodesicBase(_CapsBase): # in .geodsolve 

27 '''(INTERNAL) Base class for C{[_]Geodesic*Exact}. 

28 ''' 

29# def toRepr(self, prec=6, sep=_COMMASPACE_, **unused): # PYCHOK signature 

30# '''Return this C{GeodesicExact*} items string. 

31# 

32# @kwarg prec: The C{float} precision, number of decimal digits (0..9). 

33# Trailing zero decimals are stripped for B{C{prec}} values 

34# of 1 and above, but kept for negative B{C{prec}} values. 

35# @kwarg sep: Separator to join (C{str}). 

36# 

37# @return: C{GeodesicExact*} (C{str}). 

38# ''' 

39# return Fmt.PAREN(self.named, self.toStr(prec=prec, sep=sep)) 

40 pass 

41 

42 

43def _cosSeries(c4s, sx, cx): # PYCHOK shared .geodesicx.gx and -.gxline 

44 '''(INTERNAL) I{Karney}'s cosine series expansion using U{Clenshaw 

45 summation<https://WikiPedia.org/wiki/Clenshaw_algorithm>}. 

46 ''' 

47 ar = _2_0 * (cx - sx) * (cx + sx) # 2 * cos(2 * x) 

48 y0 = t0 = y1 = t1 = _0_0 

49 n = len(c4s) # c4s = list(c4s) 

50 if isodd(n): 

51 n -= 1 

52 y0 = c4s[n] # c4s.pop() 

53 _s2_ = _sum2_ 

54 for n in range(n - 1, 0, -2): # reversed 

55 # y1 = ar * y0 - y1 + c4s.pop() 

56 # y0 = ar * y1 - y0 + c4s.pop() 

57 y1, t1 = _s2_(ar * y0, ar * t0, -y1, -t1, c4s[n]) 

58 y0, t0 = _s2_(ar * y1, ar * t1, -y0, -t0, c4s[n - 1]) 

59 s, _ = _s2_(cx * y0, cx * t0, -cx * y1, -cx * t1) 

60 return s # cx * (y0 - y1) 

61 

62 

63_f = float # in _f2 and .geodesicx._C4_24, _27 and _30 

64 

65 

66def _f2(hi, lo): # in .geodesicx._C4_24, _27 and _30 

67 '''(INTERNAL) For C{_coeffs}. 

68 ''' 

69 return _ldexp(_f(hi), 52) + _f(lo) 

70 

71 

72def _sincos12(sin1, cos1, sin2, cos2, sineg0=False): # PYCHOK shared 

73 '''(INTERNAL) Compute the sine and cosine of angle 

74 M{ang12 = atan2(sin2, cos2) - atan2(sin1, cos1)}. 

75 

76 Use C{-sin1} to get C{sin12} and C{cos12} of the sum 

77 M{ang12 = atan2(sin2, cos2) + atan2(sin1, cos1)}. 

78 

79 @kwarg sineg0: If C{True}, make negative C{sin12} zero (C{bool}). 

80 

81 @return: 2-Tuple C{(sin12, cos12)}. 

82 ''' 

83 s = sin2 * cos1 - sin1 * cos2 

84 c = cos2 * cos1 + sin1 * sin2 

85 if sineg0 and s < 0: 

86 s = _0_0 # max(s, _0_0) or NEG0? 

87 return s, c 

88 

89 

90def _sin1cos2(sin1, cos1, sin2, cos2): # PYCHOK shared 

91 '''(INTERNAL) Compute the C{sin1 * cos2} sine and its cosine. 

92 

93 @return: 2-Tuple C{(sin1 * cos2, hypot(sin1 * sin2, cos1)}. 

94 ''' 

95 s = sin1 * cos2 

96 c = _hypot(sin1 * sin2, cos1) 

97 return s, c # _norm2(s, c) 

98 

99 

100def _xnC4(**name_nC4): 

101 '''(INTERNAL) Validate C{C4order}. 

102 ''' 

103 n, nC4 = name_nC4.popitem() 

104 if nC4 not in _nC4s or not isinstance(nC4, int): 

105 raise GeodesicError(n, nC4, txt=_not_(_or(*map(str, _nC4s)))) 

106 return _nC4s[nC4] 

107 

108 

109# **) MIT License 

110# 

111# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved. 

112# 

113# Permission is hereby granted, free of charge, to any person obtaining a 

114# copy of this software and associated documentation files (the "Software"), 

115# to deal in the Software without restriction, including without limitation 

116# the rights to use, copy, modify, merge, publish, distribute, sublicense, 

117# and/or sell copies of the Software, and to permit persons to whom the 

118# Software is furnished to do so, subject to the following conditions: 

119# 

120# The above copyright notice and this permission notice shall be included 

121# in all copies or substantial portions of the Software. 

122# 

123# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 

124# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

125# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 

126# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 

127# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 

128# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 

129# OTHER DEALINGS IN THE SOFTWARE.