///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2008 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2007-03-05
// Updated : 2007-03-05
// Licence : This source is under MIT License
// File    : glm/gtx/vector_query.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
// Dependency:
// - GLM core
///////////////////////////////////////////////////////////////////////////////////////////////////

#include <cassert>

namespace glm
{
	template <typename T>
	inline bool areCollinearGTX(const detail::tvec2<T>& v0, const detail::tvec2<T>& v1, const T epsilon)
	{
		return length(cross(detail::tvec3<T>(v0, T(0)), detail::tvec3<T>(v1, T(0)))) < epsilon;
	}

	template <typename T>
	inline bool areCollinearGTX(const detail::tvec3<T>& v0, const detail::tvec3<T>& v1, const T epsilon)
	{
		return length(cross(v0, v1)) < epsilon;
	}

	template <typename T>
	inline bool areCollinearGTX(const detail::tvec4<T>& v0, const detail::tvec4<T>& v1, const T epsilon)
	{
		return length(cross(detail::tvec3<T>(v0), detail::tvec3<T>(v1))) < epsilon;
	}

	template <typename genType>
	inline bool areOppositeGTX(const genType& v0, const genType& v1, const GLMvalType epsilon)
	{
		assert(isNormalized(v0) && isNormalized(v1));
        return((genType::value_type(1) + dot(v0, v1)) <= epsilon);
	}
/*
	template <typename T>
	inline bool areOppositeGTX(const tvec2<T>& v0, const tvec2<T>& v1, const T epsilon)
	{
		assert(isNormalized(v0) && isNormalized(v1));
		return((T(1) + dot(v0, v1)) <= epsilon);
	}

	template <typename T>
	inline bool areOppositeGTX(const tvec3<T>& v0, const tvec3<T>& v1, const T epsilon)
	{
		assert(isNormalized(v0) && isNormalized(v1));
		return((T(1) + dot(v0, v1)) <= epsilon);
	}

	template <typename T>
	inline bool areOppositeGTX(const tvec4<T>& v0, const tvec4<T>& v1, const T epsilon)
	{
		assert(isNormalized(v0) && isNormalized(v1));
		return((T(1) + dot(v0, v1)) <= epsilon);
	}
*/
	template <typename genType>
	inline bool areOrthogonalGTX(const genType& v0, const genType& v1, const GLMvalType epsilon)
	{
		return abs(dot(v0, v1)) <= max(GLMvalType(1), length(v0)) * max(GLMvalType(1), length(v1)) * epsilon;
	}
/*
	template <typename T>
	inline bool areOrthogonalGTX(const tvec2<T>& v0, const tvec2<T>& v1, const T epsilon)
	{
		return abs(dot(v0, v1)) <= max(T(1), length(v0)) * max(T(1), length(v1)) * epsilon;
	}

	template <typename T>
	inline bool areOrthogonalGTX(const tvec3<T>& v0, const tvec3<T>& v1, const T epsilon)
	{
		return abs(dot(v0, v1)) <= max(T(1), length(v0)) * max(T(1), length(v1)) * epsilon;
	}

	template <typename T>
	inline bool areOrthogonalGTX(const tvec4<T>& v0, const tvec4<T>& v1, const T epsilon)
	{
		return abs(dot(v0, v1)) <= max(T(1), length(v0)) * max(T(1), length(v1)) * epsilon;
	}
*/

	template <typename genType> 
	inline bool isNormalizedGTX(const genType& v, const GLMvalType epsilon)
	{
		return abs(length(v) - GLMvalType(1)) <= GLMvalType(2) * epsilon;
	}
/*
	template <typename T> 
	inline bool isNormalizedGTX(const tvec2<T>& v, const T epsilon)
	{
		return abs(length(v) - T(1)) <= T(2) * epsilon;
	}

	template <typename T> 
	inline bool isNormalizedGTX(const tvec3<T>& v, const T epsilon)
	{
		return abs(length(v) - T(1)) <= T(2) * epsilon;
	}

	template <typename T> 
	inline bool isNormalizedGTX(const tvec4<T>& v, const T epsilon)
	{
		return abs(length(v) - T(1)) <= T(2) * epsilon;
	}
*/
	template <typename genType> 
	inline bool isNullGTX(const genType& v, const GLMvalType epsilon)
	{
		return length(v) <= epsilon;
	}
/*
	template <typename T> 
	inline bool isNullGTX(const tvec2<T>& v, const T epsilon)
	{
		return length(v) <= epsilon;
	}

	template <typename T> 
	inline bool isNullGTX(const tvec3<T>& v, const T epsilon)
	{
		return length(v) <= epsilon;
	}

	template <typename T> 
	inline bool isNullGTX(const tvec4<T>& v, const T epsilon)
	{
		return length(v) <= epsilon;
	}
*/

