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