Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / math / interpolators / cardinal_quintic_b_spline.hpp
1 // Copyright Nick Thompson, 2019
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_MATH_INTERPOLATORS_CARDINAL_QUINTIC_B_SPLINE_HPP
8 #define BOOST_MATH_INTERPOLATORS_CARDINAL_QUINTIC_B_SPLINE_HPP
9 #include <memory>
10 #include <limits>
11 #include <boost/math/interpolators/detail/cardinal_quintic_b_spline_detail.hpp>
12
13
14 namespace boost{ namespace math{ namespace interpolators {
15
16 template <class Real>
17 class cardinal_quintic_b_spline
18 {
19 public:
20     // If you don't know the value of the derivative at the endpoints, leave them as nans and the routine will estimate them.
21     // y[0] = y(a), y[n - 1] = y(b), step_size = (b - a)/(n -1).
22     cardinal_quintic_b_spline(const Real* const y,
23                                 size_t n,
24                                 Real t0 /* initial time, left endpoint */,
25                                 Real h  /*spacing, stepsize*/,
26                                 std::pair<Real, Real> left_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()},
27                                 std::pair<Real, Real> right_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()})
28      : impl_(std::make_shared<detail::cardinal_quintic_b_spline_detail<Real>>(y, n, t0, h, left_endpoint_derivatives, right_endpoint_derivatives))
29     {}
30
31     // Oh the bizarre error messages if we template this on a RandomAccessContainer:
32     cardinal_quintic_b_spline(std::vector<Real> const & y,
33                                 Real t0 /* initial time, left endpoint */,
34                                 Real h  /*spacing, stepsize*/,
35                                 std::pair<Real, Real> left_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()},
36                                 std::pair<Real, Real> right_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()})
37      : impl_(std::make_shared<detail::cardinal_quintic_b_spline_detail<Real>>(y.data(), y.size(), t0, h, left_endpoint_derivatives, right_endpoint_derivatives))
38     {}
39
40
41     Real operator()(Real t) const {
42         return impl_->operator()(t);
43     }
44
45     Real prime(Real t) const {
46        return impl_->prime(t);
47     }
48
49     Real double_prime(Real t) const {
50         return impl_->double_prime(t);
51     }
52
53     Real t_max() const {
54         return impl_->t_max();
55     }
56
57 private:
58     std::shared_ptr<detail::cardinal_quintic_b_spline_detail<Real>> impl_;
59 };
60
61 }}}
62 #endif