@@ -207,14 +207,65 @@ pub fn find_nearest_index<T: PartialOrd>(arr: ArrayView1<T>, target: &T) -> usiz
207
207
#[ cfg_attr( feature = "serde" , derive( Deserialize , Serialize ) ) ]
208
208
pub struct Linear ;
209
209
210
- // TODO: `pub struct Quadratic;`
211
- // Maybe `pub struct Polynomial(usize);` as well?
212
- // with `pub type Quadratic = Polynomial(2)` and `pub type Cubic = Polynomial(3)`
213
-
214
210
/// Cubic spline interpolation: TODO
215
- #[ derive( Debug , Clone , PartialEq ) ]
211
+ #[ derive( Clone , Debug , Default , PartialEq ) ]
216
212
#[ cfg_attr( feature = "serde" , derive( Deserialize , Serialize ) ) ]
217
- pub struct Cubic ;
213
+ pub struct Cubic < T : Default > {
214
+ pub boundary_cond : CubicBC < T > ,
215
+ pub coeffs : ArrayD < T > ,
216
+ }
217
+
218
+ impl < T > Cubic < T >
219
+ where
220
+ T : Default ,
221
+ {
222
+ pub fn new ( bc : CubicBC < T > ) -> Self {
223
+ Self {
224
+ boundary_cond : bc,
225
+ coeffs : <ArrayD < T > as Default >:: default ( ) ,
226
+ }
227
+ }
228
+
229
+ pub fn natural ( ) -> Self {
230
+ Self :: new ( CubicBC :: Natural )
231
+ }
232
+
233
+ pub fn clamped ( a : T , b : T ) -> Self {
234
+ Self :: new ( CubicBC :: Clamped ( a, b) )
235
+ }
236
+
237
+ pub fn not_a_knot ( ) -> Self {
238
+ Self :: new ( CubicBC :: NotAKnot )
239
+ }
240
+
241
+ pub fn periodic ( ) -> Self {
242
+ Self :: new ( CubicBC :: Periodic )
243
+ }
244
+
245
+ pub fn solve_coeffs ( & mut self ) {
246
+ match & self . boundary_cond {
247
+ CubicBC :: Natural => {
248
+ todo ! ( )
249
+ }
250
+ _ => todo ! ( ) ,
251
+ }
252
+ }
253
+ }
254
+
255
+ /// Cubic boundary conditions.
256
+ #[ derive( Copy , Clone , Debug , Default , PartialEq ) ]
257
+ #[ cfg_attr( feature = "serde" , derive( Deserialize , Serialize ) ) ]
258
+ pub enum CubicBC < T > {
259
+ /// Second derivatives at endpoints are 0, thus extrapolation is linear.
260
+ // https://www.math.ntnu.no/emner/TMA4215/2008h/cubicsplines.pdf
261
+ #[ default]
262
+ Natural ,
263
+ /// Specific first derivatives at endpoints.
264
+ Clamped ( T , T ) ,
265
+ NotAKnot ,
266
+ // https://math.ou.edu/~npetrov/project-5093-s11.pdf
267
+ Periodic ,
268
+ }
218
269
219
270
/// Nearest value interpolation: <https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation>
220
271
///
0 commit comments