cardinal_quadratic_b_spline.hpp 2.3 KB

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