#ifndef __CUVECT2F_HPP__
#define __CUVECT2F_HPP__

namespace amscuda
{

    class cuvect2f
    {
        public:
        float x;
        float y;

        __host__ __device__ cuvect2f();
        __host__ __device__ ~cuvect2f();
        __host__ __device__ cuvect2f(const float &_x, const float &_y);
        
        
        __host__ __device__ float& operator[](const int &I);
        __host__ __device__ const float& operator[](const int &I) const;

        __host__ __device__ cuvect2f operator+(const cuvect2f &rhs);
        __host__ __device__ cuvect2f operator-(const cuvect2f &rhs);
        __host__ __device__ cuvect2f operator*(const float &rhs);
        __host__ __device__ cuvect2f operator/(const float &rhs);
        __host__ __device__ friend cuvect2f operator-(const cuvect2f &rhs);

        __host__ __device__ cuvect2f& operator+=(const cuvect2f &rhs);
        __host__ __device__ cuvect2f& operator-=(const cuvect2f &rhs);
        __host__ __device__ cuvect2f& operator/=(const float &rhs);
        __host__ __device__ cuvect2f& operator*=(const float &rhs);

    };

    class cumat2f
    {
        public:
        float m00,m10; //named references to force register use?
        float m01,m11; //switched to column-major-order to match GLSL/lapack

        __host__ __device__ cumat2f();
        __host__ __device__ ~cumat2f();

        __host__ __device__ cumat2f(
            const float & _m00, const float & _m01,
            const float & _m10, const float & _m11
        );

        __host__ __device__ float& operator[](const int &I);
        __host__ __device__ float& operator()(const int &I, const int &J);
        __host__ __device__ float& at(const int &I, const int &J);

        __host__ __device__ const float& operator[](const int &I) const;
        __host__ __device__ const float& operator()(const int &I, const int &J) const;
        __host__ __device__ const float& at(const int &I, const int &J) const;

        __host__ __device__ cumat2f operator+(const cumat2f &rhs);
        __host__ __device__ cumat2f operator-(const cumat2f &rhs);
        __host__ __device__ cumat2f operator*(const float &rhs);
        __host__ __device__ cumat2f operator/(const float &rhs);
        __host__ __device__ cuvect2f operator*(const cuvect2f &rhs);
        __host__ __device__ cumat2f operator*(const cumat2f &rhs);
        __host__ __device__ friend cumat2f operator-(const cumat2f &rhs);
        
        __host__ __device__ float det();
        __host__ __device__ cumat2f transpose();
        __host__ __device__ cumat2f inverse();

        __host__ __device__ float* data(); //pointer to float[9] representation of matrix
        __host__ __device__ const float* data() const; //pointer to float[9] representation of matrix

        //In place operations (to save GPU register use)
        __host__ __device__ cumat2f& operator+=(const cumat2f &rhs);
        __host__ __device__ cumat2f& operator-=(const cumat2f &rhs);
        __host__ __device__ cumat2f& operator/=(const float &rhs);
        __host__ __device__ cumat2f& operator*=(const float &rhs);
        __host__ __device__ cumat2f& operator*=(const cumat2f &rhs);
    };

    __host__ __device__ float cuvect2f_dot(const cuvect2f &a, const cuvect2f &b);
    __host__ __device__ float cuvect2f_cross(const cuvect2f &a, const cuvect2f &b);
    __host__ __device__ float cuvect2f_norm(const cuvect2f &a);
    __host__ __device__ cuvect2f cuvect2f_normalize(const cuvect2f &a);
    __host__ __device__ cuvect2f cuvect2f_proj(const cuvect2f &a, const cuvect2f &b);

    __host__ __device__ cumat2f mat2f_rot_from_angle(const cuvect3f &axis, const float &angle);

    //2x2 matrix operations
    //matrix order is assumed to be mat[I,J] = mat[I+3*J]

    //transpose a 2x2 matrix in place
    __host__ __device__ void mat2f_transpose(float *mat2inout);
    
    //copies src to dest
    __host__ __device__ void mat2f_copy(float *mat2f_dest, const float *mat2f_src);
    
    //inverts mat?inout[4]
    __host__ __device__ void mat2f_inverse(float *mat2inout);
    
    //rotatin matrix from angle
    __host__ __device__ void mat2f_rot_from_angle(float angle, float *mat2);

    //multiplies c = a*b
    __host__ __device__ void mat2f_mult(float *mat2a, float *mat2b, float *mat2c);

    // ret = a*b
    __host__ __device__ cuvect2f mat2f_mult(float *mat2a, const cuvect2f &b);


    void test_cuvect2f_1();


};

#endif

