bezier_polynomial.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright Nick Thompson, 2021
  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_BEZIER_POLYNOMIAL_HPP
  7. #define BOOST_MATH_INTERPOLATORS_BEZIER_POLYNOMIAL_HPP
  8. #include <memory>
  9. #include <boost/math/interpolators/detail/bezier_polynomial_detail.hpp>
  10. #ifdef BOOST_MATH_NO_THREAD_LOCAL_WITH_NON_TRIVIAL_TYPES
  11. #warning "Thread local storage support is necessary for the Bezier polynomial class to work."
  12. #endif
  13. namespace boost::math::interpolators {
  14. template <class RandomAccessContainer>
  15. class bezier_polynomial
  16. {
  17. public:
  18. using Point = typename RandomAccessContainer::value_type;
  19. using Real = typename Point::value_type;
  20. using Z = typename RandomAccessContainer::size_type;
  21. bezier_polynomial(RandomAccessContainer && control_points)
  22. : m_imp(std::make_shared<detail::bezier_polynomial_imp<RandomAccessContainer>>(std::move(control_points)))
  23. {
  24. }
  25. inline Point operator()(Real t) const
  26. {
  27. return (*m_imp)(t);
  28. }
  29. inline Point prime(Real t) const
  30. {
  31. return m_imp->prime(t);
  32. }
  33. void edit_control_point(Point const & p, Z index)
  34. {
  35. m_imp->edit_control_point(p, index);
  36. }
  37. RandomAccessContainer const & control_points() const
  38. {
  39. return m_imp->control_points();
  40. }
  41. friend std::ostream& operator<<(std::ostream& out, bezier_polynomial<RandomAccessContainer> const & bp) {
  42. out << *bp.m_imp;
  43. return out;
  44. }
  45. private:
  46. std::shared_ptr<detail::bezier_polynomial_imp<RandomAccessContainer>> m_imp;
  47. };
  48. }
  49. #endif