// __author__ = Juan Carlos De Abreu (jcabreur@gmail.com)

#ifndef MATH_PLANE_INL_H__
#define MATH_PLANE_INL_H__

#include "Plane.h"

BEGIN_TEG_NAMESPACE();

// 
namespace math {

// Assign operator between two planes
__forceinline void Plane::operator = (const Plane& p) {
	memcpy(values, p.values, sizeof(values));
}

// 
__forceinline void Plane::setPlaneNormal(float a_, float b_, float c_) {
   a = a_; b = b_; c = c_;	// Simply set the data members.
}

// 
__forceinline void Plane::setPlaneIntercept(float D) {
	d = D;	// Set only d.
}

// Method to get the module of the normal of the plane
__forceinline float Plane::module() {
	return ::sqrt(a*a + b*b + c*c);
}

// Method to normalize the normal of the plane
__forceinline void Plane::normalize() {
	const float mod = 1.0f / module();
	a *= mod; b *= mod; c *= mod; d *= mod;
}

// Function to get the distance between a plane and a point 
__forceinline float getDistance(const Plane& p, const Vec3f& v) {
   // Simply perform a dot product of the point and the plane.
   return p.a * v.x + p.b * v.y + p.c * v.z + p.d;
}

}; // Namespace math

END_TEG_NAMESPACE();

#endif  // MATH_PLANE_INL_H__
