mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added x0 and dx args to constructor
This commit is contained in:
parent
9bd5546470
commit
54ae4f735e
1 changed files with 7 additions and 5 deletions
12
spline.hh
12
spline.hh
|
|
@ -13,8 +13,9 @@ template <int KNOTS, typename OTYPE, typename ITYPE>
|
|||
class UniformNaturalCubicSpline
|
||||
{
|
||||
OTYPE A[KNOTS], B[KNOTS], C[KNOTS], D[KNOTS];
|
||||
ITYPE x0, dx;
|
||||
public:
|
||||
UniformNaturalCubicSpline(OTYPE *y, int STRIDE = 1)
|
||||
UniformNaturalCubicSpline(OTYPE *y, ITYPE x0 = 0, ITYPE dx = 1, int STRIDE = 1) : x0(x0), dx(dx)
|
||||
{
|
||||
for (int i = 0; i < KNOTS; ++i)
|
||||
A[i] = y[i * STRIDE];
|
||||
|
|
@ -37,14 +38,15 @@ public:
|
|||
}
|
||||
OTYPE operator () (ITYPE x)
|
||||
{
|
||||
int k = x;
|
||||
ITYPE t = x - ITYPE(k);
|
||||
ITYPE tx = (x - x0) / dx;
|
||||
int k = tx;
|
||||
ITYPE t = tx - ITYPE(k);
|
||||
if (k < 0) {
|
||||
t = x;
|
||||
t = tx;
|
||||
k = 0;
|
||||
}
|
||||
if (k >= KNOTS - 1) {
|
||||
t = x - ITYPE(KNOTS-2);
|
||||
t = tx - ITYPE(KNOTS-2);
|
||||
k = KNOTS-2;
|
||||
}
|
||||
return A[k] + t * (B[k] + t * (C[k] + t * D[k]));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue