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

#include "../common/shaders/pretty.h"


void all_transforms (point p, string to, int derivs)
{
    printf ("\ntransform to '%s':\n", to);
    if (derivs)
        printf ("  p = %g, Dx(p) = %g, Dy(p) = %.5g\n", p, Dx(p), Dy(p));
    point px = transform (to, (point)p);
    printf (" transform(\"%s\", point(%g)) = %.5g\n", to, p, px);
    if (derivs)
        printf ("  derivs of transform(\"%s\", point(%g)): Dx = %g, Dy = %g\n", 
                to, p, Dx(px), Dy(px));
    vector vx = transform (to, (vector)p);
    printf (" transform(\"%s\", vector(%g)) = %.5g\n", to, p, vx);
    if (derivs)
        printf ("  derivs of transform(\"%s\", vector(%g)): Dx = %g, Dy = %g\n",
                to, p, Dx(vx), Dy(vx));
    printf (" transform(\"%s\", normal(%g)) = %.5g\n", to,
            p, transform(to, (normal)p));
}



void all_transforms (point p, string from, string to)
{
    printf ("\ntransform '%s' to '%s':\n", from, to);
    printf (" transform(\"%s\", \"%s\", point(%g)) = %.5g\n", from, to,
            p, pretty(transform(from, to, (point)p)));
    printf (" transform(\"%s\", \"%s\", vector(%g)) = %.5g\n", from, to,
            p, pretty(transform(from, to, (vector)p)));
    printf (" transform(\"%s\", \"%s\", normal(%g)) = %.5g\n", from, to,
            p, pretty(transform(from, to, (normal)p)));
}



void do_test (point z, point p, int derivs)
{
    all_transforms (p, "shader", 1);
    all_transforms (z, "shader", 0);

    all_transforms (p, "common", "shader");
    all_transforms (z, "common", "shader");

    all_transforms (p, "shader", "common");
    all_transforms (z, "shader", "common");

    all_transforms (p, "shader", "object");
    all_transforms (z, "shader", "object");
}



shader
test ()
{
    point z = point (0, 0, 0);
    point p = point (1, 1.41421, 0);
    do_test (z, p, 0);

    printf ("\n\n varying:\n\n");
    p += vector (u, v, 0);
    do_test (z, p, 1);
}
