166 lines
2.6 KiB
C++
166 lines
2.6 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TGPoint Àà
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TGPoint ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TGPoint.h"
|
|
|
|
TGPoint::TGPoint(double X,double Y,double Z):x(X),y(Y),z(Z)
|
|
{
|
|
|
|
}
|
|
|
|
TGPoint::TGPoint(double *p):x(p[0]),y(p[1]),z(p[2])
|
|
{
|
|
}
|
|
|
|
TGPoint::TGPoint(float *p):x(p[0]),y(p[1]),z(p[2])
|
|
{
|
|
}
|
|
|
|
TGPoint::~TGPoint()
|
|
{
|
|
|
|
}
|
|
|
|
void TGPoint::SetPoint(double X,double Y,double Z)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
z = Z;
|
|
}
|
|
|
|
void TGPoint::SetPoint(double X,double Y)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
}
|
|
|
|
void TGPoint::operator += (const TGPoint& vt)
|
|
{
|
|
x += vt.x;
|
|
y += vt.y;
|
|
z += vt.z;
|
|
}
|
|
|
|
void TGPoint::operator -= (const TGPoint& vt)
|
|
{
|
|
x -= vt.x;
|
|
y -= vt.y;
|
|
z -= vt.z;
|
|
}
|
|
|
|
void TGPoint::operator *= (double rate)
|
|
{
|
|
x *= rate;
|
|
y *= rate;
|
|
z *= rate;
|
|
}
|
|
|
|
void TGPoint::operator /= (double rate)
|
|
{
|
|
x /= rate;
|
|
y /= rate;
|
|
z /= rate;
|
|
}
|
|
|
|
TGPoint TGPoint::operator + (const TGPoint& vt) const
|
|
{
|
|
return TGPoint(x + vt.x, y + vt.y, z + vt.z);
|
|
}
|
|
|
|
TGPoint TGPoint::operator - (const TGPoint& vt) const
|
|
{
|
|
return TGPoint(x - vt.x, y - vt.y, z - vt.z);
|
|
}
|
|
|
|
TGPoint TGPoint::operator * (double rate) const
|
|
{
|
|
return TGPoint(x * rate, y * rate, z * rate);
|
|
}
|
|
|
|
TGPoint TGPoint::operator / (double rate) const
|
|
{
|
|
return TGPoint(x / rate, y / rate, z / rate);
|
|
}
|
|
|
|
TGPoint TGPoint::operator - () const
|
|
{
|
|
return TGPoint(-x, -y, -z);
|
|
}
|
|
|
|
TGPoint::operator double*() const
|
|
{
|
|
return (double*)(& x);
|
|
}
|
|
|
|
double& TGPoint::operator[](int i)
|
|
{
|
|
return (& x)[i];
|
|
}
|
|
|
|
double TGPoint::Length2D() const
|
|
{
|
|
return sqrt(x * x + y * y);
|
|
}
|
|
|
|
double TGPoint::Length3D() const
|
|
{
|
|
return sqrt(x * x + y * y + z * z);
|
|
}
|
|
|
|
bool TGPoint::Equal2D(const TGPoint& pt) const
|
|
{
|
|
double d = Distance2D(*this,pt);
|
|
return EQUAL_ZEROD(d);
|
|
}
|
|
|
|
bool TGPoint::operator == (const TGPoint& pt) const
|
|
{
|
|
double d = Distance3D(*this,pt);
|
|
return EQUAL_ZEROD(d);
|
|
}
|
|
|
|
bool TGPoint::operator != (const TGPoint& pt) const
|
|
{
|
|
return !(*this == pt);
|
|
}
|
|
bool TGPoint::operator < (const TGPoint& pt) const
|
|
{
|
|
return pt > *this;
|
|
}
|
|
|
|
bool TGPoint::operator > (const TGPoint& pt) const
|
|
{
|
|
double d = x - pt.x;
|
|
if(UP_ZEROD(d))
|
|
{
|
|
return true;
|
|
}
|
|
else if(DOWN_ZEROD(d))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
d = y - pt.y;
|
|
if(UP_ZEROD(d))
|
|
{
|
|
return true;
|
|
}
|
|
else if(DOWN_ZEROD(d))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return UP_ZEROD(z - pt.z);
|
|
}
|
|
}
|
|
} |