Files
envi-code/SourceCode/Code2026/tg_shs/shs_geLib/TGGeRectAngle.cpp
T
2026-09-28 15:28:50 +08:00

279 lines
6.7 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TGGeRectAngle
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TGGeRectAngle ÀඨÒå
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TGGeRectAngle.h"
#include "TchGlobalFunc.h"
#include "TchGlobalCurveFunc.h"
#include "TchPrivateGlobalFunc.h"
#include "TGGeCurveInline.h"
TGGeRectAngle::TGGeRectAngle()
{
}
TGGeRectAngle::TGGeRectAngle(const ads_point pt1, const ads_point pt2)
{
lowLeft = Min(*(TADSGePoint3d *)pt1, *(TADSGePoint3d *)pt2);
upRight = Max(*(TADSGePoint3d *)pt1, *(TADSGePoint3d *)pt2);
}
TGGeRectAngle::TGGeRectAngle(const ads_point ptCen, ads_real dWidth, ads_real dHeight)
{
lowLeft = Point(ptCen[0] - dWidth / 2.0, ptCen[1] - dHeight / 2.0, ptCen[2]);
upRight = Point(ptCen[0] + dWidth / 2.0, ptCen[1] + dHeight / 2.0, ptCen[2]);
}
TGGeRectAngle::~TGGeRectAngle()
{
}
TADSGePoint3d TGGeRectAngle::GetLowLeft() const
{
return lowLeft;
}
TADSGePoint3d TGGeRectAngle::GetLowRight() const
{
return TADSGePoint3d(upRight.x, lowLeft.y, lowLeft.z);
}
TADSGePoint3d TGGeRectAngle::GetUpRight() const
{
return upRight;
}
TADSGePoint3d TGGeRectAngle::GetUpLeft() const
{
return TADSGePoint3d(lowLeft.x, upRight.y, lowLeft.z);
}
double TGGeRectAngle::Width() const
{
return fabs(upRight.x - lowLeft.x);
}
double TGGeRectAngle::Height() const
{
return fabs(upRight.y - lowLeft.y);
}
ads_real TGGeRectAngle::Area() const
{
return fabs((upRight.x - lowLeft.x) * (upRight.y - lowLeft.y));
}
ShapeType TGGeRectAngle::GetShapeType() const
{
return SHAPE_RECTANGLE;
}
void TGGeRectAngle::SetElevation(ads_real dElev)
{
lowLeft.z = upRight.z = dElev;
}
void TGGeRectAngle::AsPoly2D(TGGePoly2D & poly) const
{
poly.SetFlag(1);
poly.AppendNode(GetLowLeft());
poly.AppendNode(GetLowRight());
poly.AppendNode(GetUpRight());
poly.AppendNode(GetUpLeft());
poly.SetElevation(lowLeft.z);
}
// 2D only
int TGGeRectAngle::Intersection(const TGGeLine &aLine, ads_point pt1, ads_point pt2) const
{
if (!IsEqual(1.0E-5, 4, aLine.GetStartPoint().z, aLine.GetEndPoint().z, lowLeft.z, upRight.z))
{
return 0;
}
TADSGePoint3d ptLowRight(upRight.x,lowLeft.y, upRight.z),
ptUpLeft(lowLeft.x, upRight.y, upRight.z);
TGGeLine line1(lowLeft, ptLowRight, LS_FINITE),
line2(ptLowRight, upRight, LS_FINITE),
line3(upRight, ptUpLeft, LS_FINITE),
line4(ptUpLeft, lowLeft, LS_FINITE);
int nIntersNum = 0;
TADSGePoint3d ptInt;
TGGeLine *pLine[4] = { &line1, &line2, &line3, &line4 };
for (int i = 0; i < 4; i++)
{
if (pLine[i]->Intersection(&aLine, ptInt))
{
nIntersNum++;
if (nIntersNum == 2)
{
if (pt2)
{
ptInt > pt2;
}
return nIntersNum;
}
else
{
if (pt1)
{
ptInt > pt1;
}
}
}
}
return nIntersNum;
}
void TGGeRectAngle::Center(ads_point ptCen)
{
Midpoint(lowLeft, upRight, ptCen);
}
void TGGeRectAngle::Make(const TCHAR *pszLayer, int nUseLine) const
{
TADSGePoint3d ptLowRight(upRight.x, lowLeft.y, upRight.z),
ptUpLeft(lowLeft.x, upRight.y, upRight.z);
TCHAR szLayer[80] = _T("");
if (pszLayer)
{
_tcscpy(szLayer, pszLayer);
}
else
{
TGGetVar(_T("clayer"), szLayer);
}
if (nUseLine)
{
TchExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &lowLeft.x, 11, &ptLowRight.x, NULL);
TchExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &ptLowRight.x, 11, &upRight.x, NULL);
TchExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &upRight.x, 11, &ptUpLeft.x, NULL);
TchExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &ptUpLeft.x, 11, &lowLeft.x, NULL);
}
else
{
AcDbPolyline *pLwPoly = new AcDbPolyline(4);
if (pszLayer)
{
AssureLayer(pszLayer, 0);
pLwPoly->setLayer(pszLayer);
}
pLwPoly->addVertexAt(0, GetLowLeft().AsAcGePoint2d());
pLwPoly->addVertexAt(1, GetLowRight().AsAcGePoint2d());
pLwPoly->addVertexAt(2, GetUpRight().AsAcGePoint2d());
pLwPoly->addVertexAt(3, GetUpLeft().AsAcGePoint2d());
pLwPoly->setClosed(Adesk::kTrue);
double dThickness = 0.0;
TGGetVar(_T("THICKNESS"), &dThickness);
pLwPoly->setThickness(dThickness);
AddToModelSpace(pLwPoly, Adesk::kTrue);
}
}
GEOAPI int operator & (const TGGeRectAngle &box, TGGePoly2D &poly)
{
TADSGePoint3d lowRight(box.upRight.x, box.lowLeft.y, box.lowLeft.z),
upLeft(box.lowLeft.x, box.upRight.y, box.lowLeft.z),
lowLeft(box.lowLeft), upRight(box.upRight);
TGGeLine ln0(lowLeft, lowRight, LS_FINITE), ln1(lowRight, upRight, LS_FINITE),
ln2(upRight, upLeft, LS_FINITE), ln3(upLeft, lowLeft, LS_FINITE);
int flg0 = ln0&poly;
int flg1 = ln1&poly;
int flg2 = ln2&poly;
int flg3 = ln3&poly;
if (flg0 == PR_EDGE && flg1 == PR_EDGE && flg2 == PR_EDGE && flg3 == PR_EDGE)
{
return PR_EDGE;
}
if ((flg0 == PR_EDGE || flg0 == PR_INSIDE) &&
(flg1 == PR_EDGE || flg1 == PR_INSIDE) &&
(flg2 == PR_EDGE || flg2 == PR_INSIDE) &&
(flg3 == PR_EDGE || flg3 == PR_INSIDE))
{
return PR_INSIDE;
}
if ((flg0 == PR_EDGE || flg0 == PR_OUTSIDE) &&
(flg1 == PR_EDGE || flg1 == PR_OUTSIDE) &&
(flg2 == PR_EDGE || flg2 == PR_OUTSIDE) &&
(flg3 == PR_EDGE || flg3 == PR_OUTSIDE))
{
return PR_OUTSIDE;
}
return PR_INTERS;
}
GEOAPI int operator & (const TADSGePoint3d &pt, const TGGeRectAngle &box)
{
if (pt.x > box.upRight.x + TchGeLib::_DIST_SNAP
|| pt.y > box.upRight.y + TchGeLib::_DIST_SNAP
|| pt.x < box.lowLeft.x - TchGeLib::_DIST_SNAP
|| pt.y < box.lowLeft.y - TchGeLib::_DIST_SNAP )
{
return PR_OUTSIDE;
}
if (pt.x < box.upRight.x - TchGeLib::_DIST_SNAP
&& pt.y < box.upRight.y - TchGeLib::_DIST_SNAP
&& pt.x > box.lowLeft.x + TchGeLib::_DIST_SNAP
&& pt.y > box.lowLeft.y + TchGeLib::_DIST_SNAP)
{
return PR_INSIDE;
}
return PR_EDGE;
}
GEOAPI int operator & (const TGGeRectAngle &boxIn, const TGGeRectAngle &boxOut)
{
int flg1 = boxIn.lowLeft & boxOut;
int flg2 = boxIn.upRight & boxOut;
TADSGePoint3d lowRight(boxIn.upRight.x, boxIn.lowLeft.y, boxIn.lowLeft.z),
upLeft(boxIn.lowLeft.x, boxIn.upRight.y, boxIn.lowLeft.z);
int flg3 = lowRight&boxOut;
int flg4 = upLeft&boxOut;
if (flg1 == PR_EDGE && flg2 == PR_EDGE && flg3 == PR_EDGE)
{
return PR_EDGE;
}
if ((flg1 == PR_INSIDE || flg1 == PR_EDGE) &&
(flg2 == PR_INSIDE || flg2 == PR_EDGE) &&
(flg3 == PR_INSIDE || flg3 == PR_EDGE) &&
(flg4 == PR_INSIDE || flg4 == PR_EDGE))
{
return PR_INSIDE;
}
if ((flg1 == PR_OUTSIDE || flg1 == PR_EDGE) &&
(flg2 == PR_OUTSIDE || flg2 == PR_EDGE) &&
(flg3 == PR_OUTSIDE || flg3 == PR_EDGE) &&
(flg4 == PR_OUTSIDE || flg4 == PR_EDGE) )
{
return PR_OUTSIDE;
}
return PR_INTERS;
}