VBMicrolensing 5.3.5__cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,616 @@
1
+ // VBMicrolensing v5.3 (2025)
2
+ //
3
+ // This code has been developed by Valerio Bozza (University of Salerno) and collaborators.
4
+ // Check the repository at https://github.com/valboz/VBMicrolensing
5
+ // for the newest version.
6
+ // Any use of the code for scientific publications should be acknowledged by a citation
7
+ // to the appropriate publication, as detailed in the repository page.
8
+ //
9
+ // The code relies on the root solving algorithm by Jan Skworon and Andy Gould
10
+ // described in Skowron & Gould arXiv:1203.1034.
11
+ // Please also cite this paper if specifically relevant in your scientific publication.
12
+ // The original Fortran code available on http://www.astrouw.edu.pl/~jskowron/cmplx_roots_sg/
13
+ // has been translated to C++ by Tyler M. Heintz and Ava R. Hoag (2017)
14
+ //
15
+ // The Multipoly method for the calculation of multiple-lens microlensing was developed
16
+ // with Vito Saggese (2024).
17
+ //
18
+ // Optimizations for complex functions and for high-mag regime have been developed
19
+ // by Jiyuan Zhang (2025).
20
+ //
21
+ // GNU Lesser General Public License applies to all parts of this code.
22
+ // Please read the separate LICENSE.txt file for more details.
23
+
24
+
25
+ #ifndef __multilens
26
+ #define __multilens
27
+ #define __unmanaged
28
+
29
+ #define _L_1 x1-((x1+a/2.0)/((x1+a/2.0)*(x1+a/2.0)+x2*x2)+q*(x1-a/2.0)/((x1-a/2.0)*(x1-a/2.0)+x2*x2))/(1.0+q) // Used in PlotCrits
30
+ #define _L_2 x2-(x2/((x1+a/2.0)*(x1+a/2.0)+x2*x2)+q*x2/((x1-a/2.0)*(x1-a/2.0)+x2*x2))/(1.0+q)
31
+ #define _LL (y-z)+coefs[21]/(zc-coefs[20])+coefs[22]/zc //Lens equation test
32
+ #define _J1c coefs[21]/((zc-coefs[20])*(zc-coefs[20]))+coefs[22]/(zc*zc) //#define _J1 m1/((zc-0.5*a)*(zc-0.5*a))+m2/((zc+0.5*a)*(zc+0.5*a))
33
+ #define _J2 -2.0*(coefs[21]/((z-coefs[20])*(z-coefs[20])*(z-coefs[20]))+coefs[22]/(z*z*z))
34
+ #define _J3 6.0*(coefs[21]/((z-coefs[20])*(z-coefs[20])*(z-coefs[20])*(z-coefs[20]))+coefs[22]/(z*z*z*z))
35
+ #define _skew(p1,p2,q1,q2) p1*q2-p2*q1
36
+ #define _NP 200.0
37
+ #define __rsize_ESPL 151
38
+ #define __zsize_ESPL 101
39
+
40
+ #define _sign(x) ((x>0)? +1 : -1)
41
+
42
+ #include <stdio.h>
43
+ #include <string.h>
44
+ #define _USE_MATH_DEFINES
45
+ #include <math.h>
46
+ #include <vector>
47
+ #include <random>
48
+ class _sols_for_skiplist_curve;
49
+ class _skiplist_curve;
50
+ /******************************************* end *******************************************/
51
+
52
+ class _curve;
53
+ class _sols;
54
+ class _theta;
55
+ class complex;
56
+ struct annulus;
57
+
58
+
59
+ class complex {
60
+ public:
61
+ double re;
62
+ double im;
63
+ complex(double a, double b) { re = a; im = b; }
64
+ complex(double a) { re = a; im = 0; }
65
+ complex(void) { re = 0; im = 0; }
66
+ };
67
+
68
+
69
+
70
+ class VBMicrolensing
71
+ {
72
+ const int maxiter = 10000;
73
+ const double pseudorandom[12] = { 0.5, 0.4, 0.3, 0.7, 0.6, 0.5, 0.4, 0.7, 0.5, 0.6, 0.3,
74
+ 0.3 };
75
+
76
+ int* ndatasat;
77
+ double** tsat, *** possat;
78
+ double** posEar, startEar, stepEar;
79
+ int ndataEar;
80
+ double Mag0;
81
+ double* dist_mp, * q;
82
+ int nim0, n, n2, nnm1, nroots, nrootsmp, * nrootsmp_mp;
83
+ complex* zr, * zcr, ** pmza, ** pyaza, ** ppmy, * pza, * pza2, ** pmza2, * pdum, * ppy, * a, * s_offset, * pert, y, yc, * s;
84
+ complex* y_mp, *** pmza_mp, ** pza_mp, *** pyaza_mp, *** ppmy_mp, ** ppy_mp, ** zr_mp;
85
+ complex* zaltc, * J1, * J1c, ** za, ** za2;
86
+ complex* coefs, ** coefs_mp;
87
+ complex** a_mp, * s_sort;
88
+
89
+ double* prodevs, * errs, err, L0f, Jacf;
90
+ complex* devs, * init, * centralimages, * newseeds, * grads, zf, S2f, * S2s, * S3s, * S4s;
91
+ int lencentralimages, lennewseeds, ngoodold, ngood, iter, iter2;
92
+ ////
93
+ double* good, * Jacs, rho, rho2, * m;
94
+ double** m_mp, * q_sort;
95
+ int* worst;
96
+ double e, phi, phip, phi0, Om, inc, u0, tE_inv, t0, alpha, pai1, pai2, PosAng, dPosAng, thetaE, d3, v3, GM, flagits;
97
+ int iastro;
98
+ double Obj[3], rad[3], tang[3], t0old;
99
+ double Eq2000[3], Quad2000[3], North2000[3];
100
+ double Et0[2], vt0[2], Et[2], Ehel[2], lighttravel, lighttravel0;
101
+ double ESPLout[__rsize_ESPL][__zsize_ESPL], ESPLin[__rsize_ESPL][__zsize_ESPL], ESPLoutastro[__rsize_ESPL][__zsize_ESPL], ESPLinastro[__rsize_ESPL][__zsize_ESPL];
102
+ bool coordinates_set;
103
+ bool multidark;
104
+ double* LDtab, * rCLDtab, * CLDtab;
105
+ double scr2, sscr2;
106
+ int npLD;
107
+ annulus* annlist;
108
+ _skiplist_curve** cprec, ** cpres, ** cfoll;
109
+ double** A;
110
+
111
+ void ComputeCentroids(double* pr, double t, double* c1s, double* c2s, double* c1l, double* c2l);
112
+ void ComputeParallax(double, double);
113
+ double LDprofile(double r);
114
+ double rCLDprofile(double tc, annulus*, annulus*);
115
+ void initroot();
116
+ int froot(complex);
117
+ bool checkroot(_theta*);
118
+
119
+ void SetLensGeometry_spnp(int n, double* q, complex* s);
120
+ void SetLensGeometry_multipoly(int n, double* q, complex* s);
121
+ void initrootpoly();
122
+ _curve* NewImages(complex, complex*, _theta*);
123
+ _curve* NewImages(_theta*);
124
+ _curve* NewImagespoly(_theta*);
125
+ _curve* NewImagesmultipoly(_theta*);
126
+ _curve* NewImages_shear(complex, complex*, _theta *);
127
+ double BinaryMagSafe(double s, double q, double y1, double y2, double rho, _sols_for_skiplist_curve** images);
128
+ double MultiMagSafe(double y1, double y2, double rho, _sols_for_skiplist_curve** images);
129
+ void OrderImages(_sols_for_skiplist_curve*, _curve*);
130
+
131
+ void OrderMultipleImages(_sols_for_skiplist_curve*, _curve*);
132
+ void cmplx_laguerre(complex*, int, complex*, int&, bool&);
133
+ void cmplx_newton_spec(complex*, int, complex*, int&, bool&);
134
+ void cmplx_laguerre2newton(complex*, int, complex*, int&, bool&, int);
135
+ void solve_quadratic_eq(complex&, complex&, complex*);
136
+ void solve_cubic_eq(complex&, complex&, complex&, complex*);
137
+ void polyproduct(complex* p1, int n1, complex* p2, int n2, complex* pdest);
138
+ void copypol(complex* p1, int n1, complex* pdest);
139
+ void change_n(int nn);
140
+ void change_n_mp(int nn);
141
+ void polycoefficients();
142
+ void polycoefficients_multipoly();
143
+ void polycritcoefficients(complex eiphi);
144
+
145
+ public:
146
+
147
+ double rootaccuracy;
148
+ double samplingfactor;
149
+ bool squarecheck;
150
+ bool astrometry;
151
+ bool turn_off_secondary_source;
152
+ bool turn_off_secondary_lens;
153
+ bool ESPLoff;
154
+ bool t_in_HJD;
155
+
156
+ static char ESPLtablefile[1024];
157
+ static void SetESPLtablefile(char* instring) { strcpy(ESPLtablefile, instring); }
158
+ static char Suntablefile[1024];
159
+ static void SetSuntablefile(char* instring) { strcpy(Suntablefile, instring); }
160
+ double Tol, RelTol, a1, a2,corrquad, corrquad2, safedist;
161
+ double mass_radius_exponent, mass_luminosity_exponent, lens_mass_luminosity_exponent;
162
+ int satellite, parallaxsystem, t0_par_fixed, nsat;
163
+ double t0_par;
164
+ bool suntable, parallaxephemeris;
165
+ int parallaxextrapolation;
166
+ int minannuli, maxannuli, nannuli, NPS, NPcrit;
167
+ int newtonstep;
168
+ double y_1, y_2, av, therr, astrox1, astrox2;
169
+ double (*CumulativeFunction)(double r, double* LDpars);
170
+
171
+ // Critical curves and caustics calculation
172
+ _sols* PlotCrit();
173
+ _sols* PlotCrit(double a, double q);
174
+ // Initialization for parallax calculation
175
+ void SetObjectCoordinates(char* Coordinates_file, char* Directory_for_satellite_tables);
176
+ void SetObjectCoordinates(char* CoordinateString);
177
+ bool AreCoordinatesSet();
178
+ // Skowron & Gould root calculation
179
+ void cmplx_roots_gen(complex*, complex*, int, bool, bool);
180
+ void cmplx_roots_multigen(complex*, complex**, int, bool, bool);
181
+ // Bozza optimization
182
+ int findimagepoly(int iroot);
183
+ int findimagemultipoly(int iroot);
184
+
185
+ // Set Lens Geometry
186
+ void SetLensGeometry(int n, double* q, complex* s);
187
+ void SetLensGeometry(int n, double* pr);
188
+
189
+ // Magnification calculation functions.
190
+
191
+ double BinaryMag0(double s, double q, double y1, double y2, _sols_for_skiplist_curve** Images);
192
+ double BinaryMag0(double s, double q, double y1, double y2);
193
+
194
+ double BinaryMag(double s, double q, double y1, double y2, double rho, double accuracy, _sols_for_skiplist_curve** Images);
195
+ double BinaryMag(double s, double q, double y1, double y2, double rho, double accuracy);
196
+ double BinaryMag2(double s, double q, double y1, double y2, double rho);
197
+ double BinaryMagDark(double s, double q, double y1, double y2, double rho, double accuracy);
198
+ void BinaryMagMultiDark(double s, double q, double y1, double y2, double rho, double* a1_list, int n_filters, double* mag_list, double accuracy);
199
+ double MultiMag0(double y1, double y2, _sols_for_skiplist_curve** Images);
200
+ double MultiMag0(double y1, double y2);
201
+ double MultiMag(double y1, double y2, double rho, double accuracy, _sols_for_skiplist_curve** Images);
202
+ double MultiMag(double y1, double y2, double rho, double accuracy);
203
+ double MultiMag(double y1, double y2, double rho);
204
+ double MultiMag2(double y1, double y2, double rho);
205
+ double MultiMagDark(double y1, double y2, double rho, double accuracy);
206
+
207
+ double BinaryMag0_shear(double s, double q, double y1, double y2, double K1, double G1, double Gi, _sols **Images);
208
+ double BinaryMag0_shear(double s, double q, double y1, double y2, double K1, double G1, double Gi);
209
+
210
+ // Limb Darkening control
211
+ enum LDprofiles { LDlinear, LDquadratic, LDsquareroot, LDlog, LDuser };
212
+ void SetLDprofile(double(*UserLDprofile)(double), int tablesampling);
213
+ void SetLDprofile(LDprofiles);
214
+
215
+ // Method control
216
+ enum class Method { Singlepoly, Multipoly, Nopoly };
217
+ void SetMethod(Method);
218
+
219
+ //ESPL functions
220
+ void LoadESPLTable(const char* tablefilename);
221
+ double ESPLMag(double u, double rho);
222
+ double ESPLMag2(double u, double rho);
223
+ double ESPLMagDark(double u, double rho);
224
+ double PSPLMag(double u);
225
+
226
+
227
+ // New (v2) light curve functions, operating on arrays
228
+
229
+ void LoadSunTable(char* tablefilename);
230
+ void PSPLLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
231
+ void PSPLLightCurveParallax(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
232
+ void ESPLLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
233
+ void ESPLLightCurveParallax(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
234
+
235
+ void BinaryLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
236
+ void BinaryLightCurveW(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
237
+ void BinaryLightCurveParallax(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
238
+ void BinaryLightCurveOrbital(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, double* sep_array, int np);
239
+ void BinaryLightCurveKepler(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, double* sep_array, int np);
240
+
241
+ void BinSourceLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
242
+ void BinSourceLightCurveParallax(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
243
+ void BinSourceLightCurveXallarap(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, double* sep_array, int np);
244
+ void BinSourceExtLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
245
+ void BinSourceExtLightCurveXallarap(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, double* y1_array2, double* y2_array2, int np);
246
+ void BinSourceSingleLensXallarap(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, double* y1_array2, double* y2_array2, int np);
247
+ void BinSourceBinLensXallarap(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
248
+ void BinSourceBinLensLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, double* y1_array2, double* y2_array2, double* seps_array, int np);
249
+
250
+ void TripleLightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
251
+ void TripleLightCurveParallax(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np);
252
+ void LightCurve(double* parameters, double* t_array, double* mag_array, double* y1_array, double* y2_array, int np, int nl);
253
+
254
+ // Old (v1) light curve functions, for a single calculation
255
+ double PSPLLightCurve(double* parameters, double t);
256
+ double PSPLLightCurveParallax(double* parameters, double t);
257
+ double ESPLLightCurve(double* parameters, double t);
258
+ double ESPLLightCurveParallax(double* parameters, double t);
259
+
260
+ double BinaryLightCurve(double* parameters, double t);
261
+ double BinaryLightCurveW(double* parameters, double t);
262
+ double BinaryLightCurveParallax(double* parameters, double t);
263
+ double BinaryLightCurveOrbital(double* parameters, double t);
264
+ double BinaryLightCurveKepler(double* parameters, double t);
265
+
266
+ double BinSourceLightCurve(double* parameters, double t);
267
+ double BinSourceLightCurveParallax(double* parameters, double t);
268
+ double BinSourceLightCurveXallarap(double* parameters, double t);
269
+ double BinSourceExtLightCurve(double* parameters, double t);
270
+ double BinSourceExtLightCurveXallarap(double* parameters, double t);
271
+ double BinSourceBinLensXallarap(double* parameters, double t);
272
+ double BinSourceSingleLensXallarap(double* parameters, double t);
273
+ double BinSourceBinLensLightCurve(double* parameters, double t);
274
+
275
+
276
+ double TripleLightCurve(double* parameters, double t);
277
+ double TripleLightCurveParallax(double* parameters, double t);
278
+
279
+ // Astrometric functions
280
+ void CombineCentroids(double* mags, double* c1s, double* c2s, double* c1l, double* c2l, double* c1ltot, double* c2tot, double g, int np);
281
+ void PSPLAstroLightCurve(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, int np);
282
+ void ESPLAstroLightCurve(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, int np);
283
+ void BinaryAstroLightCurve(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, int np);
284
+ void BinaryAstroLightCurveOrbital(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, double* seps_array, int np);
285
+ void BinaryAstroLightCurveKepler(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, double* seps_array, int np);
286
+ void BinSourceAstroLightCurveXallarap(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, double* y1_array2, double* y2_array2, int np);
287
+ void BinSourceBinLensAstroLightCurve(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, double* y1_array2, double* y2_array2, double* seps_array, int np);
288
+ void TripleAstroLightCurve(double* parameters, double* t_array, double* mag_array, double* centroid_s1_array, double* centroid_s2_array, double* centroid_l1_array, double* centroid_l2_array, double* y1_array, double* y2_array, int np);
289
+
290
+ // Constructor and destructor
291
+
292
+ VBMicrolensing();
293
+ ~VBMicrolensing();
294
+
295
+ private: // Must be declared here at the end
296
+ LDprofiles curLDprofile;
297
+ Method SelectedMethod;
298
+
299
+ };
300
+
301
+ //std::string VBMicrolensing::ESPLtablefile = "";
302
+
303
+ double VBDefaultCumulativeFunction(double r, double* a1);
304
+
305
+ struct annulus {
306
+ double bin;
307
+ double cum;
308
+ double Mag;
309
+ double err;
310
+ double f;
311
+ int nim;
312
+ double LDastrox1, LDastrox2;
313
+ annulus* prev, * next;
314
+ };
315
+
316
+
317
+
318
+ class _theta {
319
+ public:
320
+ double th, maxerr, Mag, errworst, astrox1, astrox2;
321
+ int imlength;
322
+ _theta* prev, * next;
323
+
324
+ _theta(double);
325
+
326
+ };
327
+
328
+ class _thetas {
329
+ public:
330
+ _theta* first, * last;
331
+ int length;
332
+
333
+ _thetas(void);
334
+ ~_thetas(void);
335
+ _theta* insert(double);
336
+ _theta* insert_at_certain_position(_theta*, double);
337
+ // method: this method can only be used when inserting an element in the middle of linked list
338
+ // i.e. *first's 'th' < current 'th' < *last's 'th'
339
+ // and the new element is forced to be inserted between itheta and itheta->next,
340
+ // which means it's the programmer's responsibility to guarantee itheta->th < th < itheta->next->th holds
341
+ // (O(1) complexity)
342
+ void remove(_theta*);
343
+
344
+ };
345
+
346
+ #define max_skiplist_level 2
347
+
348
+ class _point {
349
+ public:
350
+ double x1;
351
+ double x2;
352
+ double parab, ds, dJ, Mag, err, parabastrox1;
353
+ complex d; // d is z'(theta) at this point
354
+ _theta* theta; // pointer
355
+ _point* next, * prev; // pointers that point to _point variable
356
+ _point* next_array[max_skiplist_level + 1];
357
+
358
+ double parabastrox2;
359
+ _point(double, double, _theta*);
360
+ double operator-(_point);
361
+ };
362
+
363
+ class _curve {
364
+ public:
365
+ int length;
366
+ _point* first, * last;
367
+ _curve* next, * prev;
368
+ _curve* partneratstart, * partneratend;
369
+ double parabstart, Magstart, errstart, parabastrox1, parabastrox2;
370
+
371
+ _curve(_point*);
372
+ _curve(void);
373
+ ~_curve(void);
374
+
375
+ _curve* divide(_point*);
376
+ void drop(_point*);
377
+ void append(double, double);
378
+ void append(_point*);
379
+ void prepend(double, double);
380
+ // void prepend(_point *);
381
+ _curve* join(_curve*);
382
+ _curve* joinbefore(_curve*);
383
+ _curve* reverse(void);
384
+ double closest(_point*, _point**);
385
+ double closest2(_point*, _point**);
386
+ void complement(_point**, int, _point**, int);
387
+ };
388
+
389
+ class _sols {
390
+ public:
391
+ int length;
392
+ _curve* first, * last;
393
+
394
+ _sols(void);
395
+ ~_sols(void);
396
+ void drop(_curve*);
397
+ void append(_curve*);
398
+ void prepend(_curve*);
399
+ void join(_sols*);
400
+ };
401
+
402
+
403
+ class _skiplist_curve { // a _skiplist_curve class variable is a skip list of _point variables
404
+ public:
405
+ _point* first, * last;
406
+
407
+ _point* head;
408
+ _point* last_array[max_skiplist_level + 1];
409
+ int Level;
410
+
411
+ int length_notation;
412
+
413
+ _skiplist_curve* next, * prev;
414
+ _skiplist_curve* partneratstart, * partneratend;
415
+ double parabstart, Magstart, errstart, parabastrox1, parabastrox2;
416
+
417
+ _skiplist_curve(_point* p1, int new_Level);
418
+ _skiplist_curve(void);
419
+ ~_skiplist_curve(void);
420
+ _skiplist_curve* join(_skiplist_curve* new_curve);
421
+ void append(_point* pp, int append_Level);
422
+ void append(double x1, double x2, int append_Level);
423
+ _skiplist_curve* find_prev_then_divide(double th);
424
+
425
+ };
426
+
427
+
428
+
429
+
430
+ class _sols_for_skiplist_curve { // a _sols_for_skiplist_curve class variable is a linked list of _skiplist_curve variables,
431
+ // while a _skiplist_curve class variable is a skip list of _point variables
432
+ public:
433
+ int length;
434
+ _skiplist_curve* first, * last;
435
+
436
+ _sols_for_skiplist_curve(void);
437
+ ~_sols_for_skiplist_curve(void);
438
+ void drop(_skiplist_curve* ref);
439
+ void append(_skiplist_curve* cc);
440
+
441
+ };
442
+
443
+ #define MR 8
444
+ #define MT 10
445
+ #define MAXIT (MT*MR)
446
+ #define MAXM 101
447
+
448
+ //////////////////////////////
449
+ //////////////////////////////
450
+ ////////complex methods and operators
451
+ //////////////////////////////
452
+ //////////////////////////////
453
+
454
+ inline double abs2(complex z) {
455
+ return (z.re * z.re + z.im * z.im);
456
+ }
457
+
458
+ inline double abs(complex z) {
459
+ return sqrt(z.re * z.re + z.im * z.im);
460
+ }
461
+
462
+ inline complex conj(complex z) {
463
+ return complex(z.re, -z.im);
464
+ }
465
+
466
+ inline complex sqrt(complex z) {
467
+ double md = sqrt(z.re * z.re + z.im * z.im);
468
+ return (md > 0) ? complex(sqrt((md + z.re) / 2), (sqrt((md - z.re) / 2) * ((z.im > 0) ? 1 : -1))) : 0.0;
469
+ }
470
+
471
+
472
+
473
+ inline double real(complex z) {
474
+ return z.re;
475
+ }
476
+
477
+ inline double imag(complex z) {
478
+ return z.im;
479
+ }
480
+
481
+ inline complex operator+(complex p1, complex p2) {
482
+ return complex(p1.re + p2.re, p1.im + p2.im);
483
+ }
484
+
485
+ inline complex operator-(complex p1, complex p2) {
486
+ return complex(p1.re - p2.re, p1.im - p2.im);
487
+ }
488
+
489
+ inline complex operator*(complex p1, complex p2) {
490
+ return complex(p1.re * p2.re - p1.im * p2.im, p1.re * p2.im + p1.im * p2.re);
491
+ }
492
+
493
+ inline complex operator/(complex p1, complex p2) {
494
+ double md = p2.re * p2.re + p2.im * p2.im;
495
+ return complex((p1.re * p2.re + p1.im * p2.im) / md, (p1.im * p2.re - p1.re * p2.im) / md);
496
+ }
497
+
498
+ inline complex operator+(complex z, double a) {
499
+ return complex(z.re + a, z.im);
500
+ }
501
+
502
+ inline complex operator-(complex z, double a) {
503
+ return complex(z.re - a, z.im);
504
+ }
505
+
506
+ inline complex operator*(complex z, double a) {
507
+ return complex(z.re * a, z.im * a);
508
+ }
509
+
510
+ inline complex operator/(complex z, double a) {
511
+ return complex(z.re / a, z.im / a);
512
+ }
513
+
514
+ inline complex operator+(double a, complex z) {
515
+ return complex(z.re + a, z.im);
516
+ }
517
+
518
+ inline complex operator-(double a, complex z) {
519
+ return complex(a - z.re, -z.im);
520
+ }
521
+
522
+ inline complex operator*(double a, complex z) {
523
+ return complex(a * z.re, a * z.im);
524
+ }
525
+
526
+ inline complex operator/(double a, complex z) {
527
+ double md = z.re * z.re + z.im * z.im;
528
+ return complex(a * z.re / md, -a * z.im / md);
529
+ }
530
+
531
+ inline complex operator+(complex z, int a) {
532
+ return complex(z.re + a, z.im);
533
+ }
534
+
535
+ inline complex operator-(complex z, int a) {
536
+ return complex(z.re - a, z.im);
537
+ }
538
+
539
+ inline complex operator*(complex z, int a) {
540
+ return complex(z.re * a, z.im * a);
541
+ }
542
+
543
+ inline complex operator/(complex z, int a) {
544
+ return complex(z.re / a, z.im / a);
545
+ }
546
+
547
+ inline complex operator+(int a, complex z) {
548
+ return complex(z.re + a, z.im);
549
+ }
550
+
551
+ inline complex operator-(int a, complex z) {
552
+ return complex(a - z.re, -z.im);
553
+ }
554
+
555
+ inline complex operator*(int a, complex z) {
556
+ return complex(a * z.re, a * z.im);
557
+ }
558
+
559
+ inline complex operator/(int a, complex z) {
560
+ double md = z.re * z.re + z.im * z.im;
561
+ return complex(a * z.re / md, -a * z.im / md);
562
+ }
563
+
564
+ inline complex operator-(complex z) {
565
+ return complex(-z.re, -z.im);
566
+ }
567
+
568
+ inline bool operator==(complex p1, complex p2) {
569
+ if (p1.re == p2.re && p1.im == p2.im) return true;
570
+ return false;
571
+ }
572
+
573
+ inline bool operator!=(complex p1, complex p2) {
574
+ if (p1.re == p2.re && p1.im == p2.im) return false;
575
+ return true;
576
+ }
577
+
578
+ inline complex expcmplx(complex p1) {
579
+ double r = exp(p1.re);
580
+ double theta = atan2(p1.im, p1.re);
581
+ return complex(r * cos(theta), r * sin(theta));
582
+ }
583
+
584
+ inline complex cbrt(complex z) {
585
+ complex zout;
586
+ double r, r_cube, theta, theta_cube;
587
+ r = abs(z);
588
+ r_cube = pow(r, 0.333333333333);
589
+ theta = atan2(z.im, z.re);
590
+ theta_cube = theta / 3.;
591
+ return complex(r_cube * cos(theta_cube), r_cube * sin(theta_cube));
592
+ }
593
+
594
+
595
+ inline _point::_point(double x, double y, _theta* theta1) {
596
+ x1 = x;
597
+ x2 = y;
598
+ theta = theta1;
599
+ next = 0;
600
+ prev = 0;
601
+ for (int i = 0; i < (max_skiplist_level + 1); i++)
602
+ {
603
+ next_array[i] = 0;
604
+ }
605
+ }
606
+
607
+ inline double _point::operator-(_point p2) {
608
+ static double dx1, dx2;
609
+ dx1 = x1 - p2.x1;
610
+ dx2 = x2 - p2.x2;
611
+ return dx1 * dx1 + dx2 * dx2;
612
+ }
613
+
614
+
615
+ #endif
616
+