Files
envi-code/SourceCode/Code2026/tg_shs/shs_subgeLib/TGPoint.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

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);
}
}
}