Debian Codegraph @

third_party/spiro/curves/cornu.py

raw symbols SCIP
1 from math import *
2
3 # implementation adapted from cephes
4
5 def polevl(x, coef):
6 ans = coef[-1]
7 for i in range(len(coef) - 2, -1, -1):
8 ans = ans * x + coef[i]
9 return ans
10
11 sn = [
12 -2.99181919401019853726E3,
13 7.08840045257738576863E5,
14 -6.29741486205862506537E7,
15 2.54890880573376359104E9,
16 -4.42979518059697779103E10,
17 3.18016297876567817986E11
18 ]
19 sn.reverse()
20 sd = [
21 1.00000000000000000000E0,
22 2.81376268889994315696E2,
23 4.55847810806532581675E4,
24 5.17343888770096400730E6,
25 4.19320245898111231129E8,
26 2.24411795645340920940E10,
27 6.07366389490084639049E11
28 ]
29 sd.reverse()
30 cn = [
31 -4.98843114573573548651E-8,
32 9.50428062829859605134E-6,
33 -6.45191435683965050962E-4,
34 1.88843319396703850064E-2,
35 -2.05525900955013891793E-1,
36 9.99999999999999998822E-1
37 ]
38 cn.reverse()
39 cd = [
40 3.99982968972495980367E-12,
41 9.15439215774657478799E-10,
42 1.25001862479598821474E-7,
43 1.22262789024179030997E-5,
44 8.68029542941784300606E-4,
45 4.12142090722199792936E-2,
46 1.00000000000000000118E0
47 ]
48 cd.reverse()
49
50 fn = [
51 4.21543555043677546506E-1,
52 1.43407919780758885261E-1,
53 1.15220955073585758835E-2,
54 3.45017939782574027900E-4,
55 4.63613749287867322088E-6,
56 3.05568983790257605827E-8,
57 1.02304514164907233465E-10,
58 1.72010743268161828879E-13,
59 1.34283276233062758925E-16,
60 3.76329711269987889006E-20
61 ]
62 fn.reverse()
63 fd = [
64 1.00000000000000000000E0,
65 7.51586398353378947175E-1,
66 1.16888925859191382142E-1,
67 6.44051526508858611005E-3,
68 1.55934409164153020873E-4,
69 1.84627567348930545870E-6,
70 1.12699224763999035261E-8,
71 3.60140029589371370404E-11,
72 5.88754533621578410010E-14,
73 4.52001434074129701496E-17,
74 1.25443237090011264384E-20
75 ]
76 fd.reverse()
77 gn = [
78 5.04442073643383265887E-1,
79 1.97102833525523411709E-1,
80 1.87648584092575249293E-2,
81 6.84079380915393090172E-4,
82 1.15138826111884280931E-5,
83 9.82852443688422223854E-8,
84 4.45344415861750144738E-10,
85 1.08268041139020870318E-12,
86 1.37555460633261799868E-15,
87 8.36354435630677421531E-19,
88 1.86958710162783235106E-22
89 ]
90 gn.reverse()
91 gd = [
92 1.00000000000000000000E0,
93 1.47495759925128324529E0,
94 3.37748989120019970451E-1,
95 2.53603741420338795122E-2,
96 8.14679107184306179049E-4,
97 1.27545075667729118702E-5,
98 1.04314589657571990585E-7,
99 4.60680728146520428211E-10,
100 1.10273215066240270757E-12,
101 1.38796531259578871258E-15,
102 8.39158816283118707363E-19,
103 1.86958710162783236342E-22
104 ]
105 gd.reverse()
106
107
108 def fresnel(xxa):
109 x = abs(xxa)
110 x2 = x * x
111 if x2 < 2.5625:
112 t = x2 * x2
113 ss = x * x2 * polevl(t, sn) / polevl(t, sd)
114 cc = x * polevl(t, cn) / polevl(t, cd)
115 elif x > 36974.0:
116 ss = 0.5
117 cc = 0.5
118 else:
119 t = pi * x2
120 u = 1.0 / (t * t)
121 t = 1.0 / t
122 f = 1.0 - u * polevl(u, fn) / polevl(u, fd)
123 g = t * polevl(u, gn) / polevl(u, gd)
124 t = pi * .5 * x2
125 c = cos(t)
126 s = sin(t)
127 t = pi * x
128 cc = 0.5 + (f * s - g * c) / t
129 ss = 0.5 - (f * c + g * s) / t
130 if xxa < 0:
131 cc = -cc
132 ss = -ss
133 return ss, cc
134
135 def eval_cornu(t):
136 spio2 = sqrt(pi * .5)
137 s, c = fresnel(t / spio2)
138 s *= spio2
139 c *= spio2
140 return s, c