#ifndef _Plane_h
#define _Plane_h

#include "Point.h"

struct PlaneIntersection {
	PlaneIntersection( ) : intersection( false ) { }
	PlaneIntersection( const Point & _point ) : intersection( true ), point( _point ) { }
	bool intersection;
	Point point;
};

class Plane {
public:
	Plane( ) { }
	Plane( Point _n, float _d ) : n( _n ), d( _d ) { this->n.Normalize( ); }
	inline float Distance( const Point & p ) const {
		return DotProduct( this->n, p ) - this->d;
	}
	inline const Point & GetNormal( ) const {
		return this->n;
	}
	inline float GetDistance( ) const {
		return this->d;
	}
	float Intersect( const Ray & ray ) const;
	float Intersect( const LineSegment & line ) const;
	friend PlaneIntersection PlanePlanePlaneIntersection( const Plane & p1, const Plane & p2, const Plane & p3 );
private:
	Point n;
	float d;
};

#endif
