@@ -207,14 +207,47 @@ 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
+ pub fn solve_coeffs ( & mut self ) {
229
+ match & self . boundary_cond {
230
+ CubicBC :: Natural => {
231
+ todo ! ( )
232
+ }
233
+ _ => todo ! ( ) ,
234
+ }
235
+ }
236
+ }
237
+
238
+ /// Cubic boundary conditions.
239
+ #[ derive( Copy , Clone , Debug , Default , PartialEq ) ]
240
+ pub enum CubicBC < T > {
241
+ /// Second derivatives at endpoints are 0, thus extrapolation is linear.
242
+ // https://www.math.ntnu.no/emner/TMA4215/2008h/cubicsplines.pdf
243
+ #[ default]
244
+ Natural ,
245
+ /// Specific first derivatives at endpoints.
246
+ Clamped ( T , T ) ,
247
+ NotAKnot ,
248
+ // https://math.ou.edu/~npetrov/project-5093-s11.pdf
249
+ Periodic ,
250
+ }
218
251
219
252
/// Nearest value interpolation: <https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation>
220
253
///
0 commit comments