mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added simpler interface to non-uniform spline
This commit is contained in:
parent
ad44b0f435
commit
7d32acd2bb
1 changed files with 12 additions and 0 deletions
12
spline.hh
12
spline.hh
|
|
@ -6,6 +6,8 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <int KNOTS, typename OTYPE, typename ITYPE>
|
||||
|
|
@ -92,6 +94,16 @@ struct CubicHermiteSpline
|
|||
:
|
||||
h00(t) * Y[n-2] + h10(t) * (X[n-1]-X[n-2]) * central(X+n-2, Y+n-2) + h01(t) * Y[n-1] + h11(t) * (X[n-1]-X[n-2]) * left(X+n-1, Y+n-1);
|
||||
}
|
||||
static OTYPE eval(const ITYPE *X, const OTYPE *Y, ITYPE x, int n)
|
||||
{
|
||||
int k = std::lower_bound(X, X+n, x) - X;
|
||||
return k < 1 ?
|
||||
eval(X, Y, (x - X[0]) / (X[1] - X[0]), 0, n)
|
||||
: k < n ?
|
||||
eval(X, Y, (x - X[k-1]) / (X[k] - X[k-1]), k-1, n)
|
||||
:
|
||||
eval(X, Y, (x - X[n-2]) / (X[n-1] - X[n-2]), n-2, n);
|
||||
}
|
||||
static constexpr OTYPE left(const OTYPE *Y)
|
||||
{
|
||||
return Y[0] - Y[-1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue