// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage


void s (string basis, float y, float knots[])
{
    float x;
    x = splineinverse (basis, y, knots);
    printf ("splineinverse(\"%s\", %g) = %g  (derivs %g %g)\n",
            basis, y, x, Dx(x), Dy(x));
    float y2 = spline (basis, x, knots);
    printf ("spline(\"%s\",%g) = %g   (derivs %g %g)\n",
            basis, x, y, Dx(y), Dy(y));
    if (fabs(y-y2) > 0.0001)
        printf ("ERR! splineinverse doesn't appear to work\n");
    printf ("  spline(\"%s\",%g) = %g\n", basis, 0.0, spline(basis,0.0,knots));
    printf ("  spline(\"%s\",%g) = %g\n", basis, 1.0, spline(basis,1.0,knots));
    printf ("\n");
}



shader test ()
{
    float knots[7] = { 0, 0, 0.05, 0.1, 0.3, 1, 1 };

    printf ("u = %g  (derivs %g %g)\n", u, Dx(u), Dy(u));
    s ("linear", u, knots);
    s ("catmull-rom", u, knots);
    s ("bspline", u, knots);
}
