spline_unit_test
 All Classes Functions Enumerations
cSpline.h
1 /*
2  * Copyright (c) 2014 by James Bremner
3  * All rights reserved.
4  *
5  * Use license: Modified from standard BSD license.
6  *
7  * Redistribution and use in source and binary forms are permitted
8  * provided that the above copyright notice and this paragraph are
9  * duplicated in all such forms and that any documentation, advertising
10  * materials, Web server pages, and other materials related to such
11  * distribution and use acknowledge that the software was developed
12  * by James Bremner. The name "James Bremner" may not be used to
13  * endorse or promote products derived from this software without
14  * specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 */
20 
21 #include <functional>
22 #include <vector>
23 
24 namespace raven
25 {
26 
28 class cSpline
29 {
30 
31 public:
32 
41  cSpline(
42  std::vector< double >& x,
43  std::vector< double >& y );
44 
49  bool IsSane() { return (bool) ! myError; }
50 
52  enum e_error
53  {
54  no_error,
55  x_not_ascending,
56  no_input,
57  not_single_valued,
58  } myError;
59 
65  e_error IsError() { return myError; }
66 
89  void Draw( std::function<void (double x, double y)> func,
90  int resolution = 100 );
91 
99  double getY( double x);
100 
101 private:
102 
103  // The fitted points
104  std::vector< double > myX;
105  std::vector< double > myY;
106 
108  struct SplineSet
109  {
110  double a; // constant
111  double b; // 1st order coefficient
112  double c; // 2nd order coefficient
113  double d; // 3rd order coefficient
114  double x; // starting x value
115  };
116 
118  std::vector< SplineSet > mySplineSet;
119 
121  double myMinUniqueDelta;
122 
123  bool IsInputSane();
124 
125 };
126 };
void Draw(std::function< void(double x, double y)> func, int resolution=100)
Definition: cSpline.cpp:100
Definition: cSpline.h:28
e_error
error numbers
Definition: cSpline.h:52
e_error IsError()
Definition: cSpline.h:65
bool IsSane()
Definition: cSpline.h:49
cSpline(std::vector< double > &x, std::vector< double > &y)
Definition: cSpline.cpp:40
double getY(double x)
Definition: cSpline.cpp:112