Files
envi-code/SourceCode/Code2026/tg_shs/shs_subgeLib/TPGeEllipse.cpp
T

87 lines
1.6 KiB
C++
Raw Normal View History

2026-09-28 15:28:50 +08:00
//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TPGeEllipse.cpp
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: ÀàµÄ¶¨Òå
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TPGeEllipse.h"
TPGeEllipse::TPGeEllipse()
{
}
TPGeEllipse::TPGeEllipse(const TGPoint&pt,double aRadius,double bRadius):center(pt),a(aRadius),b(bRadius)
{
}
TPGeEllipse::~TPGeEllipse()
{
}
bool TPGeEllipse::IsValid() const
{
return UP_ZEROD(a) && UP_ZEROD(b);
}
bool TPGeEllipse::IsCircle() const
{
double temp = a - b;
return EQUAL_ZEROD(temp);
}
void TPGeEllipse::Pt2Pa(const TGPoint&pt,double&pa) const
{
pa = TGVector2D(center,pt).GetAngle();
}
void TPGeEllipse::Pa2Pt(double pa,TGPoint&pt) const
{
pt.x = center.x + a * cos(pa);
pt.y = center.y + b * sin(pa);
pt.z = center.z;
}
bool TPGeEllipse::operator != (const TPGeEllipse&e) const
{
return !(*this == e);
}
GRelation TPGeEllipse::HitTest(const TGPoint&pt) const
{
double dx = pt.x - center.x, dy = pt.y - center.y;
double temp = dx * dx / (a * a) + dy * dy / (b * b) - 1;
if(UP_ZERO(temp))
{
return GR_OUTSIDE;
}
else if(DOWN_ZERO(temp))
{
return GR_INSIDE;
}
else
{
return GR_IN;
}
}
bool TPGeEllipse::operator == (const TPGeEllipse&e) const
{
double d = a - e.a;
if(EQUAL_ZEROD(d))
{
d = b - e.b;
if(EQUAL_ZEROD(d))
{
return center == e.center;
}
}
return false;
}