//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TGNPolygon2D Àà // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TGNPolygon2D ¶¨Òå // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #include "StdAfx.h" #include "TGNPolygon2D.h" #include "TGTriangle2D.h" #include "TPtList.h" TGNPolygon2D::TGNPolygon2D(long vertexNum) : TGPolygon2D(vertexNum) { } TGNPolygon2D::TGNPolygon2D(const TGMLine2D&ml,bool bCheck) : TGPolygon2D(ml,bCheck) { } TGNPolygon2D::TGNPolygon2D(const TGPolygon2D&poly) : TGPolygon2D(poly) { } TGNPolygon2D::~TGNPolygon2D() { } TGObject* TGNPolygon2D::Clone() const { return new TGNPolygon2D(*this); } bool TGNPolygon2D::IsValid() const { return TGPolygon2D::IsValid() && !IsConcave(); } bool TGNPolygon2D::Explode(TGObjectList&res) const { if(mLine.GetVertexNum() < 9) { if(mLine.GetVertexNum() == 3) { res << new TGTriangle2D(mLine.GetVertex(0),mLine.GetVertex(1),mLine.GetVertex(2),false); } else { const TGPoint&pt = mLine.GetVertex(0); long num = mLine.GetVertexNum()-1; for(long i = 1;i < num;i++) { TGTriangle2D *pT = new TGTriangle2D(pt,mLine.GetVertex(i),mLine.GetVertex(i+1),false); if(pT->Outline().IsLinear()) { delete pT; } else { res << pT; } } } } else { const TGPoint&pt = Center(); long num = mLine.GetVertexNum()-1; for(long i = 0;iSetClosed(); pSeg2->SetClosed(); GRelation r = line.HitTest(pSeg1->GetSamplePoint()); if(r.Is(GR_LEFT)) { left << new TGNPolygon2D(*pSeg1,false); } else if(r.Is(GR_RIGHT)) { right << new TGNPolygon2D(*pSeg1,false); } r = line.HitTest(pSeg2->GetSamplePoint()); if(r.Is(GR_LEFT)) { left << new TGNPolygon2D(*pSeg2,false); } else if(r.Is(GR_RIGHT)) { right << new TGNPolygon2D(*pSeg2,false); } delete pSeg1; delete pSeg2; return; } } else if(r == INT_LINE) { break; } } GRelation r = GR_IN; for(i = 0;r.Is(GR_IN);i++) { r = line.HitTest(mLine.GetVertex(i)); } if(r.Is(GR_LEFT)) { left << Clone(); } else { right << Clone(); } } else { TGRegion2D::CutBy(curve,left,right); } }