Serenity Operating System
at master 35 lines 760 B view raw
1/* 2 * Copyright (c) 2022, Rodrigo Tobar <rtobarc@gmail.com>. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibPDF/Interpolation.h> 8 9namespace PDF { 10 11static float slope(float x_min, float x_max, float y_min, float y_max) 12{ 13 return (y_max - y_min) / (x_max - x_min); 14} 15 16LinearInterpolation1D::LinearInterpolation1D(float x_min, float x_max, float y_min, float y_max) 17 : m_x_min(x_min) 18 , m_y_min(y_min) 19 , m_slope(slope(x_min, x_max, y_min, y_max)) 20{ 21} 22 23float LinearInterpolation1D::interpolate(float x) const 24{ 25 return m_y_min + ((x - m_x_min) * m_slope); 26} 27 28void LinearInterpolation1D::interpolate(Span<float> const& x, Span<float> y) const 29{ 30 for (size_t i = 0; i < x.size(); ++i) { 31 y[i] = interpolate(x[i]); 32 } 33} 34 35}