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)
7 // This implements bilinear interpolation on a uniform grid.
8 // If dx and dy are both positive, then the (x,y) = (x0, y0) is associated with data index 0 (herein referred to as f[0])
9 // The point (x0 + dx, y0) is associated with f[1], and (x0 + i*dx, y0) is associated with f[i],
10 // i.e., we are assuming traditional C row major order.
11 // The y coordinate increases *downward*, as is traditional in 2D computer graphics.
12 // This is *not* how people generally think in numerical analysis (although it *is* how they lay out matrices).
13 // Providing the capability of a grid rotation is too expensive and not ergonomic; you'll need to perform any rotations at the call level.
15 // For clarity, the value f(x0 + i*dx, y0 + j*dy) must be stored in the f[j*cols + i] position.
17 #ifndef BOOST_MATH_INTERPOLATORS_BILINEAR_UNIFORM_HPP
18 #define BOOST_MATH_INTERPOLATORS_BILINEAR_UNIFORM_HPP
22 #include <boost/math/interpolators/detail/bilinear_uniform_detail.hpp>
24 namespace boost::math::interpolators {
26 template <class RandomAccessContainer>
27 class bilinear_uniform
30 using Real = typename RandomAccessContainer::value_type;
31 using Z = typename RandomAccessContainer::size_type;
33 bilinear_uniform(RandomAccessContainer && fieldData, Z rows, Z cols, Real dx = 1, Real dy = 1, Real x0 = 0, Real y0 = 0)
34 : m_imp(std::make_shared<detail::bilinear_uniform_imp<RandomAccessContainer>>(std::move(fieldData), rows, cols, dx, dy, x0, y0))
38 Real operator()(Real x, Real y) const
40 return m_imp->operator()(x,y);
44 friend std::ostream& operator<<(std::ostream& out, bilinear_uniform<RandomAccessContainer> const & bu) {
50 std::shared_ptr<detail::bilinear_uniform_imp<RandomAccessContainer>> m_imp;