1#![doc = include_str!("../README.md")]
2
3
4pub mod curfit;
8pub use curfit::*;
9
10pub mod concur;
11pub use concur::*;
12
13pub mod clocur;
14pub use clocur::*;
15
16pub mod dierckx_val;
17
18pub mod util;
19pub use util::*;
20
21use std::error;
22use std::fmt;
23pub type Result<T> = std::result::Result<T, Box<dyn error::Error>>;
28
29pub type LinearSplineFit = SplineCurveFit<1>;
31pub type CubicSplineFit = SplineCurveFit<3>;
32pub type QuinticSplineFit = SplineCurveFit<5>;
33
34
35pub type LinearSplineFit1D = ParameterSplineCurveFit<1,1>;
37pub type CubicSplineFit1D = ParameterSplineCurveFit<3,1>;
38pub type QuinticSplineFit1D = ParameterSplineCurveFit<5,1>;
39pub type LinearSplineFit2D = ParameterSplineCurveFit<1,2>;
40pub type CubicSplineFit2D = ParameterSplineCurveFit<3,2>;
41pub type QuinticSplineFit2D = ParameterSplineCurveFit<5,2>;
42pub type LinearSplineFit3D = ParameterSplineCurveFit<1,3>;
43pub type CubicSplineFit3D = ParameterSplineCurveFit<3,3>;
44pub type QuinticSplineFit3D = ParameterSplineCurveFit<5,3>;
45
46pub type ClosedLinearSplineFit2D = ClosedParameterSplineCurveFit<1,2>;
48pub type ClosedCubicSplineFit2D = ClosedParameterSplineCurveFit<3,2>;
49pub type ClosedQuinticSplineFit2D = ClosedParameterSplineCurveFit<5,2>;
50pub type ClosedLinearSplineFit3D = ClosedParameterSplineCurveFit<1,3>;
51pub type ClosedCubicSplineFit3D = ClosedParameterSplineCurveFit<3,3>;
52pub type ClosedQuinticSplineFit3D = ClosedParameterSplineCurveFit<5,3>;
53
54#[derive(Debug, Clone)]
55pub struct FitError(i32);
56
57impl FitError {
58 fn new(ierr: i32) -> Self { Self(ierr) }
59}
60
61impl fmt::Display for FitError {
62 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63 match self.0 {
64 -2 => write!(f, "normal return for weighted least squares spline, fp upper bound for smoothing factor"),
66 -1 => write!(f, "normal return for interpolating spline"),
67 0 => write!(f, "normal return"),
68 1 => write!(f, "out of storage space; nest too small (m/2); or s too small"),
69 2 => write!(f, "smoothing spline error, s too small"),
70 3 => write!(f, "reached iteration limit (20) for finding smoothing spline; s too small"),
71 10 => write!(f, "invalid input data; check if -1<=iopt<=1, 1<=k<=5, m>k, nest>2*k+2, w(i)>0,i=1,2,...,m xb<=x(1)<x(2)<...<x(m)<=xe, lwrk>=(k+1)*m+nest*(7+3*k)"),
72 200 => write!(f, "N should be between 1 and 10"),
74 201 => write!(f, "need at least 2 parameter values"),
75 202 => write!(f, "incorrect size of coordinate array xn"),
76 203 => write!(f, "wrong size for weights array"),
77 204 => write!(f, "too many derivative contraints supplied"),
78 205 => write!(f, "cardinal spline spacing too large: select smaller interval"),
79 206 => write!(f, "smoothing_spline not converged"),
80 207 => write!(f, "failed to initialize smoothing_spline"),
81 208 => write!(f, "K should be 1, 3 or 5"),
82 _ => write!(f, "unknown error"),
83 }
84 }
85}
86
87
88impl error::Error for FitError {}
89