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

279 lines
6.5 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, SH Software Co. Ltd.
// = FileName : XRectAngle
// = Version : ver2.0
// = Author : zjq
// = CreateDate : 2002-09-09
// = Description: XRectAngle 类定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "XRectAngle.h"
#include "XGlobalFunc.h"
#include "XGlobalCurveFunc.h"
#include "XPrivateGlobalFunc.h"
#include "XCurveInline.h"
XRectAngle::XRectAngle()
{
}
XRectAngle::XRectAngle(const ads_point pt1, const ads_point pt2)
{
lowLeft = Min(*(XPoint *)pt1, *(XPoint *)pt2);
upRight = Max(*(XPoint *)pt1, *(XPoint *)pt2);
}
XRectAngle::XRectAngle(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]);
}
XRectAngle::~XRectAngle()
{
}
XPoint XRectAngle::GetLowLeft() const
{
return lowLeft;
}
XPoint XRectAngle::GetLowRight() const
{
return XPoint(upRight.x, lowLeft.y, lowLeft.z);
}
XPoint XRectAngle::GetUpRight() const
{
return upRight;
}
XPoint XRectAngle::GetUpLeft() const
{
return XPoint(lowLeft.x, upRight.y, lowLeft.z);
}
double XRectAngle::Width() const
{
return fabs(upRight.x - lowLeft.x);
}
double XRectAngle::Height() const
{
return fabs(upRight.y - lowLeft.y);
}
ads_real XRectAngle::Area() const
{
return fabs((upRight.x - lowLeft.x) * (upRight.y - lowLeft.y));
}
ShapeType XRectAngle::GetShapeType() const
{
return SHAPE_RECTANGLE;
}
void XRectAngle::SetElevation(ads_real dElev)
{
lowLeft.z = upRight.z = dElev;
}
void XRectAngle::AsPoly2D(XPoly2D & poly) const
{
poly.SetFlag(1);
poly.AppendNode(GetLowLeft());
poly.AppendNode(GetLowRight());
poly.AppendNode(GetUpRight());
poly.AppendNode(GetUpLeft());
poly.SetElevation(lowLeft.z);
}
// 2D only
int XRectAngle::Intersection(const XLine &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;
}
XPoint ptLowRight(upRight.x,lowLeft.y, upRight.z),
ptUpLeft(lowLeft.x, upRight.y, upRight.z);
XLine line1(lowLeft, ptLowRight, LS_FINITE),
line2(ptLowRight, upRight, LS_FINITE),
line3(upRight, ptUpLeft, LS_FINITE),
line4(ptUpLeft, lowLeft, LS_FINITE);
int nIntersNum = 0;
XPoint ptInt;
XLine *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 XRectAngle::Center(ads_point ptCen)
{
Midpoint(lowLeft, upRight, ptCen);
}
void XRectAngle::Make(const TCHAR *pszLayer, int nUseLine) const
{
XPoint ptLowRight(upRight.x, lowLeft.y, upRight.z),
ptUpLeft(lowLeft.x, upRight.y, upRight.z);
TCHAR szLayer[80] = _T("");
if (pszLayer)
{
_tcscpy(szLayer, pszLayer);
}
else
{
xg_getvar(_T("clayer"), szLayer);
}
if (nUseLine)
{
XExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &lowLeft.x, 11, &ptLowRight.x, NULL);
XExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &ptLowRight.x, 11, &upRight.x, NULL);
XExport::MakeEntity(RTDXF0, _T("LINE"), 8, szLayer, 10, &upRight.x, 11, &ptUpLeft.x, NULL);
XExport::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;
xg_getvar(_T("THICKNESS"), &dThickness);
pLwPoly->setThickness(dThickness);
AddToModelSpace(pLwPoly, Adesk::kTrue);
}
}
GEOAPI int operator & (const XRectAngle &box, XPoly2D &poly)
{
XPoint 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);
XLine 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 XPoint &pt, const XRectAngle &box)
{
if (pt.x > box.upRight.x + XGeLib::_DIST_SNAP
|| pt.y > box.upRight.y + XGeLib::_DIST_SNAP
|| pt.x < box.lowLeft.x - XGeLib::_DIST_SNAP
|| pt.y < box.lowLeft.y - XGeLib::_DIST_SNAP )
{
return PR_OUTSIDE;
}
if (pt.x < box.upRight.x - XGeLib::_DIST_SNAP
&& pt.y < box.upRight.y - XGeLib::_DIST_SNAP
&& pt.x > box.lowLeft.x + XGeLib::_DIST_SNAP
&& pt.y > box.lowLeft.y + XGeLib::_DIST_SNAP)
{
return PR_INSIDE;
}
return PR_EDGE;
}
GEOAPI int operator & (const XRectAngle &boxIn, const XRectAngle &boxOut)
{
int flg1 = boxIn.lowLeft & boxOut;
int flg2 = boxIn.upRight & boxOut;
XPoint 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;
}