summaryrefslogtreecommitdiff
path: root/support/dktools/f2lpara.ctr
blob: c38387ab30b09cbf67bc6166048a28acc9dd6b76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2014-xxxx
license		=	bsd



%%	header

#ifdef __cplusplus
extern "C" {
#endif

/**	Get left point first derivative value for parabola
	through x=-1, x=0, and x=1.
	@param	yneg	Y value for x=-1.
	@param	y0	Y value for x=0.
	@param	ypos	Y value for x=1.
	@param	ec	Pointer to error code variable, may be NULL.
	@return	Result.
*/
double
f2lpara_derived_left(double yneg, double y0, double ypos, int *ec);

/**	Get center point first derivative value for parabola
	through x=-1, x=0, and x=1.
	@param	yneg	Y value for x=-1.
	@param	y0	Y value for x=0.
	@param	ypos	Y value for x=1.
	@param	ec	Pointer to error code variable, may be NULL.
	@return	Result.
*/
double
f2lpara_derived_center(double yneg, double y0, double ypos, int *ec);

/**	Get right point first derivative value for parabola
	through x=-1, x=0, and x=1.
	@param	yneg	Y value for x=-1.
	@param	y0	Y value for x=0.
	@param	ypos	Y value for x=1.
	@param	ec	Pointer to error code variable, may be NULL.
	@return	Result.
*/
double
f2lpara_derived_right(double yneg, double y0, double ypos, int *ec);


#ifdef __cplusplus
}
#endif

%%	module


#include "dk3ma.h"
#include "f2lpara.h"


double
f2lpara_derived_left(double yneg, double y0, double ypos, int *ec)
{
  double		back	= 0.0;
  int			myec	= 0;
  /* back = 2 * y0 - 0.5 * ypos - 1.5 * yneg */
  back = dk3ma_d_sub_ok(
    dk3ma_d_mul_ok(2.0, y0, &myec),
    dk3ma_d_add_ok(
      (0.5 * ypos),
      dk3ma_d_mul_ok(1.5, yneg, &myec),
      &myec
    ),
    &myec
  );
  if (myec) { if (ec) { *ec = myec; } }
  return back;
}


double
f2lpara_derived_center(double yneg, double y0, double ypos, int *ec)
{
  double		back	= 0.0;
  int			myec	= 0;
  /* back = 0.5 * (ypos - yneg)  */
  back = 0.5 * dk3ma_d_sub_ok(ypos, yneg, &myec);
  if (myec) { if (ec) { *ec = myec; } }
  return back;
}


double
f2lpara_derived_right(double yneg, double y0, double ypos, int *ec)
{
  double		back	= 0.0;
  int			myec	= 0;
  /* back = 1.5 * ypos + 0.5 * yneg - 2 * y0 */
  back = dk3ma_d_sub_ok(
    dk3ma_d_add_ok(
      dk3ma_d_mul_ok(1.5, ypos, &myec),
      (0.5 * yneg),
      &myec
    ),
    dk3ma_d_mul_ok(2.0, y0, &myec),
    &myec
  );
  if (myec) { if (ec) { *ec = myec; } }
  return back;
}