From 3c03d6d76e61c5b4bcd4e8ab925641c9d62fd25e Mon Sep 17 00:00:00 2001 From: Matt Spraggs Date: Mon, 23 Nov 2015 13:57:19 +0000 Subject: [PATCH] Examples: Added example for nearest interpolation algorithm. --- examples/exInterp.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/exInterp.cpp b/examples/exInterp.cpp index 81224fa..0b560f3 100644 --- a/examples/exInterp.cpp +++ b/examples/exInterp.cpp @@ -29,10 +29,23 @@ int main(int argc, char* argv[]) auto tab = Latan::TabFunction(xs, ys, Latan::InterpType::QUADRATIC); - std::cout << "Interpolating naive y = x^2 data..." << std::endl; + std::cout << "Interpolating naive y = x^2 data using quadratic "; + std::cout << "interpolation..." << std::endl; for (double x = -1.0; x < 1.0; x += 0.1) { double y = tab(&x); std::cout << "y @ " << x << " = " << y; std::cout << " ( " << x * x << " expected)" << std::endl; } + std::cout << std::endl; + + tab = Latan::TabFunction(xs, ys, Latan::InterpType::NEAREST); + + std::cout << "Interpolating naive y = x^2 data using nearest "; + std::cout << "interpolation..." << std::endl; + for (double x = -1.0; x < 1.0; x += 0.1) { + double y = tab(&x); + std::cout << "y @ " << x << " = " << y; + double expected = (x > 0.5) ? 1.0 : ((x <= -0.5) ? 1.0 : 0.0); + std::cout << " ( " << expected << " expected)" << std::endl; + } } \ No newline at end of file