@@ -48,23 +48,6 @@ pub trait SplineNum:
4848{
4949}
5050
51- impl < T > SplineNum for T where
52- T : Debug
53- + Num
54- + Copy
55- + PartialOrd
56- + Sub
57- + SubAssign
58- + Neg < Output = T >
59- + NumCast
60- + Add
61- + Pow < Self , Output = Self >
62- + ScalarOperand
63- + Euclid
64- + Send
65- {
66- }
67-
6851/// The CubicSpline 1d interpolation Strategy (Builder)
6952///
7053/// # Example
@@ -104,6 +87,20 @@ pub struct CubicSpline<T, D: Dimension> {
10487 boundary : BoundaryCondition < T , D > ,
10588}
10689
90+ /// The CubicSpline 1d interpolation Strategy (Implementation)
91+ ///
92+ /// This is constructed by [`CubicSpline`]
93+ #[ derive( Debug ) ]
94+ pub struct CubicSplineStrategy < Sd , D >
95+ where
96+ Sd : Data ,
97+ D : Dimension + RemoveAxis ,
98+ {
99+ a : Array < Sd :: Elem , D > ,
100+ b : Array < Sd :: Elem , D > ,
101+ extrapolate : Extrapolate ,
102+ }
103+
107104/// Boundary conditions for the whole dataset
108105///
109106/// The boundary condition is structured in three hirarchic enum's:
@@ -170,12 +167,6 @@ pub enum BoundaryCondition<T, D: Dimension> {
170167 Individual ( Array < RowBoundary < T > , D > ) ,
171168}
172169
173- impl < T , D : Dimension > Default for BoundaryCondition < T , D > {
174- fn default ( ) -> Self {
175- Self :: NotAKnot
176- }
177- }
178-
179170/// Boundary condition for a single data row
180171#[ derive( Debug , PartialEq , Eq , Clone ) ]
181172pub enum RowBoundary < T > {
@@ -192,27 +183,11 @@ pub enum RowBoundary<T> {
192183 } ,
193184}
194185
195- impl < T : SplineNum > Default for RowBoundary < T > {
196- fn default ( ) -> Self {
197- Self :: NotAKnot
198- }
199- }
200-
201- impl < T > From < RowBoundary < T > > for InternalBoundary < T > {
202- fn from ( val : RowBoundary < T > ) -> Self {
203- match val {
204- RowBoundary :: NotAKnot => InternalBoundary :: NotAKnot ,
205- RowBoundary :: Natural => InternalBoundary :: Natural ,
206- RowBoundary :: Clamped => InternalBoundary :: Clamped ,
207- RowBoundary :: Mixed { left, right } => InternalBoundary :: Mixed { left, right } ,
208- }
209- }
210- }
211-
212186/// This is essentially [`RowBoundary`] but including the Periodic variant.
213187/// The periodic variant can not be applied to a single row only all or nothing.
214188/// But we still need it for calculating the coefficients, which may or may not be done
215189/// for each row individually.
190+ #[ derive( Debug ) ]
216191enum InternalBoundary < T > {
217192 NotAKnot ,
218193 Natural ,
@@ -224,6 +199,59 @@ enum InternalBoundary<T> {
224199 } ,
225200}
226201
202+ /// Boundary condition for a single boundary (one side of one data row)
203+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
204+ pub enum SingleBoundary < T > {
205+ /// ![`BoundaryCondition::NotAKnot`]
206+ NotAKnot ,
207+ /// This ist the same as `SingleBoundary::SecondDeriv(0.0)`
208+ /// ![`BoundaryCondition::Natural`]
209+ Natural ,
210+ /// This ist the same as `SingleBoundary::FirstDeriv(0.0)`
211+ /// ![`BoundaryCondition::Clamped`]
212+ Clamped ,
213+ /// Set a value for the first derivative at the curve end
214+ FirstDeriv ( T ) ,
215+ /// Set a value for the second derivative at the curve end
216+ SecondDeriv ( T ) ,
217+ }
218+
219+ #[ derive( Debug ) ]
220+ enum Extrapolate {
221+ Yes ,
222+ No ,
223+ Periodic ,
224+ }
225+
226+ impl < T > SplineNum for T where
227+ T : Debug
228+ + Num
229+ + Copy
230+ + PartialOrd
231+ + Sub
232+ + SubAssign
233+ + Neg < Output = T >
234+ + NumCast
235+ + Add
236+ + Pow < Self , Output = Self >
237+ + ScalarOperand
238+ + Euclid
239+ + Send
240+ {
241+ }
242+
243+ impl < T , D : Dimension > Default for BoundaryCondition < T , D > {
244+ fn default ( ) -> Self {
245+ Self :: NotAKnot
246+ }
247+ }
248+
249+ impl < T : SplineNum > Default for RowBoundary < T > {
250+ fn default ( ) -> Self {
251+ Self :: NotAKnot
252+ }
253+ }
254+
227255impl < T : SplineNum > InternalBoundary < T > {
228256 fn specialize ( self ) -> Self {
229257 use SingleBoundary :: * ;
@@ -245,21 +273,15 @@ impl<T: SplineNum> InternalBoundary<T> {
245273 }
246274}
247275
248- /// Boundary condition for a single boundary (one side of one data row)
249- #[ derive( Debug , PartialEq , Eq , Clone ) ]
250- pub enum SingleBoundary < T > {
251- /// ![`BoundaryCondition::NotAKnot`]
252- NotAKnot ,
253- /// This ist the same as `SingleBoundary::SecondDeriv(0.0)`
254- /// ![`BoundaryCondition::Natural`]
255- Natural ,
256- /// This ist the same as `SingleBoundary::FirstDeriv(0.0)`
257- /// ![`BoundaryCondition::Clamped`]
258- Clamped ,
259- /// Set a value for the first derivative at the curve end
260- FirstDeriv ( T ) ,
261- /// Set a value for the second derivative at the curve end
262- SecondDeriv ( T ) ,
276+ impl < T > From < RowBoundary < T > > for InternalBoundary < T > {
277+ fn from ( val : RowBoundary < T > ) -> Self {
278+ match val {
279+ RowBoundary :: NotAKnot => InternalBoundary :: NotAKnot ,
280+ RowBoundary :: Natural => InternalBoundary :: Natural ,
281+ RowBoundary :: Clamped => InternalBoundary :: Clamped ,
282+ RowBoundary :: Mixed { left, right } => InternalBoundary :: Mixed { left, right } ,
283+ }
284+ }
263285}
264286
265287impl < T : SplineNum > SingleBoundary < T > {
@@ -279,36 +301,6 @@ impl<T: SplineNum> Default for SingleBoundary<T> {
279301 }
280302}
281303
282- impl < Sd , Sx , D > Interp1DStrategyBuilder < Sd , Sx , D > for CubicSpline < Sd :: Elem , D >
283- where
284- Sd : Data ,
285- Sd :: Elem : SplineNum ,
286- Sx : Data < Elem = Sd :: Elem > ,
287- D : Dimension + RemoveAxis ,
288- {
289- const MINIMUM_DATA_LENGHT : usize = 3 ;
290- type FinishedStrat = CubicSplineStrategy < Sd , D > ;
291-
292- fn build < Sx2 > (
293- self ,
294- x : & ArrayBase < Sx2 , Ix1 > ,
295- data : & ArrayBase < Sd , D > ,
296- ) -> Result < Self :: FinishedStrat , BuilderError >
297- where
298- Sx2 : Data < Elem = Sd :: Elem > ,
299- {
300- let ( a, b) = self . calc_coefficients ( x, data) ?;
301- let extrapolate = if !self . extrapolate {
302- Extrapolate :: No
303- } else if matches ! ( self . boundary, BoundaryCondition :: Periodic ) {
304- Extrapolate :: Periodic
305- } else {
306- Extrapolate :: Yes
307- } ;
308- Ok ( CubicSplineStrategy { a, b, extrapolate } )
309- }
310- }
311-
312304impl < T , D > CubicSpline < T , D >
313305where
314306 D : Dimension + RemoveAxis ,
@@ -749,35 +741,44 @@ where
749741 }
750742}
751743
752- impl < T , D > Default for CubicSpline < T , D >
744+ impl < Sd , Sx , D > Interp1DStrategyBuilder < Sd , Sx , D > for CubicSpline < Sd :: Elem , D >
753745where
746+ Sd : Data ,
747+ Sd :: Elem : SplineNum ,
748+ Sx : Data < Elem = Sd :: Elem > ,
754749 D : Dimension + RemoveAxis ,
755- T : SplineNum ,
756750{
757- fn default ( ) -> Self {
758- Self :: new ( )
759- }
760- }
751+ const MINIMUM_DATA_LENGHT : usize = 3 ;
752+ type FinishedStrat = CubicSplineStrategy < Sd , D > ;
761753
762- #[ derive( Debug ) ]
763- enum Extrapolate {
764- Yes ,
765- No ,
766- Periodic ,
754+ fn build < Sx2 > (
755+ self ,
756+ x : & ArrayBase < Sx2 , Ix1 > ,
757+ data : & ArrayBase < Sd , D > ,
758+ ) -> Result < Self :: FinishedStrat , BuilderError >
759+ where
760+ Sx2 : Data < Elem = Sd :: Elem > ,
761+ {
762+ let ( a, b) = self . calc_coefficients ( x, data) ?;
763+ let extrapolate = if !self . extrapolate {
764+ Extrapolate :: No
765+ } else if matches ! ( self . boundary, BoundaryCondition :: Periodic ) {
766+ Extrapolate :: Periodic
767+ } else {
768+ Extrapolate :: Yes
769+ } ;
770+ Ok ( CubicSplineStrategy { a, b, extrapolate } )
771+ }
767772}
768773
769- /// The CubicSpline 1d interpolation Strategy (Implementation)
770- ///
771- /// This is constructed by [`CubicSpline`]
772- #[ derive( Debug ) ]
773- pub struct CubicSplineStrategy < Sd , D >
774+ impl < T , D > Default for CubicSpline < T , D >
774775where
775- Sd : Data ,
776776 D : Dimension + RemoveAxis ,
777+ T : SplineNum ,
777778{
778- a : Array < Sd :: Elem , D > ,
779- b : Array < Sd :: Elem , D > ,
780- extrapolate : Extrapolate ,
779+ fn default ( ) -> Self {
780+ Self :: new ( )
781+ }
781782}
782783
783784impl < Sd , Sx , D > Interp1DStrategy < Sd , Sx , D > for CubicSplineStrategy < Sd , D >
0 commit comments