/////////////////////////////////////////////////////////////////////////////
// Copyright 2004 The RenderMan Repository.  All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the
//   documentation and/or other materials provided with the distribution.
// * Neither the name of The RenderMan Repository nor the names of its contributors
//   may be used to endorse or promote products derived from this software
//   without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// "RenderMan" is a trademark of Pixar, Inc.
// "Gelato" is a trademark of NVIDIA Corporation
//
// (This is the Modified BSD License)
/////////////////////////////////////////////////////////////////////////////

#ifndef RSL2OSL_H
#define RSL2OSL_H

/*
 * Utils to ease conversion from rsl to osl
 * 
 */
#define PI M_PI

// access helpers
float comp (color c, float i) { return c[(int)i]; } 

//sometime people might pass in other tuples
float comp (vector v, float i) { return v[(int)i]; } 
float comp (normal n, float i) { return n[(int)i]; } 
float comp (point p, float i) { return p[(int)i]; } 

float comp (matrix m, float row, float col) 
{ 
    float val = m[(int)row][(int)col]; 
    return val;
}

float xcomp (point p) {return p[0]; }
float xcomp (vector v) {return v[0]; }
float xcomp (normal n) {return n[0]; }

float ycomp (point p) {return p[1]; }
float ycomp (vector v) {return v[1]; }
float ycomp (normal n) {return n[1]; }

float zcomp (point p) {return p[2]; }
float zcomp (vector v) {return v[2]; }
float zcomp (normal n) {return n[2]; }

void setcomp (output matrix m, float row, float col, float val) 
{
    m[(int)row][(int)col] = val;
}

float atan (float y, float x) { return atan2 (y, x); }
float filterstep (float a, float b) { return aastep (a, b); }
float ptlined (point P0, point P1, point Q) { return distance (P0, P1, Q); }

float Deriv(float a, float b)  { return Dx(a)/Dx(b) + Dy(a)/Dy(b); }
float Du (float t) { return Deriv (t, u); }
float Dv (float t) { return Deriv (t, v); }
point Deriv(point a, point b)  { return Dx(a)/Dx(b) + Dy(a)/Dy(b); }
point Du (point p) { return Deriv (p, u); }
point Dv (point p) { return Deriv (p, v); }

/* OSL doesn't support open ended min, max functions
 * Adding suport for 3 floats
 */

float min (float x, float y, float z)
{
    return min (x, min (y, z));
}

float max (float x, float y, float z)
{
    return max (x, max (y, z));
}

#endif /* RSL2OSL_H */
