#ifndef TRIPLET_HXX
# define TRIPLET_HXX
# ifndef STDCXX_HXX
#  include <stdcxx.hxx>
# endif


class triplet	{
	public:
	double x, y, z;
	triplet(double xx, double yy, double zz)	{x=xx; y=yy; z=zz;}
	triplet(C triplet& a)	{x=a.x;y=a.y;z=a.z;}
	triplet()	{x = y = z = 0.0;}
	triplet operator=(C triplet& a)	{x=a.x; y=a.y; z=a.z; return *this;}
	C triplet& operator+=(C triplet& a) {x+=a.x; y+=a.y; z+=a.z; return *this;}
	C triplet& operator-=(C triplet& a) {x-=a.x; y-=a.y; z-=a.z; return *this;}
	};

inline BOOL operator==(C triplet& a, C triplet& b);
inline BOOL operator!=(C triplet& a, C triplet& b);
inline triplet operator-(C triplet& a, C triplet& b);
inline triplet operator+(C triplet& a, C triplet& b);
inline triplet operator*(double a, C triplet& b);
inline triplet operator*(C triplet& b, double a);
inline triplet operator/(C triplet& b, double a);
triplet rotate(C triplet& a, double theta, double phi, double psi);
triplet rotate(C triplet& a, C triplet& axis, double theta);
inline triplet perspect(C triplet& a, double dist);
inline triplet perspect(C triplet& a, C triplet& dist);
inline double operator*(C triplet& x, C triplet& y);	// dot product
inline double norm(C triplet& a);
double abs(C triplet& a);



/* inline bodies */
inline  triplet perspect(triplet& a, triplet& dist)
{
return triplet((a.x+dist.x)/(a.z+dist.z), (a.y+dist.y)/(a.z+dist.z), 0.0);
}

inline triplet perspect(C triplet& a, double dist)
	{//printf("persp(%g, %g, %g) ", a.x, a.y, a.z);
	return triplet(a.x/(dist+a.z), a.y/(dist+a.z), 0.0);}

inline triplet operator-(C triplet& a, C triplet& b)
	{return triplet(a.x-b.x, a.y-b.y, a.z-b.z);}
inline triplet operator+(C triplet& a, C triplet& b)
	{return triplet(a.x+b.x, a.y+b.y, a.z+b.z);}
inline triplet operator*(double a, C triplet& b)
	{return triplet(a*b.x, a*b.y, a*b.z);}
inline triplet operator*(C triplet& b, double a)
	{return triplet(a*b.x, a*b.y, a*b.z);}
inline double operator*(C triplet& x, C triplet& y)
{ return x.x*y.x + x.y*y.y + x.z*y.z; }

inline double norm(C triplet& a)
{ return a.x*a.x+a.y*a.y+a.z*a.z; }

inline triplet operator/(C triplet& b, double a)
{ return triplet(b.x/a, b.y/a, b.z/a);}

inline BOOL operator==(C triplet& a, C triplet& b)
{ return a.x==b.x && a.y==b.y && a.z==b.z; }

inline BOOL operator!=(C triplet& a, C triplet& b)
{ return !(a==b);}
#endif
