Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

267 lines
6.3 KiB
C++

#include "StdAfx.h"
#include "GeRectAngle.h"
#include "GlobalFunc.h"
#include "GeCurveInline.h"
GeRectAngle::GeRectAngle()
{
}
GeRectAngle::GeRectAngle(const ads_point pt1, const ads_point pt2)
{
lowLeft = Min(*(ADSGePoint3d *)pt1, *(ADSGePoint3d *)pt2);
upRight = Max(*(ADSGePoint3d *)pt1, *(ADSGePoint3d *)pt2);
}
GeRectAngle::GeRectAngle(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]);
}
GeRectAngle::~GeRectAngle()
{
}
ADSGePoint3d GeRectAngle::GetLowLeft() const
{
return lowLeft;
}
ADSGePoint3d GeRectAngle::GetLowRight() const
{
return ADSGePoint3d(upRight.x, lowLeft.y, lowLeft.z);
}
ADSGePoint3d GeRectAngle::GetUpRight() const
{
return upRight;
}
ADSGePoint3d GeRectAngle::GetUpLeft() const
{
return ADSGePoint3d(lowLeft.x, upRight.y, lowLeft.z);
}
double GeRectAngle::Width() const
{
return fabs(upRight.x - lowLeft.x);
}
double GeRectAngle::Height() const
{
return fabs(upRight.y - lowLeft.y);
}
ads_real GeRectAngle::Area() const
{
return fabs((upRight.x - lowLeft.x) * (upRight.y - lowLeft.y));
}
ShapeType GeRectAngle::GetShapeType() const
{
return SHAPE_RECTANGLE;
}
void GeRectAngle::SetElevation(ads_real dElev)
{
lowLeft.z = upRight.z = dElev;
}
void GeRectAngle::AsPoly2D(GePoly2D & poly) const
{
poly.SetFlag(1);
poly.AppendNode(GetLowLeft());
poly.AppendNode(GetLowRight());
poly.AppendNode(GetUpRight());
poly.AppendNode(GetUpLeft());
poly.SetElevation(lowLeft.z);
}
// 2D only
int GeRectAngle::Intersection(const GeLine &aLine, ads_point pt1, ads_point pt2) const
{
if (!GlobalFunc::IsEqual(1.0E-5, 4, aLine.GetStartPoint().z, aLine.GetEndPoint().z, lowLeft.z, upRight.z))
{
return 0;
}
ADSGePoint3d ptLowRight(upRight.x,lowLeft.y, upRight.z),
ptUpLeft(lowLeft.x, upRight.y, upRight.z);
GeLine line1(lowLeft, ptLowRight, LS_FINITE),
line2(ptLowRight, upRight, LS_FINITE),
line3(upRight, ptUpLeft, LS_FINITE),
line4(ptUpLeft, lowLeft, LS_FINITE);
int nIntersNum = 0;
ADSGePoint3d ptInt;
GeLine *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 GeRectAngle::Center(ads_point ptCen)
{
Midpoint(lowLeft, upRight, ptCen);
}
void GeRectAngle::Make(const TCHAR *pszLayer, int nUseLine) const
{
ADSGePoint3d ptLowRight(upRight.x, lowLeft.y, upRight.z),
ptUpLeft(lowLeft.x, upRight.y, upRight.z);
TCHAR szLayer[80] = _T("");
if (pszLayer)
{
_tcscpy(szLayer, pszLayer);
}
else
{
GlobalFunc::TGGetVar(_T("clayer"), szLayer);
}
if (nUseLine)
{
GlobalFunc::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &lowLeft.x, 11, &ptLowRight.x, NULL);
GlobalFunc::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &ptLowRight.x, 11, &upRight.x, NULL);
GlobalFunc::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &upRight.x, 11, &ptUpLeft.x, NULL);
GlobalFunc::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &ptUpLeft.x, 11, &lowLeft.x, NULL);
}
else
{
AcDbPolyline *pLwPoly = new AcDbPolyline(4);
if (pszLayer)
{
GlobalFunc::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;
GlobalFunc::TGGetVar(_T("THICKNESS"), &dThickness);
pLwPoly->setThickness(dThickness);
GlobalFunc::AddToModelSpace(pLwPoly, Adesk::kTrue);
}
}
int operator & (const GeRectAngle &box, GePoly2D &poly)
{
ADSGePoint3d 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);
GeLine 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;
}
int operator & (const ADSGePoint3d &pt, const GeRectAngle &box)
{
if (pt.x > box.upRight.x + g_Option::instance()._DIST_SNAP
|| pt.y > box.upRight.y + g_Option::instance()._DIST_SNAP
|| pt.x < box.lowLeft.x - g_Option::instance()._DIST_SNAP
|| pt.y < box.lowLeft.y - g_Option::instance()._DIST_SNAP )
{
return PR_OUTSIDE;
}
if (pt.x < box.upRight.x - g_Option::instance()._DIST_SNAP
&& pt.y < box.upRight.y - g_Option::instance()._DIST_SNAP
&& pt.x > box.lowLeft.x + g_Option::instance()._DIST_SNAP
&& pt.y > box.lowLeft.y + g_Option::instance()._DIST_SNAP)
{
return PR_INSIDE;
}
return PR_EDGE;
}
int operator & (const GeRectAngle &boxIn, const GeRectAngle &boxOut)
{
int flg1 = boxIn.lowLeft & boxOut;
int flg2 = boxIn.upRight & boxOut;
ADSGePoint3d 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;
}