CARMA C++
quad.h
1 #ifndef quad_h
2 #define quad_h
3 
8 #define QP_ANGLE_FN(fn) double (fn)(double angle)
9 
10 namespace sza {
11  namespace array {
12 
13  /*
14  * QuadPath objects contain a circular table of the last three
15  * coordinate pairs that were appended with extend_QuadPath().
16  * Quadratic interpolation of this table is provided by eval_QuadPath().
17  */
18  typedef struct QuadPath QuadPath;
19 
20  /*
21  * The type of ordinate to be interpolated.
22  */
23  typedef enum {
24  QP_NORMAL, /* A continuous function */
25  QP_SIGNED_ANGLE, /* Angles defined modulo 2.pi between -pi <= v < pi */
26  QP_POSITIVE_ANGLE /* Angles defined modulo 2.pi between 0 <= v < 2.pi */
27  } QuadType;
28 
29  QuadPath *new_QuadPath(double empty_value, QuadType type);
30  QuadPath *del_QuadPath(QuadPath *quad);
31 
32  typedef struct {
33  double x,y; /* One sample of a function to be interpolated */
34  } QuadSample;
35 
36  /*
37  * The following object type is used to query or replace the current
38  * contents of a QuadPath object.
39  */
40  typedef struct {
41  int npt; /* The number of samples in x[] and y[] (0..3). */
42  /* If npt==0 eval_QuadPath(X) always returns the value */
43  /* of the empty_value argument of new_QuadPath() */
44  /* If npt==1 eval_QuadPath(X) always returns x[0],y[0]. */
45  /* If npt==2 eval_QuadPath(X) returns the linear */
46  /* interpolation of x[0..1],y[0..1] at x==X. */
47  /* If npt==3 eval_QuadPath(X) returns the quadratic */
48  /* interpolation of x[0..1],y[0..1] at x==X. */
49  QuadSample s[3]; /* The npt<=3 samples of the function being
50  approximated */
51  } QuadData;
52 
53  void ini_QuadData(QuadData *data);
54 
55  int get_QuadPath(QuadPath *quad, QuadData *data);
56  int set_QuadPath(QuadPath *quad, QuadData *data);
57 
58  int extend_QuadPath(QuadPath *quad, double x, double y);
59  void empty_QuadPath(QuadPath *quad);
60 
61  /*
62  * Return the value of the quadratic equation at x.
63  */
64  double eval_QuadPath(QuadPath *quad, double x);
65 
66  /*
67  * Return the gradient of the quadratic equation at x.
68  */
69  double grad_QuadPath(QuadPath *quad, double x);
70 
71  /*
72  * Make these functions public in the namespace, since if we decide to
73  * change the algorithms anywhere, they will change for everybody.
74  * Ie, I don't want to maintain a separate complement of these
75  * functions for the antenna code.
76  */
77  double extend_angle(double a, double b);
78  QP_ANGLE_FN(angle_around_zero);
79  QP_ANGLE_FN(angle_around_pi);
80 
81  }
82 }
83 
84 #endif