252 lines
4.6 KiB
C++
252 lines
4.6 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeGLineRay2D Àà
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TPGeGLineRay2D ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeGLineRay2D.h"
|
|
#include "TPGeGLineRay3D.h"
|
|
#include "TGPoint2D.h"
|
|
|
|
IMPLEMENT_RUN_TIME_CLASS1(TPGeGLineRay2D,"TPGeGLineRay2D",TPGeGLine2D)
|
|
|
|
TPGeGLineRay2D::TPGeGLineRay2D()
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGLineRay2D::TPGeGLineRay2D(const TGVector2D& vt,const TGPoint& pt):TPGeGLine2D(vt,pt)
|
|
{
|
|
}
|
|
|
|
TPGeGLineRay2D::TPGeGLineRay2D(const TGPoint& pt0,const TGPoint& pt1):TPGeGLine2D(pt0,pt1)
|
|
{
|
|
}
|
|
|
|
TPGeGLineRay2D::TPGeGLineRay2D(const TPGeLine2D& line):TPGeGLine2D(line)
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGLineRay2D::~TPGeGLineRay2D()
|
|
{
|
|
|
|
}
|
|
|
|
bool TPGeGLineRay2D::IsFinite(bool bStart) const
|
|
{
|
|
return bStart ? true : false;
|
|
}
|
|
|
|
TPGeCurve2D* TPGeGLineRay2D::GetExtendCurve() const
|
|
{
|
|
return new TPGeGLine2D(*this);
|
|
}
|
|
|
|
TGObject * TPGeGLineRay2D::Clone() const
|
|
{
|
|
return new TPGeGLineRay2D(*this);
|
|
}
|
|
|
|
bool TPGeGLineRay2D::IsSameRay(const TPGeGLineRay2D& ray) const
|
|
{
|
|
return basePoint.Equal2D(ray.basePoint) && IsParallel(ray) && IsSameDirection(ray);
|
|
}
|
|
|
|
GRelation TPGeGLineRay2D::HitTest(const TGPoint& pt) const
|
|
{
|
|
GRelation r = TPGeGLine2D::HitTest(pt);
|
|
if (r.Is(GR_IN))
|
|
{
|
|
double pa;
|
|
Pt2Pa(pt,pa);
|
|
if (DOWN_ZERO(pa) && UP_ZEROD(Distance2D(basePoint,pt)))
|
|
{
|
|
return GR_OUT;
|
|
}
|
|
else
|
|
{
|
|
return GR_IN;
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
|
|
bool TPGeGLineRay2D::IsInclude(const TGObject& obj) const
|
|
{
|
|
switch(obj.GetClassID())
|
|
{
|
|
case CID_GLine2D:
|
|
return false;
|
|
case CID_GLineRay2D:
|
|
{
|
|
const TPGeGLineRay2D& ray = (const TPGeGLineRay2D& )obj;
|
|
if (GetGeLine() == ray.GetGeLine() && IsSameDirection(ray))
|
|
{
|
|
double pa;
|
|
Pt2Pa(ray.basePoint,pa);
|
|
return UPEQUAL_ZERO(pa);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
case CID_GLineSeg2D:
|
|
{
|
|
const TPGeGLineSeg2D& seg = (const TPGeGLineSeg2D& )obj;
|
|
if (GetGeLine() == seg.GetGeLine())
|
|
{
|
|
double pa;
|
|
Pt2Pa(seg.GetStartPoint(),pa);
|
|
if (DOWN_ZERO(pa))
|
|
{
|
|
return false;
|
|
}
|
|
Pt2Pa(seg.GetEndPoint(),pa);
|
|
return UPEQUAL_ZERO(pa);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
case CID_GCircle2D:
|
|
case CID_GArc2D:
|
|
return false;
|
|
default:
|
|
return TPGeCurve2D::IsInclude(obj);
|
|
}
|
|
}
|
|
|
|
bool TPGeGLineRay2D::Intersect(const TGObject& obj,TGObjectList& res) const
|
|
{
|
|
switch(obj.GetClassID())
|
|
{
|
|
case CID_GLine2D:
|
|
{
|
|
double pa;
|
|
int ret = TPGeLine2D::Intersect((const TPGeGLine2D& )obj,pa);
|
|
if (ret == INT_NULL)
|
|
{
|
|
return false;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
res << new TPGeGLineRay2D(*this);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (DOWN_ZERO(pa))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
TGPoint2D *pPt = new TGPoint2D;
|
|
Pa2Pt(pa,*pPt);
|
|
res << pPt;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
case CID_GLineRay2D:
|
|
{
|
|
double pa1,pa2;
|
|
const TPGeGLineRay2D& ray = (const TPGeGLineRay2D& )obj;
|
|
int ret = TPGeLine2D::Intersect(ray,pa1,pa2);
|
|
if (ret == INT_NULL)
|
|
{
|
|
return false;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
Pt2Pa(ray.basePoint,pa1);
|
|
if (IsSameDirection(ray))
|
|
{
|
|
if (UP_ZERO(pa1))
|
|
{
|
|
res << new TPGeGLineRay2D(ray);
|
|
}
|
|
else
|
|
{
|
|
res << new TPGeGLineRay2D(*this);
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (UP_ZERO(pa1))
|
|
{
|
|
res << new TPGeGLineSeg2D(basePoint,ray.basePoint);
|
|
}
|
|
else if (DOWN_ZERO(pa1))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
res << new TGPoint2D(basePoint);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (DOWN_ZERO(pa1) || DOWN_ZERO(pa2))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
TGPoint2D *pPt = new TGPoint2D;
|
|
Pa2Pt(pa1,*pPt);
|
|
res << pPt;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
return obj.Intersect(*this, res);
|
|
}
|
|
}
|
|
|
|
void TPGeGLineRay2D::Split(const TTable<double>& paTable,TGObjectList& res) const
|
|
{
|
|
if (paTable.IsEmpty())
|
|
{
|
|
return;
|
|
}
|
|
TGPoint pt0;
|
|
if (UP_ZERO(paTable.GetAt(0)))
|
|
{
|
|
Pa2Pt(paTable.GetAt(0),pt0);
|
|
res << new TPGeGLineSeg2D(basePoint,pt0);
|
|
}
|
|
else
|
|
{
|
|
pt0 = basePoint;
|
|
}
|
|
for (long i = 1; i < paTable.GetLength(); i++)
|
|
{
|
|
if (UP_ZERO(paTable.GetAt(i) - paTable.GetAt(i - 1)))
|
|
{
|
|
TGPoint pt1;
|
|
Pa2Pt(paTable.GetAt(i),pt1);
|
|
res << new TPGeGLineSeg2D(pt0,pt1);
|
|
pt0 = pt1;
|
|
}
|
|
}
|
|
res << new TPGeGLineRay2D(TGVector2D(*this),pt0);
|
|
}
|
|
|
|
TGObject3D* TPGeGLineRay2D::Convert3D() const
|
|
{
|
|
return new TPGeGLineRay3D(TGVector3D(x,y,z),basePoint);
|
|
} |