    template <typename T> 
    inline bool isCompNullGTX(const T s, const T epsilon)
    {
        return abs(s) < epsilon;
    }

    template <typename T> 
    inline detail::tvec2<bool> isCompNullGTX(const detail::tvec2<T>& v, const T epsilon)
    {
        return detail::tvec2<bool>(
            (abs(v.x) < epsilon),
            (abs(v.y) < epsilon));
    }

    template <typename T> 
    inline detail::tvec3<bool> isCompNullGTX(const detail::tvec3<T>& v, const T epsilon)
    {
        return detail::tvec3<bool>(
            abs(v.x) < epsilon,
            abs(v.y) < epsilon,
            abs(v.z) < epsilon);
    }

    template <typename T> 
    inline detail::tvec4<bool> isCompNullGTX(const detail::tvec4<T>& v, const T epsilon)
    {
        return detail::tvec4<bool>(
            abs(v.x) < epsilon,
            abs(v.y) < epsilon,
            abs(v.z) < epsilon,
            abs(v.w) < epsilon);
    }

	template <typename genType>
	inline bool areOrthonormalGTX(const genType& v0, const genType& v1, const GLMvalType epsilon)
	{
		return isNormalizedGTX(v0) && isNormalizedGTX(v1) && (abs(dot(v0, v1)) <= epsilon);
	}

/*
	template <typename T>
	inline bool areOrthonormalGTX(const tvec2<T>& v0, const tvec2<T>& v1, const T epsilon)
	{
		return isNormalizedGTX(v0) && isNormalizedGTX(v1) && (abs(dot(v0, v1)) <= epsilon);
	}

	template <typename T>
	inline bool areOrthonormalGTX(const tvec3<T>& v0, const tvec3<T>& v1, const T epsilon)
	{
		return isNormalizedGTX(v0) && isNormalizedGTX(v1) && (abs(dot(v0, v1)) <= epsilon);
	}

	template <typename T>
	inline bool areOrthonormalGTX(const tvec4<T>& v0, const tvec4<T>& v1, const T epsilon)
	{
		return isNormalizedGTX(v0) && isNormalizedGTX(v1) && (abs(dot(v0, v1)) <= epsilon);
	}
*/

	template <typename genType>
	inline bool areSimilarGTX(const genType& v0, const genType& v1, const GLMvalType epsilon)
	{
		bool similar = true;
        for(typename genType::size_type i = 0; similar && i < genType::value_size(); i++)
			similar = (abs(v0[i] - v1[i]) <= epsilon);
		return similar;
	}

/*
	template <typename T>
	inline bool areSimilar(const tvec2<T>& v0, const tvec2<T>& v1, const T epsilon)
	{
		bool similar = true;
		for(int i = 0; similar && i < 2; i++)
			similar = (abs(v0[i] - v1[i]) <= epsilon);
		return similar;
	}

	template <typename T> 
	inline bool areSimilar(const tvec3<T>& v0, const tvec3<T>& v1, const T epsilon)
	{
		bool similar = true;
		for(int i = 0; similar && i < 3; i++)
			similar = (abs(v0[i] - v1[i]) <= epsilon);
		return similar;
	}

	template <typename T>
	inline bool areSimilar(const tvec4<T>& v0, const tvec4<T>& v1, const T epsilon)
	{
		bool similar = true;
		for(int i = 0; similar && i < 4; i++)
			similar = (abs(v0[i] - v1[i]) <= epsilon);
		return similar;
	}
*/
}
