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

shader
test ()
{
    int i = 5;
    float f = 6.5;
    point p = point (0.25, 0.5, 0.75);

    printf ("Testing basic typecasts:\n");
    float g = (float) i;
    printf (" (float)%d = %f\n", i, g);
    int j = (int) f;
    printf (" (int)%f = %d\n", f, j);

    color c = (color)p;
    printf (" (color) (point %g) = %g\n", p, c);

    printf ("\nTesting type constructors:\n");
    g = float(i);
    printf (" float(%d) = %f\n", i, g);
    j = int(f);
    printf (" int(%f) = %d\n", f, j);
    c = color(p);
    printf (" color(point %g) = %g\n", p, c);

    // Also test typecasts of array elements
    // point q[2] = { ... };
    // color c = (color) q[1];

    {
        printf ("\n varying:\n");
        int i = 5 + (int)u;
        float f = 6.5 + u;
        point p = point (0.25, 0.5, 0.75+u);

        float g = (float) i;
        printf (" (float)%d = %f\n", i, g);
        int j = (int) f;
        printf (" (int)%f = %d\n", f, j);

        color c = (color)p;
        printf (" (color) (point %g) = %g\n", p, c);

        g = float(i);
        printf (" float(%d) = %f\n", i, g);
        j = int(f);
        printf (" int(%f) = %d\n", f, j);
        c = color(p);
        printf (" color(point %g) = %g\n", p, c);

        // Also test typecasts of array elements
        // point q[2] = { ... };
        // color c = (color) q[1];
    }

    // Test some tricky cases -- these should not warn! The constructors
    // ought to be able to figure out the desired type of the ambiguous
    // function arguments.
    closure color result = diffuse(N) * float(cellnoise(u, v));
    color c1 = float(cellnoise(u,v));
    color c2 = color(cellnoise(u,v));
    color c3 = color(cellnoise(u,v),0.0,0.0);
    color c4 = c1 * cellnoise(u,v);
}
