Files
envi-code/SourceCode/Code2026/tg_shs/inc/subgeo/TGMLine2D.h
T
2026-09-28 15:28:50 +08:00

169 lines
4.3 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TGMLine2D 类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TGMLine2D 声明
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#ifndef _TGMLINE2D_H_
#define _TGMLINE2D_H_
#ifndef _TPGECURVE2D_H_
#include "TPGeCurve2D.h"
#endif
#ifndef _TPGELINE2D_H_
#include "TPGeLine2D.h"
#endif
#ifndef _TGPOINT_H_
#include "TGPoint.h"
#endif
#ifndef _TARRAY_H_
#include "TArray.h"
#endif
#ifndef _TTABLE_H_
#include "TTable.h"
#endif
#ifndef _TGOBJECT_H_
#include "TGObject.h"
#endif
#ifndef _TGOBJECTLIST_H_
#include "TGObjectList.h"
#endif
#ifndef _TWFLAG_H_
#include "TWFlag.h"
#endif
#ifndef _TPGEARC2D_H_
#include "TPGeArc2D.h"
#endif
#ifndef _TPGEGLINERAY2D_H_
#include "TPGeGLineRay2D.h"
#endif
#ifndef _TPGECIRCLE2D_H_
#include "TPGeCircle2D.h"
#endif
class TGObject3D;
class TGMatrix;
class TPGeGLineSeg2D;
class GEOAPI TGMLine2D : public TPGeCurve2D
{
DECLARE_RUN_TIME_CLASS(TGMLine2D)
public:
//contruct
TGMLine2D(long vertexNum = 0,bool bClosed = false);
TGMLine2D(const TArray<TGPoint>&vertexs,bool bClosed = false);
TGMLine2D(const TTable<TGPoint>&vertexs,bool bClosed = false);
virtual ~TGMLine2D();
TGMLine2D& operator = (const TArray<TGPoint>&vertexs);
TGMLine2D& operator = (const TTable<TGPoint>&vertexs);
TGPoint& operator[](long i);
virtual long Pa2Seg(double&pa) const;
virtual void SetVertexNum(long num,bool bCopy = false);
//消除相邻重合点,如使之有效返回true
virtual bool RemoveDupPoint();
virtual bool OffsetSeg(long i,double offset);
//override TPGeCurve2D
//参数区间为各段参数区间之和,即[0,GetSegNum()]
virtual double Length() const;
virtual void Pa2Pt(double pa,TGPoint&pt) const;
virtual void Pt2Pa(const TGPoint&pt,double&pa) const;
virtual void GetStartPoint(TGPoint&pt) const;
virtual void GetEndPoint(TGPoint&pt) const;
virtual void Reverse();
virtual void GetTangent(double pa,TPGeLine2D&line) const;
//对于!IS(CLOSE_CURVE),如果首尾结点相同,也将认为是自交!
virtual bool IsSelfCross() const;
virtual bool IsClosed() const;
virtual bool Offset(double offset);
virtual double Integration(double pa0,double pa1) const;
virtual TGMLine2D* MLinearize(double paDist = 0) const;
virtual TPGeCurve2D* GetSubCurve(double pa0,double pa1) const;
virtual TGPoint GetSamplePoint() const;
//override TGObject2D
virtual void SetElev(double elev);
virtual double GetElev() const;
//override TGObject
//节点数大于1,无相邻重合点
virtual bool IsValid() const;
//分解为TPGeGLineSeg2D
virtual bool Explode(TGObjectList&res) const;
virtual void TransformBy(const TGMatrix& pMatrix);
virtual TGObject * Clone() const;
virtual GRelation HitTest(const TGPoint&pt) const;
virtual bool IsInclude(const TGObject&obj) const;
virtual bool GetExtend2D(TPGeExtend2D&ext) const;
//edit
void SetClosed(bool bClosed = true);
//query
//pa转化为本地参数
bool IsLinear() const;
bool IsConcave() const;
long GetVertexNum() const;
long GetSegNum() const;
void GetSegment(long i,TPGeLine2D&seg) const;
const TGPoint& GetVertex(long i) const;
//operator
//closed and not selfcross
void QuickCut(const TPGeGLine2D&line,TGObjectList&left,TGObjectList&right,TGObjectList&mid) const;
void QuickCut(const TPGeGLineRay2D&line,TGObjectList&left,TGObjectList&right,TGObjectList&mid) const;
void QuickCut(const TPGeGLineSeg2D& seg,TGObjectList&left,TGObjectList&right,TGObjectList&mid) const;
void QuickCut(const TPGeArc2D&arc,TGObjectList&left,TGObjectList&right) const;
void QuickCut(const TPGeCircle2D&circle,TGObjectList&left,TGObjectList&right) const;
//分解为不自交段,如不自交则返回false
bool ExplodeSelfcross(TGObjectList&oList) const;
protected:
TArray<TGPoint> points;//节点
};
inline long TGMLine2D::GetSegNum() const
{
if(GetVertexNum() < 2)
{
return 0;
}
else
{
return Is(CLOSED_CURVE) ? GetVertexNum() : GetVertexNum() - 1;
}
}
inline void TGMLine2D::GetSegment(long i,TPGeLine2D&seg) const
{
if(i < points.GetLastIndex())
{
seg.SetPoint(points.GetAt(i),points.GetAt(i + 1));
}
else
{
seg.SetPoint(points.GetAt(i),points.GetAt(0));
}
}
#endif