xref: /haiku/headers/libs/agg/agg_bspline.h (revision 95bac3fda53a4cb21880712d7b43f8c21db32a2e)
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.2
3 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 //          mcseemagg@yahoo.com
13 //          http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 //
16 // class bspline
17 //
18 //----------------------------------------------------------------------------
19 
20 #ifndef AGG_BSPLINE_INCLUDED
21 #define AGG_BSPLINE_INCLUDED
22 
23 #include "agg_basics.h"
24 
25 namespace agg
26 {
27     //----------------------------------------------------------------bspline
28     // A very simple class of Bi-cubic Spline interpolation.
29     // First call init(num, x[], y[]) where num - number of source points,
30     // x, y - arrays of X and Y values respectively. Here Y must be a function
31     // of X. It means that all the X-coordinates must be arranged in the ascending
32     // order.
33     // Then call get(x) that calculates a value Y for the respective X.
34     // The class supports extrapolation, i.e. you can call get(x) where x is
35     // outside the given with init() X-range. Extrapolation is a simple linear
36     // function.
37     //
38     //  See Implementation agg_bspline.cpp
39     //------------------------------------------------------------------------
40     class bspline
41     {
42     public:
43         ~bspline();
44         bspline();
45         bspline(int num);
46         bspline(int num, const double* x, const double* y);
47 
48         void   init(int num);
49         void   add_point(double x, double y);
50         void   prepare();
51 
52         void   init(int num, const double* x, const double* y);
53 
54         double get(double x) const;
55         double get_stateful(double x) const;
56 
57     private:
58         bspline(const bspline&);
59         const bspline& operator = (const bspline&);
60 
61         static void bsearch(int n, const double *x, double x0, int *i);
62         double extrapolation_left(double x) const;
63         double extrapolation_right(double x) const;
64         double interpolation(double x, int i) const;
65 
66         int     m_max;
67         int     m_num;
68         double* m_x;
69         double* m_y;
70         double* m_am;
71         mutable int m_last_idx;
72     };
73 
74 
75 }
76 
77 #endif
78