cardinal_quintic_b_spline.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef BOOST_MATH_INTERPOLATORS_CARDINAL_QUINTIC_B_SPLINE_HPP
  7. #define BOOST_MATH_INTERPOLATORS_CARDINAL_QUINTIC_B_SPLINE_HPP
  8. #include <memory>
  9. #include <limits>
  10. #include <boost/math/interpolators/detail/cardinal_quintic_b_spline_detail.hpp>
  11. namespace boost{ namespace math{ namespace interpolators {
  12. template <class Real>
  13. class cardinal_quintic_b_spline
  14. {
  15. public:
  16. // If you don't know the value of the derivative at the endpoints, leave them as nans and the routine will estimate them.
  17. // y[0] = y(a), y[n - 1] = y(b), step_size = (b - a)/(n -1).
  18. cardinal_quintic_b_spline(const Real* const y,
  19. size_t n,
  20. Real t0 /* initial time, left endpoint */,
  21. Real h /*spacing, stepsize*/,
  22. std::pair<Real, Real> left_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()},
  23. std::pair<Real, Real> right_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()})
  24. : impl_(std::make_shared<detail::cardinal_quintic_b_spline_detail<Real>>(y, n, t0, h, left_endpoint_derivatives, right_endpoint_derivatives))
  25. {}
  26. // Oh the bizarre error messages if we template this on a RandomAccessContainer:
  27. cardinal_quintic_b_spline(std::vector<Real> const & y,
  28. Real t0 /* initial time, left endpoint */,
  29. Real h /*spacing, stepsize*/,
  30. std::pair<Real, Real> left_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()},
  31. std::pair<Real, Real> right_endpoint_derivatives = {std::numeric_limits<Real>::quiet_NaN(), std::numeric_limits<Real>::quiet_NaN()})
  32. : impl_(std::make_shared<detail::cardinal_quintic_b_spline_detail<Real>>(y.data(), y.size(), t0, h, left_endpoint_derivatives, right_endpoint_derivatives))
  33. {}
  34. Real operator()(Real t) const {
  35. return impl_->operator()(t);
  36. }
  37. Real prime(Real t) const {
  38. return impl_->prime(t);
  39. }
  40. Real double_prime(Real t) const {
  41. return impl_->double_prime(t);
  42. }
  43. Real t_max() const {
  44. return impl_->t_max();
  45. }
  46. private:
  47. std::shared_ptr<detail::cardinal_quintic_b_spline_detail<Real>> impl_;
  48. };
  49. }}}
  50. #endif