#ifndef POINT_T_H #define POINT_T_H #include template struct point_t { point_t(T a=0, T b=0, T c=0); point_t(const point_t&P); ~point_t(); point_t& operator += (const point_t&P); point_t& operator -= (const point_t&P); point_t operator + (const point_t&P) const; point_t operator - (const point_t&P) const; T operator * (const point_t&P) const; point_t& neg(); point_t operator - () const; point_t& operator *= (T d); point_t& operator /= (T d); point_t& operator += (T d); point_t& operator -= (T d); point_t operator * (T d) const; point_t operator / (T d) const; point_t operator + (T d) const; point_t operator - (T d) const; point_t cross(const point_t&P) const; T mag() const; T mag2() const; point_t& make_unit(); point_t ret_unit() const; T x, y, z; }; typedef point_t point3ld; typedef point_t point3d; typedef point_t point3f; template point_t operator * (T d, const point_t& P); template point_t operator / (T d, const point_t& P); template point_t operator + (T d, const point_t& P); template point_t operator - (T d, const point_t& P); template inline point_t::point_t(T a, T b, T c) { x=a; y=b; z=c; } template inline point_t::point_t(const point_t&P) { x=P.x; y=P.y; z=P.z; } template inline point_t::~point_t() {} template inline point_t& point_t::operator += (const point_t&P) { x += P.x; y += P.y; z += P.z; return *this; } template inline point_t& point_t::operator -= (const point_t&P) { x -= P.x; y -= P.y; z -= P.z; return *this; } template inline point_t point_t::operator + (const point_t&P) const { return point_t(*this) += P; } template inline point_t point_t::operator - (const point_t&P) const { return point_t(*this) -= P; } template inline T point_t::operator * (const point_t&P) const { return x * P.x + y * P.y + z * P.z; } template inline point_t& point_t::neg() { x = -x; y = -y; z = -z; return *this; } template inline point_t point_t::operator - () const { return point_t(*this).neg(); } template inline point_t& point_t::operator *= (T d) { x *= d; y *= d; z *= d; return *this; } template inline point_t& point_t::operator /= (T d) { x /= d; y /= d; z /= d; return *this; } template inline point_t& point_t::operator += (T d) { x += d; y += d; z += d; return *this; } template inline point_t& point_t::operator -= (T d) { x -= d; y -= d; z -= d; return *this; } template inline point_t point_t::operator + (T d) const { return point_t(*this) += d; } template inline point_t point_t::operator - (T d) const { return point_t(*this) -= d; } template inline point_t point_t::operator * (T d) const { return point_t(*this) *= d; } template inline point_t point_t::operator / (T d) const { return point_t(*this) /= d; } template inline point_t operator * (T d, const point_t& P) { return point_t(P) *= d; } template inline point_t operator / (T d, const point_t& P) { return point_t(P) /= d; } template inline point_t operator + (T d, const point_t& P) { return point_t(P) += d; } template inline point_t operator - (T d, const point_t& P) { return point_t(P) -= d; } template T point_t_dist2(const point_t&A, const point_t&B) { T x = A.x - B.x; T y = A.y - B.y; T z = A.z - B.z; return x*x + y*y + z*z; } template inline point_t point_t::cross(const point_t&P) const { point_t ret; ret.x = y * P.z - z * P.y; ret.y = z * P.x - x * P.z; ret.z = x * P.y - y * P.x; return ret; } template inline T point_t::mag() const { return sqrt(mag2()); } template inline T point_t::mag2() const { return *this * *this; } template inline point_t& point_t::make_unit() { return *this /= mag(); } template inline point_t point_t::ret_unit() const { return point_t(*this).make_unit(); } #endif