|
- // ************************************************************************** //
- // Copyright(c)2010 Naiky Company. All rights reserved.
- //
- // Abstract:
- // Cad对象求交函数的实现
- // ********************************************* ---- 吴阳明 2010-09-08 ***** //
- #include "stdafx.h"
- #include "Intersect.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- using namespace ncmath;
-
- // 总接口定义 --- 吴阳明 2010 09 10
- int nce::GetIntersection(IN const CCadObject* pCadObject1_,
- IN const CCadObject* pCadObject2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadObject1_);
- ASSERT(pCadObject2_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 用两个变量转存入口形参,并保证_pCadObject1对象的Type值不大于_pCadObject2
- // 对象的Type值。 ---- 杨开锦 2010-09-14
- const CCadObject* _pCadObject1 = pCadObject1_;
- const CCadObject* _pCadObject2 = pCadObject2_;
- if ((UINT)_pCadObject1->GetType() > (UINT)_pCadObject2->GetType())
- {
- _pCadObject1 = pCadObject2_;
- _pCadObject2 = pCadObject1_;
- }
-
- // 用32位整数表示参数_pCadObject1与_pCadObject2的类型(结合方式),设前者的
- // 类型为Type1,后者的类型为Type2,则结合类型为 (Type1 << 16 | Type2)。本种
- // 表示方式依赖于所有对象的Type值不超过0xFFFF。 ---- 杨开锦 2010-09-14
- UINT _nType1 = _pCadObject1->GetType();
- UINT _nType2 = _pCadObject2->GetType();
- ASSERT(_nType1 < 0xFFFF && _nType2 < 0xFFFF);
-
- // 按结合类型分类求解,该switch-case实际上是一个二维表,以_nType1和_nType2为
- // 该表的索引值,查询对应的处理路径(即函数入口)。
- // 由于A与B求交的结果理应等同于B与A求交的结果,因此,为减小本表查询项的数
- // 量和所提供函数的数量,此处只查询表的左上角块(_nType1<=_nType2),右下角块
- // 被镜像到左上角相应位置(这在前面的代码中已完成)。 ---- 杨开锦 2010-09-14
- int _nResult = 0;
- ASSERT(_nType1 <= _nType2);
- switch(_nType1 << 16 | _nType2)
- {
- // 线段和线段 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadline):
- {
- C_ASSERT(cadline <= cadline);
-
- const CCadLine* _pCadLine1 = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadLine* _pCadLine2 = dynamic_cast<const CCadLine*>(_pCadObject2);
- _nResult = Intersect_CadLineWithCadLine(_pCadLine1, _pCadLine2, pvectorIntersect_);
- }
- break;
-
- // 线段和直线 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadbeeline):
- {
- C_ASSERT(cadline <= cadbeeline);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*>(_pCadObject2);
- _nResult = Intersect_CadLineWithCadBeeline(_pCadLine, _pCadBeeline, pvectorIntersect_);
- }
- break;
-
- // 线段和圆 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadcircle):
- {
- C_ASSERT(cadline <= cadcircle);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*>(_pCadObject2);
- _nResult = Intersect_CadLineWithCadCircle(_pCadLine, _pCadCircle, pvectorIntersect_);
- }
- break;
-
- // 线段和圆弧 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadarc):
- {
- C_ASSERT(cadline <= cadarc);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadArc * _pCadArc = dynamic_cast<const CCadArc *>(_pCadObject2);
- _nResult = Intersect_CadLineWithCadArc(_pCadLine, _pCadArc, pvectorIntersect_);
- }
- break;
-
- // 线段和椭圆 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadellipse):
- {
- C_ASSERT(cadline <= cadellipse);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject2);
- _nResult = Intersect_CadLineWithCadEllipse(_pCadLine, _pCadEllipse, pvectorIntersect_);
- }
- break;
-
- // 线段和椭圆弧 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadellipsearc):
- {
- C_ASSERT(cadline <= cadellipsearc);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject2);
- _nResult = Intersect_CadLineWithCadEllipseArc(_pCadLine, _pCadEllipseArc, pvectorIntersect_);
- }
- break;
-
- // 线段和多段线 --- 吴阳明 2010 09 19
- case (cadline << 16 | cadmultisegments):
- case (cadline << 16 | cadrectangle):
- case (cadline << 16 | cadstar):
- case (cadline << 16 | cadpolygon):
- case (cadline << 16 | cadpolyline):
- {
- C_ASSERT(cadline <= cadmultisegments &&
- cadline <= cadrectangle &&
- cadline <= cadstar &&
- cadline <= cadpolygon &&
- cadline <= cadpolyline);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*>(_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadLineWithCadMultiSegments(_pCadLine, _pCadMultiSegments, pvectorIntersect_);
- }
- break;
-
- // 线段和群组 --- 吴阳明 2010 10 21
- case (cadline << 16 | cadgroup):
- {
- C_ASSERT(cadline <= cadgroup);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*> (_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadLine, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 线段和文字 --- 吴阳明 2010 10 21
- case (cadline << 16 | cadtext):
- {
- C_ASSERT(cadline <= cadtext);
-
- const CCadLine* _pCadLine = dynamic_cast<const CCadLine*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadLine, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 直线和直线 --- 吴阳明 2010 09 19
- case (cadbeeline << 16 | cadbeeline):
- {
- C_ASSERT(cadbeeline <= cadbeeline);
-
- const CCadBeeline* _pCadBeeline1 = dynamic_cast<const CCadBeeline*> (_pCadObject1);
- const CCadBeeline* _pCadBeeline2 = dynamic_cast<const CCadBeeline*> (_pCadObject2);
- _nResult = Intersect_CadBeelineWithCadBeeline(_pCadBeeline1, _pCadBeeline2, pvectorIntersect_);
- }
- break;
-
- // 直线和圆 --- 吴阳明 2010 09 19
- case (cadbeeline << 16 | cadcircle):
- {
- C_ASSERT(cadbeeline <= cadcircle);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*> (_pCadObject1);
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject2);
- _nResult = Intersect_CadBeelineWithCadCircle(_pCadBeeline, _pCadCircle, pvectorIntersect_);
- }
- break;
-
- // 直线和圆弧 --- 吴阳明 2010 09 19
- case (cadbeeline << 16 | cadarc):
- {
- C_ASSERT(cadbeeline <= cadarc);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*> (_pCadObject1);
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject2);
- _nResult = Intersect_CadBeelineWithCadArc(_pCadBeeline, _pCadArc, pvectorIntersect_);
- }
- break;
-
- // 直线和椭圆 --- 吴阳明 2010 09 19
- case (cadbeeline << 16 | cadellipse):
- {
- C_ASSERT(cadbeeline <= cadellipse);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*> (_pCadObject1);
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject2);
- _nResult = Intersect_CadBeelineWithCadEllipse(_pCadBeeline, _pCadEllipse, pvectorIntersect_);
- }
- break;
-
- // 直线和椭圆弧 --- 吴阳明 2010 09 19
- case (cadbeeline << 16 | cadellipsearc):
- {
- C_ASSERT(cadbeeline <= cadellipsearc);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*> (_pCadObject1);
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject2);
- _nResult = Intersect_CadBeelineWithCadEllipseArc(_pCadBeeline, _pCadEllipseArc, pvectorIntersect_);
- }
- break;
-
- // 直线和多段线 --- 吴阳明 2010 09 19
- case (cadbeeline << 16 | cadmultisegments):
- case (cadbeeline << 16 | cadrectangle):
- case (cadbeeline << 16 | cadstar):
- case (cadbeeline << 16 | cadpolygon):
- case (cadbeeline << 16 | cadpolyline):
- {
- C_ASSERT(cadbeeline <= cadmultisegments &&
- cadbeeline <= cadrectangle &&
- cadbeeline <= cadstar &&
- cadbeeline <= cadpolygon &&
- cadbeeline <= cadpolyline);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*>(_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadBeelineWithCadMultiSegments(_pCadBeeline, _pCadMultiSegments, pvectorIntersect_);
- }
- break;
-
- // 直线和群组 --- 吴阳明 2010 10 21
- case (cadbeeline << 16 | cadgroup):
- {
- C_ASSERT(cadbeeline <= cadgroup);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*>(_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadBeeline, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 直线和文字 --- 吴阳明 2010 10 21
- case (cadbeeline << 16 | cadtext):
- {
- C_ASSERT(cadbeeline <= cadtext);
-
- const CCadBeeline* _pCadBeeline = dynamic_cast<const CCadBeeline*>(_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadBeeline, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 圆和圆 --- 吴阳明 2010 09 19
- case (cadcircle << 16 | cadcircle):
- {
- C_ASSERT(cadcircle <= cadcircle);
-
- const CCadCircle* _pCadCircle1 = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadCircle* _pCadCircle2 = dynamic_cast<const CCadCircle*> (_pCadObject2);
- _nResult = Intersect_CadCircleWithCadCircle(_pCadCircle1, _pCadCircle2, pvectorIntersect_);
- }
- break;
-
- // 圆和圆弧 --- 吴阳明 2010 09 19
- case (cadcircle << 16 | cadarc):
- {
- C_ASSERT(cadcircle <= cadarc);
-
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject2);
- _nResult = Intersect_CadArcWithCadCircle(_pCadArc, _pCadCircle, pvectorIntersect_);
- }
- break;
-
- // 圆和椭圆 --- 吴阳明 2010 09 19
- case (cadcircle << 16 | cadellipse):
- {
- C_ASSERT(cadcircle <= cadellipse);
-
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject2);
- _nResult = Intersect_CadCircleWithCadEllipse(_pCadCircle, _pCadEllipse, pvectorIntersect_);
- }
- break;
-
- // 圆和椭圆弧 --- 吴阳明 2010 09 19
- case (cadcircle << 16 | cadellipsearc):
- {
- C_ASSERT(cadcircle <= cadellipsearc);
-
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject2);
- _nResult = Intersect_CadCircleWithCadEllipseArc(_pCadCircle, _pCadEllipseArc, pvectorIntersect_);
- }
- break;
-
- // 圆和多段线 --- 吴阳明 2010 09 19
- case (cadcircle << 16 | cadmultisegments):
- case (cadcircle << 16 | cadrectangle):
- case (cadcircle << 16 | cadstar):
- case (cadcircle << 16 | cadpolygon):
- case (cadcircle << 16 | cadpolyline):
- {
- C_ASSERT(cadcircle <= cadmultisegments &&
- cadcircle <= cadrectangle &&
- cadcircle <= cadstar &&
- cadcircle <= cadpolygon &&
- cadcircle <= cadpolyline);
-
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadCircleWithCadMultiSegments(_pCadCircle, _pCadMultiSegments, pvectorIntersect_);
- }
- break;
-
- // 圆和群组 --- 吴阳明 2010 10 21
- case (cadcircle << 16 | cadgroup):
- {
- C_ASSERT(cadcircle <= cadgroup);
-
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadCircle, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 圆和文字 --- 吴阳明 2010 10 21
- case (cadcircle<< 16 | cadtext):
- {
- C_ASSERT(cadcircle <= cadtext);
-
- const CCadCircle* _pCadCircle = dynamic_cast<const CCadCircle*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadCircle, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 圆弧和圆弧 --- 吴阳明 2010 09 19
- case (cadarc << 16 | cadarc):
- {
- C_ASSERT(cadarc <= cadarc);
-
- const CCadArc* _pCadArc1 = dynamic_cast<const CCadArc*> (_pCadObject1);
- const CCadArc* _pCadArc2 = dynamic_cast<const CCadArc*> (_pCadObject2);
- _nResult = Intersect_CadArcWithCadArc(_pCadArc1, _pCadArc2, pvectorIntersect_);
- }
- break;
-
- // 圆弧和椭圆 --- 吴阳明 2010 09 19
- case (cadarc << 16 | cadellipse):
- {
- C_ASSERT(cadarc <= cadellipse);
-
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject1);
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject2);
- _nResult = Intersect_CadArcWithCadEllipse(_pCadArc, _pCadEllipse, pvectorIntersect_);
- }
- break;
-
- // 圆弧和椭圆弧 --- 吴阳明 2010 09 19
- case (cadarc << 16 | cadellipsearc):
- {
- C_ASSERT(cadarc <= cadellipsearc);
-
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject1);
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject2);
- _nResult = Intersect_CadArcWithCadEllipseArc(_pCadArc, _pCadEllipseArc, pvectorIntersect_);
- }
- break;
-
- // 圆弧和多段线 --- 吴阳明 2010 09 19
- case (cadarc << 16 | cadmultisegments):
- case (cadarc << 16 | cadrectangle):
- case (cadarc << 16 | cadstar):
- case (cadarc << 16 | cadpolygon):
- case (cadarc << 16 | cadpolyline):
- {
- C_ASSERT(cadarc <= cadmultisegments &&
- cadarc <= cadrectangle &&
- cadarc <= cadstar &&
- cadarc <= cadpolygon &&
- cadarc <= cadpolyline);
-
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadArcWithCadMultiSegments(_pCadArc, _pCadMultiSegments, pvectorIntersect_);
- }
- break;
-
- // 圆弧和群组 --- 吴阳明 2010 10 21
- case (cadarc << 16 | cadgroup):
- {
- C_ASSERT(cadarc <= cadgroup);
-
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadArc, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 圆弧和文字 --- 吴阳明 2010 10 21
- case (cadarc<< 16 | cadtext):
- {
- C_ASSERT(cadarc <= cadtext);
-
- const CCadArc* _pCadArc = dynamic_cast<const CCadArc*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadArc, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 椭圆和椭圆 --- 吴阳明 2010 09 19
- case (cadellipse << 16 | cadellipse):
- {
- C_ASSERT(cadellipse <= cadellipse);
-
- const CCadEllipse* _pCadEllipse1 = dynamic_cast<const CCadEllipse*> (_pCadObject1);
- const CCadEllipse* _pCadEllipse2 = dynamic_cast<const CCadEllipse*> (_pCadObject2);
- _nResult = Intersect_CadEllipseWithCadEllipse(_pCadEllipse1, _pCadEllipse2, pvectorIntersect_);
- }
- break;
-
- // 椭圆和椭圆弧 --- 吴阳明 2010 09 19
- case (cadellipse << 16 | cadellipsearc):
- {
- C_ASSERT(cadellipse <= cadellipsearc);
-
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject1);
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject2);
- _nResult = Intersect_CadEllipseWithCadEllipseArc(_pCadEllipse, _pCadEllipseArc, pvectorIntersect_);
- }
- break;
-
- // 椭圆和多段线 --- 吴阳明 2010 09 19
- case (cadellipse << 16 | cadmultisegments):
- case (cadellipse << 16 | cadrectangle):
- case (cadellipse << 16 | cadstar):
- case (cadellipse << 16 | cadpolygon):
- case (cadellipse << 16 | cadpolyline):
- {
- C_ASSERT(cadellipse <= cadmultisegments &&
- cadellipse <= cadrectangle &&
- cadellipse <= cadstar &&
- cadellipse <= cadpolygon &&
- cadellipse <= cadpolyline);
-
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadMultiSegmentsWithCadEllipse(_pCadMultiSegments, _pCadEllipse, pvectorIntersect_);
- }
- break;
-
- // 椭圆和群组 --- 吴阳明 2010 10 21
- case (cadellipse << 16 | cadgroup):
- {
- C_ASSERT(cadellipse <= cadgroup);
-
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadEllipse, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 椭圆和文字 --- 吴阳明 2010 10 21
- case (cadellipse<< 16 | cadtext):
- {
- C_ASSERT(cadellipse <= cadtext);
-
- const CCadEllipse* _pCadEllipse = dynamic_cast<const CCadEllipse*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadEllipse, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 椭圆弧和椭圆弧 --- 吴阳明 2010 09 19
- case (cadellipsearc << 16 | cadellipsearc):
- {
- C_ASSERT(cadellipsearc <= cadellipsearc);
-
- const CCadEllipseArc* _pCadEllipseArc1 = dynamic_cast<const CCadEllipseArc*> (_pCadObject1);
- const CCadEllipseArc* _pCadEllipseArc2 = dynamic_cast<const CCadEllipseArc*> (_pCadObject2);
- _nResult = Intersect_CadEllipseArcWithCadEllipseArc(_pCadEllipseArc1, _pCadEllipseArc2, pvectorIntersect_);
- }
- break;
-
- // 椭圆弧和多段线 --- 吴阳明 2010 09 19
- case (cadellipsearc << 16 | cadmultisegments):
- case (cadellipsearc << 16 | cadrectangle):
- case (cadellipsearc << 16 | cadstar):
- case (cadellipsearc << 16 | cadpolygon):
- case (cadellipsearc << 16 | cadpolyline):
- {
- C_ASSERT(cadellipsearc <= cadmultisegments &&
- cadellipsearc <= cadrectangle &&
- cadellipsearc <= cadstar &&
- cadellipsearc <= cadpolygon &&
- cadellipsearc <= cadpolyline);
-
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadMultiSegmentsWithCadEllipseArc(_pCadMultiSegments, _pCadEllipseArc, pvectorIntersect_);
- }
- break;
-
- // 椭圆弧和群组 --- 吴阳明 2010 10 21
- case (cadellipsearc << 16 | cadgroup):
- {
- C_ASSERT(cadellipsearc <= cadgroup);
-
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadEllipseArc, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 椭圆弧和文字 --- 吴阳明 2010 10 21
- case (cadellipsearc<< 16 | cadtext):
- {
- C_ASSERT(cadellipsearc <= cadtext);
-
- const CCadEllipseArc* _pCadEllipseArc = dynamic_cast<const CCadEllipseArc*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadEllipseArc, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 多段线和多段线 --- 吴阳明 2010 09 19
- case (cadmultisegments << 16 | cadmultisegments):
- case (cadmultisegments << 16 | cadrectangle):
- case (cadmultisegments << 16 | cadpolygon):
- case (cadmultisegments << 16 | cadstar):
- case (cadmultisegments << 16 | cadpolyline):
- case (cadrectangle << 16 | cadrectangle):
- case (cadrectangle << 16 | cadpolygon):
- case (cadrectangle << 16 | cadstar):
- case (cadrectangle << 16 | cadpolyline):
- case (cadpolygon << 16 | cadpolygon):
- case (cadpolygon << 16 | cadstar):
- case (cadpolygon << 16 | cadpolyline):
- case (cadstar << 16 | cadstar):
- case (cadstar << 16 | cadpolyline):
- case (cadpolyline << 16 | cadpolyline):
- {
- C_ASSERT(cadmultisegments <= cadrectangle &&
- cadrectangle <= cadpolygon &&
- cadpolygon <= cadstar &&
- cadstar <= cadpolyline);
-
- const CCadMultiSegments* _pCadMultiSegments1 = dynamic_cast<const CCadMultiSegments*> (_pCadObject1);
- const CCadMultiSegments* _pCadMultiSegments2 = dynamic_cast<const CCadMultiSegments*> (_pCadObject2);
- _nResult = Intersect_CadMultiSegmentsWithCadMultiSegments(_pCadMultiSegments1, _pCadMultiSegments2, pvectorIntersect_);
- }
- break;
-
- // 多段线和群组 --- 吴阳明 2010 10 21
- case (cadmultisegments << 16 | cadgroup):
- case (cadrectangle << 16 | cadgroup):
- case (cadpolygon << 16 | cadgroup):
- case (cadstar << 16 | cadgroup):
- case (cadpolyline << 16 | cadgroup):
- {
- C_ASSERT(cadmultisegments <= cadgroup &&
- cadrectangle <= cadgroup &&
- cadpolygon <= cadgroup &&
- cadstar <= cadgroup &&
- cadpolyline <= cadgroup);
-
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject1);
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadGroup(_pCadMultiSegments, _pCadGroup, pvectorIntersect_);
- }
- break;
-
- // 多段线和文字 --- 吴阳明 2010 10 21
- case (cadmultisegments << 16 | cadtext):
- case (cadrectangle << 16 | cadtext):
- case (cadpolygon << 16 | cadtext):
- case (cadstar << 16 | cadtext):
- case (cadpolyline << 16 | cadtext):
- {
- C_ASSERT(cadmultisegments <= cadtext &&
- cadrectangle <= cadtext &&
- cadpolygon <= cadtext &&
- cadstar <= cadtext &&
- cadpolyline <= cadtext);
-
- const CCadMultiSegments* _pCadMultiSegments = dynamic_cast<const CCadMultiSegments*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadObjectWithCadText(_pCadMultiSegments, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 椭圆弧和群组 --- 吴阳明 2010 10 21
- case (cadgroup << 16 | cadgroup):
- {
- C_ASSERT(cadgroup <= cadgroup);
-
- const CCadGroup* _pCadGroup1 = dynamic_cast<const CCadGroup*> (_pCadObject1);
- const CCadGroup* _pCadGroup2 = dynamic_cast<const CCadGroup*> (_pCadObject2);
- _nResult = Intersect_CadGroupWithCadGroup(_pCadGroup1, _pCadGroup2, pvectorIntersect_);
- }
- break;
-
- // 群组和文字 --- 吴阳明 2010 10 21
- case (cadgroup<< 16 | cadtext):
- {
- C_ASSERT(cadgroup <= cadtext);
-
- const CCadGroup* _pCadGroup = dynamic_cast<const CCadGroup*> (_pCadObject1);
- const CCadText* _pCadText = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadGroupWithCadText(_pCadGroup, _pCadText, pvectorIntersect_);
- }
- break;
-
- // 文字和文字 --- 吴阳明 2010 10 21
- case (cadtext<< 16 | cadtext):
- {
- C_ASSERT(cadgroup <= cadtext);
-
- const CCadText* _pCadText1 = dynamic_cast<const CCadText*> (_pCadObject1);
- const CCadText* _pCadText2 = dynamic_cast<const CCadText*> (_pCadObject2);
- _nResult = Intersect_CadTextWithCadText(_pCadText1, _pCadText2, pvectorIntersect_);
- }
- break;
-
- default:
- break;
- }
-
- return _nResult;
- }
-
- int nce::Intersect_CadArcWithCadArc(IN const CCadArc* pCadArc1_,
- IN const CCadArc* pCadArc2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadArc1_);
- ASSERT(pCadArc2_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadArc1_->GetLength()));
- ASSERT(DOUBLE_GREAT_ZERO(pCadArc2_->GetLength()));
-
- // 圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptArc1Center = pCadArc1_->GetCenterPoint();
- DPOINT2 _ptArc2Center = pCadArc2_->GetCenterPoint();
-
- double _nArc1Radius = pCadArc1_->GetRadius();
- double _nArc2Radius = pCadArc2_->GetRadius();
-
- double _nArc1StartAngle = pCadArc1_->GetStartAngle();
- double _nArc2StartAngle = pCadArc2_->GetStartAngle();
-
- double _nFactor1 = pCadArc1_->IsNormalDir() ? 1 : -1;
- double _nFactor2 = pCadArc2_->IsNormalDir() ? 1 : -1;
-
- double _nArc1CentralAngle = pCadArc1_->GetCentralAngle() * _nFactor1;
- double _nArc2CentralAngle = pCadArc2_->GetCentralAngle() * _nFactor2;
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_ArcWithArc(_ptArc1Center, _nArc1Radius, _nArc1StartAngle, _nArc1CentralAngle,
- _ptArc2Center, _nArc2Radius, _nArc2StartAngle, _nArc2CentralAngle, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadArcWithCadCircle(IN const CCadArc* pCadArc_,
- IN const CCadCircle* pCadCircle_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadArc_);
- ASSERT(pCadCircle_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadArc_->GetLength()));
- ASSERT(DOUBLE_GREAT_ZERO(pCadCircle_->GetLength()));
-
- // 圆心 --- 吴阳明 2010 09 09
- DPOINT2 _ptArcCenter = pCadArc_->GetCenterPoint();
- DPOINT2 _ptCircleCenter = pCadCircle_->GetCenterPoint();
-
- // 半径 --- 吴阳明 2010 09 09
- double _nArcRadius = pCadArc_->GetRadius();
- double _nCircleRadius = pCadCircle_->GetRadius();
-
- // 圆弧起始角和中心角 --- 吴阳明 2010 09 09
- double _nArcStartAngle = pCadArc_->GetStartAngle();
- double _nArcCentralAngle = pCadArc_->GetCentralAngle();
-
- // 将中心角赋予方向 --- 吴阳明 2010 09 09
- double _nFactor = pCadArc_->IsNormalDir() ? 1 : -1;
- _nArcCentralAngle *= _nFactor;
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_CircleWithArc(_ptCircleCenter, _nCircleRadius, _ptArcCenter,
- _nArcRadius, _nArcStartAngle, _nArcCentralAngle, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadArcWithCadEllipse(IN const CCadArc* pCadArc_,
- IN const CCadEllipse* pCadEllipse_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadArc_);
- ASSERT(pCadEllipse_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptArcCenter = pCadArc_->GetCenterPoint();
- double _nRadius = pCadArc_->GetRadius();
- double _nArcStartAngle = pCadArc_->GetStartAngle();
- double _nArcSweptAngle = pCadArc_->GetCentralAngle();
- if (!pCadArc_->IsNormalDir())
- _nArcSweptAngle *= -1;
-
- // 椭圆信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptEllipseCenter = pCadEllipse_->GetCenterPoint();
- double _nLongRadius = pCadEllipse_->GetLongRadius();
- double _nShortRadius = pCadEllipse_->GetShortRadius();
- double _nAngle = pCadEllipse_->GetAngle();
-
- int _nRet = 0;
- if (!pvectorIntersect_)
- {
- _nRet = Intersect_ArcWithEllipse(_ptArcCenter, _nRadius, _nArcStartAngle, _nArcSweptAngle,
- _ptEllipseCenter, _nLongRadius, _nShortRadius, _nAngle);
- }
- else
- {
- _nRet = Intersect_ArcWithEllipse(_ptArcCenter, _nRadius, _nArcStartAngle, _nArcSweptAngle,
- _ptEllipseCenter, _nLongRadius, _nShortRadius, _nAngle, *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadArcWithCadEllipseArc(IN const CCadArc* pCadArc_,
- IN const CCadEllipseArc* pCadEllipseArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadArc_);
- ASSERT(pCadEllipseArc_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptArcCenter = pCadArc_->GetCenterPoint();
- double _nRadius = pCadArc_->GetRadius();
- double _nArcStartAngle = pCadArc_->GetStartAngle();
- double _nArcSweptAngle = pCadArc_->GetCentralAngle();
- if (!pCadArc_->IsNormalDir())
- _nArcSweptAngle *= -1;
-
- // 椭圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptEllipseArcCenter = pCadEllipseArc_->GetCenterPoint();
- double _nLongRadius = pCadEllipseArc_->GetLongRadius();
- double _nShortRadius = pCadEllipseArc_->GetShortRadius();
- double _nAngle = pCadEllipseArc_->GetAngle();
- double _nEllipseArcStartAngle = pCadEllipseArc_->GetStartAngle();
- double _nEllipseArcSweptAngle = pCadEllipseArc_->GetCentralAngle();
- if (!pCadEllipseArc_->IsNormalDir())
- _nEllipseArcSweptAngle *= -1;
-
- int _nRet = 0;
- if (!pvectorIntersect_)
- {
- _nRet = Intersect_ArcWithEllipseArc(
- _ptArcCenter, _nRadius, _nArcStartAngle, _nArcSweptAngle,
- _ptEllipseArcCenter, _nLongRadius, _nShortRadius, _nAngle,
- _nEllipseArcStartAngle, _nEllipseArcSweptAngle);
- }
- else
- {
- _nRet = Intersect_ArcWithEllipseArc(
- _ptArcCenter, _nRadius, _nArcStartAngle, _nArcSweptAngle,
- _ptEllipseArcCenter, _nLongRadius, _nShortRadius, _nAngle,
- _nEllipseArcStartAngle, _nEllipseArcSweptAngle, *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadArcWithCadMultiSegments(IN const CCadArc* pCadArc_,
- IN const CCadMultiSegments* pCadMultiSegments_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadArc_);
- ASSERT(pCadMultiSegments_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadArc_->GetLength()));
- ASSERT(DOUBLE_GREAT_ZERO(pCadMultiSegments_->GetLength()));
-
- // 信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptArc1Center = pCadArc_->GetCenterPoint();
- double _nArc1Radius = pCadArc_->GetRadius();
- double _nArc1StartAngle = pCadArc_->GetStartAngle();
-
- double _nFactor = pCadArc_->IsNormalDir() ? 1 : -1;
- double _nArc1CentralAngle = _nFactor * pCadArc_->GetCentralAngle();
-
- int _nResult = 0;
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- // 将圆弧同多段线个片段求交 --- 吴阳明 2010 09 19
- for (int _i = 0; _i != pCadMultiSegments_->GetSegmentCount(); ++_i)
- {
- SEGMENT _Segment = pCadMultiSegments_->GetSegment(_i);
- std::vector<DPOINT2> _vectorTemp;
-
- switch(_Segment.nType)
- {
- // 圆弧求交 --- 吴阳明 2010 09 19
- case SEGMENT::ARC:
- {
- DPOINT2 _ptArc2Center(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArc2Radius = 0.0;
- double _nArc2StartAngle = 0.0;
- double _nArc2CentralAngle = 0.0;
-
- SEGMENT::SolveArc(_Segment.ptStart, _Segment.ptEnd, _Segment.nBulge,
- &_ptArc2Center, &_nArc2Radius, &_nArc2StartAngle, &_nArc2CentralAngle);
-
- _nResult += ncmath::Intersect_ArcWithArc(_ptArc1Center, _nArc1Radius, _nArc1StartAngle,
- _nArc1CentralAngle, _ptArc2Center, _nArc2Radius,
- _nArc2StartAngle, _nArc2CentralAngle, _vectorTemp,
- _nNeed);
- }
- break;
-
- // 线段求交 --- 吴阳明 2010 09 19
- case SEGMENT::LINE:
- {
- _nResult += ncmath::Intersect_LineWithArc(_Segment.ptStart, _Segment.ptEnd, _ptArc1Center,
- _nArc1Radius, _nArc1StartAngle, _nArc1CentralAngle, _vectorTemp, _nNeed);
- }
- break;
-
- // 不支持的格式 --- 吴阳明 2010 09 19
- case SEGMENT::BEZIER:
- default:
- ASSERT(false);
- }
-
- if (pvectorIntersect_ != NULL && !_vectorTemp.empty())
- copy(_vectorTemp.begin(), _vectorTemp.end(), back_inserter(*pvectorIntersect_));
- }
- return _nResult;
- }
-
- int nce::Intersect_CadBeelineWithCadArc(IN const CCadBeeline* pCadBeeline_,
- IN const CCadArc* pCadArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadArc_);
- ASSERT(pCadBeeline_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadArc_->GetLength()));
-
- //直线和圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptBeeline = pCadBeeline_->GetPoint();
- double _nAngle = pCadBeeline_->GetAngle();
-
- DPOINT2 _ptArcCenter = pCadArc_->GetCenterPoint();
- double _nArcRadius = pCadArc_->GetRadius();
- double _nArcStartAngle = pCadArc_->GetStartAngle();
-
- double _nFactor = pCadArc_->IsNormalDir() ? 1 : -1;
- double _nArcCentralAngle = _nFactor * pCadArc_->GetCentralAngle();
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_BeelineWithArc(_ptBeeline, _nAngle, _ptArcCenter,_nArcRadius,
- _nArcStartAngle, _nArcCentralAngle, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadBeelineWithCadBeeline(IN const CCadBeeline* pCadBeeline1_,
- IN const CCadBeeline* pCadBeeline2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadBeeline1_);
- ASSERT(pCadBeeline2_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
-
- // 直线信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptBeeline1 = pCadBeeline1_->GetPoint();
- double _nAngle1 = pCadBeeline1_->GetAngle();
-
- DPOINT2 _ptBeeline2 = pCadBeeline2_->GetPoint();
- double _nAngle2 = pCadBeeline2_->GetAngle();
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_BeelineWithBeeline(_ptBeeline1, _nAngle1,
- _ptBeeline2, _nAngle2, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadBeelineWithCadCircle(IN const CCadBeeline* pCadBeeline_,
- IN const CCadCircle* pCadCircle_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadBeeline_);
- ASSERT(pCadCircle_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadCircle_->GetLength()));
-
- DPOINT2 _ptBeeline = pCadBeeline_->GetPoint();
- double _nAngle = pCadBeeline_->GetAngle();
-
- DPOINT2 _ptCircleCenter = pCadCircle_->GetCenterPoint();
- double _nCircleRadius = pCadCircle_->GetRadius();
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_BeelineWithCircle(_ptBeeline, _nAngle,_ptCircleCenter,
- _nCircleRadius, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadBeelineWithCadEllipse(IN const CCadBeeline* pCadBeeline_,
- IN const CCadEllipse* pCadEllipse_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadBeeline_);
- ASSERT(pCadEllipse_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
-
- // 直线和椭圆信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptBeeline = pCadBeeline_->GetPoint();
- double _nAngle = pCadBeeline_->GetAngle();
-
- DPOINT2 _ptCenter = pCadEllipse_->GetCenterPoint();
- double _nLRadius = pCadEllipse_->GetLongRadius();
- double _nSRadius = pCadEllipse_->GetShortRadius();
- double _nUAngle = pCadEllipse_->GetAngle();
-
- return ncmath::Intersect_BeelineWithEllipse(_ptBeeline, _nAngle, _ptCenter, _nLRadius,
- _nSRadius, _nUAngle, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadBeelineWithCadEllipseArc(IN const CCadBeeline* pCadBeeline_,
- IN const CCadEllipseArc* pCadEllipseArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadBeeline_);
- ASSERT(pCadEllipseArc_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
-
- // 直线信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptBeeline = pCadBeeline_->GetPoint();
- double _nAngle = pCadBeeline_->GetAngle();
-
- // 椭圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptCenter = pCadEllipseArc_->GetCenterPoint();
- double _nLRadius = pCadEllipseArc_->GetLongRadius();
- double _nSRadius = pCadEllipseArc_->GetShortRadius();
- double _nUAngle = pCadEllipseArc_->GetAngle();
- double _nStartAngle = pCadEllipseArc_->GetStartAngle();
- double _nFactor = pCadEllipseArc_->IsNormalDir() ? 1 : -1;
- double _nCentralAngle = pCadEllipseArc_->GetCentralAngle() * _nFactor;
-
- return ncmath::Intersect_BeelineWithEllipseArc(_ptBeeline, _nAngle, _ptCenter, _nLRadius, _nSRadius,
- _nUAngle,_nStartAngle, _nCentralAngle, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadBeelineWithCadMultiSegments(IN const CCadBeeline* pCadBeeline_,
- IN const CCadMultiSegments* pCadMultiSegments_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadBeeline_);
- ASSERT(pCadMultiSegments_);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadMultiSegments_->GetLength()));
-
- DPOINT2 _ptBeeline = pCadBeeline_->GetPoint();
- double _nAngle = pCadBeeline_->GetAngle();
-
- int _nResult = 0;
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- for (int _i = 0; _i < pCadMultiSegments_->GetSegmentCount(); ++_i)
- {
- SEGMENT _Segment = pCadMultiSegments_->GetSegment(_i);
- std::vector<DPOINT2> _vectorTemp;
-
- switch(_Segment.nType)
- {
- case SEGMENT::ARC:
- {
- DPOINT2 _ptArcCenter(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArcRadius = 0.0;
- double _nArcStartAngle = 0.0;
- double _nArcCentralAngle = 0.0;
-
- SEGMENT::SolveArc(_Segment.ptStart, _Segment.ptEnd, _Segment.nBulge,
- &_ptArcCenter, &_nArcRadius, &_nArcStartAngle, &_nArcCentralAngle);
-
- _nResult += ncmath::Intersect_BeelineWithArc(_ptBeeline, _nAngle, _ptArcCenter,
- _nArcRadius, _nArcStartAngle, _nArcCentralAngle, _vectorTemp, _nNeed);
- }
- break;
-
- case SEGMENT::LINE:
- {
- _nResult += ncmath::Intersect_BeelineWithLine(_ptBeeline, _nAngle, _Segment.ptStart,
- _Segment.ptEnd, _vectorTemp, _nNeed);
- }
- break;
- default:
- ASSERT(false);
- }
-
- // 有交点且需要存储则存储到容器中 --- 吴阳明 2010 09 19
- if (pvectorIntersect_ != NULL && !_vectorTemp.empty())
- copy(_vectorTemp.begin(), _vectorTemp.end(), back_inserter(*pvectorIntersect_));
- }
-
- return _nResult;
- }
-
- int nce::Intersect_CadCircleWithCadCircle(IN const CCadCircle* pCadCircle1_,
- IN const CCadCircle* pCadCircle2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadCircle1_ != NULL);
- ASSERT(pCadCircle1_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_CircleWithCircle(pCadCircle1_->GetCenterPoint(), pCadCircle1_->GetRadius(),
- pCadCircle2_->GetCenterPoint(), pCadCircle2_->GetRadius(), *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadCircleWithCadEllipse(IN const CCadCircle* pCadCircle_,
- IN const CCadEllipse* pCadEllipse_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadCircle_);
- ASSERT(pCadEllipse_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- DPOINT2 _ptCircleCenter = pCadCircle_->GetCenterPoint();
- double _nRadius = pCadCircle_->GetRadius();
- DPOINT2 _ptEllipseCenter = pCadEllipse_->GetCenterPoint();
- double _nLongRadius = pCadEllipse_->GetLongRadius();
- double _nShortRadius = pCadEllipse_->GetShortRadius();
- double _nAngle = pCadEllipse_->GetAngle();
-
- int _nRet = 0;
- if (!pvectorIntersect_)
- {
- _nRet = Intersect_CircleWithEllipse(_ptCircleCenter, _nRadius, _ptEllipseCenter,
- _nLongRadius, _nShortRadius, _nAngle);
- }
- else
- {
- _nRet = Intersect_CircleWithEllipse(_ptCircleCenter, _nRadius, _ptEllipseCenter,
- _nLongRadius, _nShortRadius, _nAngle, *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadCircleWithCadEllipseArc(IN const CCadCircle* pCadCircle_,
- IN const CCadEllipseArc* pCadEllipseArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadCircle_);
- ASSERT(pCadEllipseArc_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- DPOINT2 _ptCircleCenter = pCadCircle_->GetCenterPoint();
- double _nRadius = pCadCircle_->GetRadius();
- DPOINT2 _ptEllipseArcCenter = pCadEllipseArc_->GetCenterPoint();
- double _nLongRadius = pCadEllipseArc_->GetLongRadius();
- double _nShortRadius = pCadEllipseArc_->GetShortRadius();
- double _nAngle = pCadEllipseArc_->GetAngle();
- double _nStartAngle = pCadEllipseArc_->GetStartAngle();
- double _nSweptAngle = pCadEllipseArc_->GetCentralAngle();
-
- if (!pCadEllipseArc_->IsNormalDir())
- _nSweptAngle *= -1;
-
- int _nRet = 0;
- if (!pvectorIntersect_)
- {
- _nRet = Intersect_CircleWithEllipseArc(_ptCircleCenter, _nRadius, _ptEllipseArcCenter,
- _nLongRadius, _nShortRadius, _nAngle, _nStartAngle, _nSweptAngle);
- }
- else
- {
- _nRet = Intersect_CircleWithEllipseArc(_ptCircleCenter, _nRadius, _ptEllipseArcCenter,
- _nLongRadius, _nShortRadius, _nAngle,_nStartAngle, _nSweptAngle, *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadCircleWithCadMultiSegments(IN const CCadCircle* pCadCircle_,
- IN const CCadMultiSegments* pCadMultiSegments_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadCircle_ != NULL);
- ASSERT(pCadMultiSegments_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- int _nSegCount = pCadMultiSegments_->GetSegmentCount();
- for (int _i = 0; _i < _nSegCount; ++_i)
- {
- std::vector<DPOINT2> _vecTmp;
-
- SEGMENT _segTmp = pCadMultiSegments_->GetSegment(_i);
- switch (_segTmp.nType)
- {
- case SEGMENT::ARC:
- {
-
- DPOINT2 _ptArcCenter(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArcRadius = 0.0;
- double _nArcStartAngle = 0.0, _nArcCentralAngle = 0.0;
-
- SEGMENT::SolveArc(_segTmp.ptStart, _segTmp.ptEnd, _segTmp.nBulge,
- &_ptArcCenter, &_nArcRadius, &_nArcStartAngle, &_nArcCentralAngle);
-
- _nResult += ncmath::Intersect_CircleWithArc(pCadCircle_->GetCenterPoint(), pCadCircle_->GetRadius(),
- _ptArcCenter, _nArcRadius, _nArcStartAngle, _nArcCentralAngle, _vecTmp);
- }
- break;
-
- case SEGMENT::LINE:
- _nResult += ncmath::Intersect_LineWithCircle(_segTmp.ptStart, _segTmp.ptEnd,
- pCadCircle_->GetCenterPoint(), pCadCircle_->GetRadius(), _vecTmp);
- break;
-
- case SEGMENT::BEZIER:
- default:
- // 这里可以选择抛出异常 --- wanghong 2010 09 12
- ASSERT(false);
- }
-
- if (pvectorIntersect_ != NULL && !_vecTmp.empty())
- std::copy(_vecTmp.begin(), _vecTmp.end(), std::back_inserter(*pvectorIntersect_));
- }
-
- return _nResult;
- }
-
- int nce::Intersect_CadEllipseWithCadEllipse(IN const CCadEllipse* pCadEllipse1_,
- IN const CCadEllipse* pCadEllipse2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadEllipse1_);
- ASSERT(pCadEllipse2_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 提取几何参数。椭圆所需的几何参数有:中心点、长半轴、短半轴、长半轴对X正向
- // 的倾角。 ---- 杨开锦 2010-09-14
- DPOINT2 _ptCenter1 = pCadEllipse1_->GetCenterPoint();
- double _nURadius1 = pCadEllipse1_->GetLongRadius();
- double _nVRadius1 = pCadEllipse1_->GetShortRadius();
- double _nUAngle1 = pCadEllipse1_->GetAngle();
- DPOINT2 _ptCenter2 = pCadEllipse2_->GetCenterPoint();
- double _nURadius2 = pCadEllipse2_->GetLongRadius();
- double _nVRadius2 = pCadEllipse2_->GetShortRadius();
- double _nUAngle2 = pCadEllipse2_->GetAngle();
-
- // 调用数学函数计算交点 ---- 杨开锦 2010-09-14
- int _nRet = 0;
- if (pvectorIntersect_ == NULL)
- {
- _nRet = ncmath::Intersect_EllipseWithEllipse(
- _ptCenter1, _nURadius1, _nVRadius1, _nUAngle1,
- _ptCenter2, _nURadius2, _nVRadius2, _nUAngle2);
- }
- else
- {
- _nRet = ncmath::Intersect_EllipseWithEllipse(
- _ptCenter1, _nURadius1, _nVRadius1, _nUAngle1,
- _ptCenter2, _nURadius2, _nVRadius2, _nUAngle2,
- *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadEllipseWithCadEllipseArc(IN const CCadEllipse* pCadEllipse_,
- IN const CCadEllipseArc* pCadEllipseArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadEllipse_);
- ASSERT(pCadEllipseArc_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 提取几何参数。椭圆所需的几何参数有:中心点、长半轴、短半轴、长半轴对X正向
- // 的倾角;椭圆弧所需的几何参数有:中心点、长半轴、短半轴、长半轴对X正向的倾
- // 角、起始角、扫过角。 ---- 杨开锦 2010-09-14
- DPOINT2 _ptCenter1 = pCadEllipse_->GetCenterPoint();
- double _nURadius1 = pCadEllipse_->GetLongRadius();
- double _nVRadius1 = pCadEllipse_->GetShortRadius();
- double _nUAngle1 = pCadEllipse_->GetAngle();
- DPOINT2 _ptCenter2 = pCadEllipseArc_->GetCenterPoint();
- double _nURadius2 = pCadEllipseArc_->GetLongRadius();
- double _nVRadius2 = pCadEllipseArc_->GetShortRadius();
- double _nUAngle2 = pCadEllipseArc_->GetAngle();
- double _nStartAngle2 = pCadEllipseArc_->GetStartAngle();
- double _nSweptAngle2 = pCadEllipseArc_->GetCentralAngle();
- if (!pCadEllipseArc_->IsNormalDir())
- {
- // 数学函数中只接受逆时针椭圆弧 ---- 杨开锦 2010-09-14
- _nStartAngle2 -= _nSweptAngle2;
-
- while (_nStartAngle2 < 0.0)
- {
- _nStartAngle2 += 2.0 * c_nPIE;
- }
-
- while (_nStartAngle2 >= 2.0 * c_nPIE)
- {
- _nStartAngle2 -= 2.0 * c_nPIE;
- }
- }
-
- // 调用数学函数计算交点 ---- 杨开锦 2010-09-14
- int _nRet = 0;
- if (pvectorIntersect_ == NULL)
- {
- _nRet = ncmath::Intersect_EllipseWithEllipseArc(
- _ptCenter1, _nURadius1, _nVRadius1, _nUAngle1,
- _ptCenter2, _nURadius2, _nVRadius2, _nUAngle2, _nStartAngle2, _nSweptAngle2);
- }
- else
- {
- _nRet = ncmath::Intersect_EllipseWithEllipseArc(
- _ptCenter1, _nURadius1, _nVRadius1, _nUAngle1,
- _ptCenter2, _nURadius2, _nVRadius2, _nUAngle2, _nStartAngle2, _nSweptAngle2,
- *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadEllipseArcWithCadEllipseArc(IN const CCadEllipseArc* pCadEllipseArc1_,
- IN const CCadEllipseArc* pCadEllipseArc2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadEllipseArc1_);
- ASSERT(pCadEllipseArc2_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 提取几何参数。椭圆弧所需的几何参数有:中心点、长半轴、短半轴、长半轴对X正
- // 向的倾角、起始角、扫过角。 ---- 杨开锦 2010-09-14
- DPOINT2 _ptCenter1 = pCadEllipseArc1_->GetCenterPoint();
- double _nURadius1 = pCadEllipseArc1_->GetLongRadius();
- double _nVRadius1 = pCadEllipseArc1_->GetShortRadius();
- double _nUAngle1 = pCadEllipseArc1_->GetAngle();
- double _nStartAngle1 = pCadEllipseArc1_->GetStartAngle();
- double _nSweptAngle1 = pCadEllipseArc1_->GetCentralAngle();
- if (!pCadEllipseArc1_->IsNormalDir())
- {
- // 数学函数中只接受逆时针椭圆弧 ---- 杨开锦 2010-09-14
- _nStartAngle1 -= _nSweptAngle1;
-
- while (_nStartAngle1 < 0.0)
- {
- _nStartAngle1 += 2.0 * c_nPIE;
- }
-
- while (_nStartAngle1 >= 2.0 * c_nPIE)
- {
- _nStartAngle1 -= 2.0 * c_nPIE;
- }
- }
-
- // 同上 ---- 杨开锦 2010-09-14
- DPOINT2 _ptCenter2 = pCadEllipseArc2_->GetCenterPoint();
- double _nURadius2 = pCadEllipseArc2_->GetLongRadius();
- double _nVRadius2 = pCadEllipseArc2_->GetShortRadius();
- double _nUAngle2 = pCadEllipseArc2_->GetAngle();
- double _nStartAngle2 = pCadEllipseArc2_->GetStartAngle();
- double _nSweptAngle2 = pCadEllipseArc2_->GetCentralAngle();
- if (!pCadEllipseArc2_->IsNormalDir())
- {
- _nStartAngle2 -= _nSweptAngle2;
-
- while (_nStartAngle2 < 0.0)
- {
- _nStartAngle2 += 2.0 * c_nPIE;
- }
-
- while (_nStartAngle2 >= 2.0 * c_nPIE)
- {
- _nStartAngle2 -= 2.0 * c_nPIE;
- }
- }
-
- // 调用数学函数计算交点 ---- 杨开锦 2010-09-14
- int _nRet = 0;
- if (pvectorIntersect_ == NULL)
- {
- _nRet = ncmath::Intersect_EllipseArcWithEllipseArc(
- _ptCenter1, _nURadius1, _nVRadius1, _nUAngle1, _nStartAngle1, _nSweptAngle1,
- _ptCenter2, _nURadius2, _nVRadius2, _nUAngle2, _nStartAngle2, _nSweptAngle2);
- }
- else
- {
- _nRet = ncmath::Intersect_EllipseArcWithEllipseArc(
- _ptCenter1, _nURadius1, _nVRadius1, _nUAngle1, _nStartAngle1, _nSweptAngle1,
- _ptCenter2, _nURadius2, _nVRadius2, _nUAngle2, _nStartAngle2, _nSweptAngle2,
- *pvectorIntersect_);
- }
-
- return _nRet;
- }
-
- int nce::Intersect_CadLineWithCadArc(IN const CCadLine* pCadLine_,
- IN const CCadArc* pCadArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine_);
- ASSERT(pCadArc_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadLine_->GetLength()));
- ASSERT(DOUBLE_GREAT_ZERO(pCadArc_->GetLength()));
-
- // 线段信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptLineStart = pCadLine_->GetStartPoint();
- DPOINT2 _ptLineEnd = pCadLine_->GetEndPoint();
-
- // 圆弧信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptArcCenter = pCadArc_->GetCenterPoint();
- double _nArcRadius = pCadArc_->GetRadius();
- double _nArcStartAngle = pCadArc_->GetStartAngle();
-
- double _nArcCentralAngle = pCadArc_->GetCentralAngle();
- double _nFactor = pCadArc_->IsNormalDir() ? 1 : -1;
- _nArcCentralAngle *= _nFactor;
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_LineWithArc(_ptLineStart, _ptLineEnd, _ptArcCenter,_nArcRadius,
- _nArcStartAngle, _nArcCentralAngle, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadLineWithCadBeeline(IN const CCadLine* pCadLine_,
- IN const CCadBeeline* pCadBeeline_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine_ != NULL);
- ASSERT(pCadBeeline_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_BeelineWithLine(pCadBeeline_->GetPoint(), pCadBeeline_->GetAngle(),
- pCadLine_->GetStartPoint(), pCadLine_->GetEndPoint(), *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadLineWithCadCircle(IN const CCadLine* pCadLine_,
- IN const CCadCircle* pCadCircle_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine_ != NULL);
- ASSERT(pCadCircle_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_LineWithCircle(pCadLine_->GetStartPoint(), pCadLine_->GetEndPoint(),
- pCadCircle_->GetCenterPoint(), pCadCircle_->GetRadius(), *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadLineWithCadEllipse(IN const CCadLine* pCadLine_,
- IN const CCadEllipse* pCadEllipse_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine_ && pCadEllipse_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
-
- // 线段信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptStart = pCadLine_->GetStartPoint();
- DPOINT2 _ptEnd = pCadLine_->GetEndPoint();
-
- // 椭圆信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptCenter = pCadEllipse_->GetCenterPoint();
- double _nLRadius = pCadEllipse_->GetLongRadius();
- double _nSRadius = pCadEllipse_->GetShortRadius();
- double _nUAngle = pCadEllipse_->GetAngle();
-
- return ncmath::Intersect_LineWithEllipse(_ptStart, _ptEnd,
- _ptCenter, _nLRadius, _nSRadius, _nUAngle,
- *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadLineWithCadEllipseArc(IN const CCadLine* pCadLine_,
- IN const CCadEllipseArc* pCadEllipseArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine_ && pCadEllipseArc_);
- ASSERT(!pvectorIntersect_ || pvectorIntersect_->empty());
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
-
- // 线段信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptStart = pCadLine_->GetStartPoint();
- DPOINT2 _ptEnd = pCadLine_->GetEndPoint();
-
- // 椭圆信息求取 --- 吴阳明 2010 09 19
- DPOINT2 _ptCenter = pCadEllipseArc_->GetCenterPoint();
- double _nLRadius = pCadEllipseArc_->GetLongRadius();
- double _nSRadius = pCadEllipseArc_->GetShortRadius();
- double _nUAngle = pCadEllipseArc_->GetAngle();
- double _nStartAngle = pCadEllipseArc_->GetStartAngle();
- double _nFactor = pCadEllipseArc_->IsNormalDir() ? 1 : -1;
- double _nCentralAngle = pCadEllipseArc_->GetCentralAngle() * _nFactor;
-
- return ncmath::Intersect_LineWithEllipseArc(_ptStart, _ptEnd,
- _ptCenter, _nLRadius, _nSRadius, _nUAngle, _nStartAngle, _nCentralAngle,
- *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadLineWithCadLine(IN const CCadLine* pCadLine1_,
- IN const CCadLine* pCadLine2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine1_);
- ASSERT(pCadLine2_);
- ASSERT(pvectorIntersect_== NULL || pvectorIntersect_->empty());
- ASSERT(DOUBLE_GREAT_ZERO(pCadLine1_->GetLength()));
- ASSERT(DOUBLE_GREAT_ZERO(pCadLine2_->GetLength()));
-
- // 线段信息提取 --- 吴阳明 2010 09 19
- DPOINT2 _ptLine1Start = pCadLine1_->GetStartPoint();
- DPOINT2 _ptLine2Start = pCadLine2_->GetStartPoint();
- DPOINT2 _ptLine1End = pCadLine1_->GetEndPoint();
- DPOINT2 _ptLine2End = pCadLine2_->GetEndPoint();
-
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- return ncmath::Intersect_LineWithLine(_ptLine1Start, _ptLine1End,
- _ptLine2Start, _ptLine2End, *pvectorIntersect_, _nNeed);
- }
-
- int nce::Intersect_CadLineWithCadMultiSegments(IN const CCadLine* pCadLine_,
- IN const CCadMultiSegments* pCadMultiSegments_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadLine_ != NULL);
- ASSERT(pCadMultiSegments_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- // 需要交点个数 0代表不需要,而-1代表尽可能多 --- 吴阳明 2010 09 19
- int _nNeed = (pvectorIntersect_ == NULL) ? 0 : -1;
- int _nSegCount = pCadMultiSegments_->GetSegmentCount();
- for (int _i = 0; _i < _nSegCount; ++_i)
- {
- std::vector<DPOINT2> _vecTmp;
-
- SEGMENT _segTmp = pCadMultiSegments_->GetSegment(_i);
- switch (_segTmp.nType)
- {
- case SEGMENT::ARC:
- {
- DPOINT2 _ptArcCenter(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArcRadius = 0.0;
- double _nArcStartAngle = 0.0, _nArcCentralAngle = 0.0;
-
- SEGMENT::SolveArc(_segTmp.ptStart, _segTmp.ptEnd, _segTmp.nBulge,
- &_ptArcCenter, &_nArcRadius, &_nArcStartAngle, &_nArcCentralAngle);
-
- _nResult += ncmath::Intersect_LineWithArc(pCadLine_->GetStartPoint(), pCadLine_->GetEndPoint(),
- _ptArcCenter, _nArcRadius, _nArcStartAngle, _nArcCentralAngle, _vecTmp, _nNeed);
- }
- break;
-
- case SEGMENT::LINE:
- _nResult += ncmath::Intersect_LineWithLine(pCadLine_->GetStartPoint(), pCadLine_->GetEndPoint(),
- _segTmp.ptStart, _segTmp.ptEnd, _vecTmp, _nNeed);
- break;
-
- case SEGMENT::BEZIER:
- default:
- // 这里可以选择抛出异常 --- wanghong 2010 09 12
- ASSERT(false);
- }
-
- if (pvectorIntersect_ != NULL && !_vecTmp.empty())
- std::copy(_vecTmp.begin(), _vecTmp.end(), std::back_inserter(*pvectorIntersect_));
- }
-
- return _nResult;
- }
-
- int nce::Intersect_CadObjectWithCadGroup(IN const CCadObject* pCadObject_,
- IN const CCadGroup* pCadGroup_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadObject_ && pCadGroup_);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
- ASSERT(pCadObject_->GetType() != cadgroup);
-
- int _nResult = 0;
- for (int _i = 0; _i != pCadGroup_->GetNumOfChild(); ++_i)
- {
- const CCadObject* _pCadObjectTemp = pCadGroup_->GetAt(_i);
- int _nNum = 0;
-
- if (pvectorIntersect_ != NULL)
- {
- std::vector<DPOINT2> _vecTmp;
- if (_nNum = GetIntersection(pCadObject_, _pCadObjectTemp, &_vecTmp))
- {
- _nResult += _nNum;
- copy(_vecTmp.begin(), _vecTmp.end(), back_inserter(*pvectorIntersect_));
- }
- }
- else
- {
- if (_nNum = GetIntersection(pCadObject_, _pCadObjectTemp, NULL))
- _nResult += _nNum;
- }
- }
-
- return _nResult;
- }
-
- int nce::Intersect_CadObjectWithCadText(IN const CCadObject* pCadObject_,
- IN const CCadText* pCadText_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadObject_ && pCadText_);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
- ASSERT(pCadObject_->GetType() != cadtext);
-
- const CCadGroup* _pCadGroup = pCadText_->GetTextGroup();
- return GetIntersection(pCadObject_, _pCadGroup, pvectorIntersect_);
- }
-
- // 群组与群组求交
- int nce::Intersect_CadGroupWithCadGroup(IN const CCadGroup* pCadGroup1_,
- IN const CCadGroup* pCadGroup2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadGroup1_ && pCadGroup1_->GetType() == cadgroup);
- ASSERT(pCadGroup2_ && pCadGroup2_->GetType() == cadgroup);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- for (int _i = 0; _i != pCadGroup1_->GetNumOfChild(); ++_i)
- {
- const CCadObject* _pCadObjectTemp = pCadGroup1_->GetAt(_i);
- int _nNum = 0;
-
- if (pvectorIntersect_ != NULL)
- {
- std::vector<DPOINT2> _vecTmp;
- if (_nNum = GetIntersection(_pCadObjectTemp, pCadGroup2_, &_vecTmp))
- {
- _nResult += _nNum;
- copy(_vecTmp.begin(), _vecTmp.end(), back_inserter(*pvectorIntersect_));
- }
- }
- else
- {
- if (_nNum = GetIntersection(_pCadObjectTemp, pCadGroup2_, NULL))
- _nResult += _nNum;
- }
- }
-
- return _nResult;
- }
-
- // 群组与文字求交
- int nce::Intersect_CadGroupWithCadText(IN const CCadGroup* pCadGroup_,
- IN const CCadText* pCadText_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadGroup_ && pCadGroup_->GetType() == cadgroup);
- ASSERT(pCadText_ && pCadText_->GetType() == cadtext);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- for (int _i = 0; _i != pCadGroup_->GetNumOfChild(); ++_i)
- {
- const CCadObject* _pCadObjectTemp = pCadGroup_->GetAt(_i);
- int _nNum = 0;
-
- if (pvectorIntersect_ != NULL)
- {
- std::vector<DPOINT2> _vecTmp;
- if (_nNum = GetIntersection(_pCadObjectTemp, pCadText_, &_vecTmp))
- {
- _nResult += _nNum;
- copy(_vecTmp.begin(), _vecTmp.end(), back_inserter(*pvectorIntersect_));
- }
- }
- else
- {
- if (_nNum = GetIntersection(_pCadObjectTemp, pCadText_, NULL))
- _nResult += _nNum;
- }
- }
-
- return _nResult;
- }
-
- // 群组与文字求交
- int nce::Intersect_CadTextWithCadText(IN const CCadText* pCadText1_,
- IN const CCadText* pCadText2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadText1_ && pCadText1_->GetType() == cadtext);
- ASSERT(pCadText2_ && pCadText2_->GetType() == cadtext);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- const CCadGroup* _pCadGroup1 = pCadText1_->GetTextGroup();
- const CCadGroup* _pCadGroup2 = pCadText2_->GetTextGroup();
-
- return Intersect_CadGroupWithCadGroup(_pCadGroup1, _pCadGroup2, pvectorIntersect_);
- }
-
- int nce::Intersect_CadMultiSegmentsWithCadEllipse(IN const CCadMultiSegments* pCadMultiSegments_,
- IN const CCadEllipse* pCadEllipse_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadMultiSegments_ != NULL);
- ASSERT(pCadEllipse_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- // 多段线中的各段与椭圆进行求交 --- 吴阳明 2010 09 19
- for (int _i = 0; _i != pCadMultiSegments_->GetSegmentCount(); ++_i)
- {
- SEGMENT _SegmentOut = pCadMultiSegments_->GetSegment(_i);
- std::vector<DPOINT2> _vectorTemp;
-
- switch(_SegmentOut.nType)
- {
- case SEGMENT::LINE:
- {
- CCadLine _CadLine(_SegmentOut.ptStart, _SegmentOut.ptEnd);
-
- if (pvectorIntersect_ != NULL)
- _nResult += Intersect_CadLineWithCadEllipse(&_CadLine, pCadEllipse_, &_vectorTemp);
- else
- _nResult += Intersect_CadLineWithCadEllipse(&_CadLine, pCadEllipse_, NULL);
- }
- break;
-
- case SEGMENT::ARC:
- {
- DPOINT2 _ptArcCenter(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArcRadius = 0.0;
- double _nArcStartAngle = 0.0, _nArcCentralAngle = 0.0;
-
- SEGMENT::SolveArc(_SegmentOut.ptStart, _SegmentOut.ptEnd, _SegmentOut.nBulge,
- &_ptArcCenter, &_nArcRadius, &_nArcStartAngle, &_nArcCentralAngle);
- CCadArc _CadArc(_ptArcCenter, _nArcRadius, _nArcStartAngle, fabs(_nArcCentralAngle), _SegmentOut.nBulge > 0);
-
- if (pvectorIntersect_ != NULL)
- _nResult += Intersect_CadArcWithCadEllipse(&_CadArc, pCadEllipse_, &_vectorTemp);
- else
- _nResult += Intersect_CadArcWithCadEllipse(&_CadArc, pCadEllipse_, NULL);
- }
- break;
-
- case SEGMENT::BEZIER:
- default:
- ASSERT(false);
- }
-
- // 需要求取交点,且求取交点不为空则进行存储 --- 吴阳明 2010 09 19
- if (pvectorIntersect_ != NULL && !_vectorTemp.empty())
- {
- copy(_vectorTemp.begin(), _vectorTemp.end(), back_inserter(*pvectorIntersect_));
- }
- }
- return _nResult;
- }
-
- int nce::Intersect_CadMultiSegmentsWithCadEllipseArc(IN const CCadMultiSegments* pCadMultiSegments_,
- IN const CCadEllipseArc* pCadEllipseArc_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadMultiSegments_ != NULL);
- ASSERT(pCadEllipseArc_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- // 多段线中的各段同椭圆弧进行求交 --- 吴阳明 2010 09 19
- for (int _i = 0; _i != pCadMultiSegments_->GetSegmentCount(); ++_i)
- {
- SEGMENT _SegmentOut = pCadMultiSegments_->GetSegment(_i);
- std::vector<DPOINT2> _vectorTemp;
-
- switch(_SegmentOut.nType)
- {
- case SEGMENT::LINE:
- {
- CCadLine _CadLine(_SegmentOut.ptStart, _SegmentOut.ptEnd);
-
- if (pvectorIntersect_ != NULL)
- _nResult += Intersect_CadLineWithCadEllipseArc(&_CadLine, pCadEllipseArc_, &_vectorTemp);
- else
- _nResult += Intersect_CadLineWithCadEllipseArc(&_CadLine, pCadEllipseArc_, NULL);
- }
- break;
-
- case SEGMENT::ARC:
- {
- DPOINT2 _ptArcCenter(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArcRadius = 0.0;
- double _nArcStartAngle = 0.0, _nArcCentralAngle = 0.0;
-
- SEGMENT::SolveArc(_SegmentOut.ptStart, _SegmentOut.ptEnd, _SegmentOut.nBulge,
- &_ptArcCenter, &_nArcRadius, &_nArcStartAngle, &_nArcCentralAngle);
- CCadArc _CadArc(_ptArcCenter, _nArcRadius, _nArcStartAngle, fabs(_nArcCentralAngle), _SegmentOut.nBulge > 0);
-
- if (pvectorIntersect_ != NULL)
- _nResult += Intersect_CadArcWithCadEllipseArc(&_CadArc, pCadEllipseArc_, &_vectorTemp);
- else
- _nResult += Intersect_CadArcWithCadEllipseArc(&_CadArc, pCadEllipseArc_, NULL);
- }
- break;
-
- case SEGMENT::BEZIER:
- default:
- ASSERT(false);
- }
-
- if (pvectorIntersect_ != NULL && !_vectorTemp.empty())
- {
- copy(_vectorTemp.begin(), _vectorTemp.end(), back_inserter(*pvectorIntersect_));
- }
- }
- return _nResult;
- }
-
- int nce::Intersect_CadMultiSegmentsWithCadMultiSegments(IN const CCadMultiSegments* pCadMultiSegments1_,
- IN const CCadMultiSegments* pCadMultiSegments2_,
- OUT std::vector<DPOINT2>* pvectorIntersect_)
- {
- ASSERT(pCadMultiSegments1_ != NULL);
- ASSERT(pCadMultiSegments2_ != NULL);
- ASSERT(pvectorIntersect_ == NULL || pvectorIntersect_->empty());
-
- int _nResult = 0;
- // 将多段线中的各段同多段线进行求交 --- 吴阳明 2010 09 19
- for (int _i = 0; _i != pCadMultiSegments1_->GetSegmentCount(); ++_i)
- {
- SEGMENT _SegmentOut = pCadMultiSegments1_->GetSegment(_i);
-
- CCadObject* _pCadObjectOut = NULL;
- if (!GetCadObjectFromSegment(_SegmentOut, &_pCadObjectOut))
- continue;
-
- std::vector<DPOINT2> _vectorTemp;
- int _j = pCadMultiSegments1_->GetID() == pCadMultiSegments2_->GetID() ? _i + 1 : 0;
- for (; _j < pCadMultiSegments2_->GetSegmentCount(); ++_j)
- {
- SEGMENT _SegmentIn = pCadMultiSegments2_->GetSegment(_j);
-
- CCadObject* _pCadObjectIn = NULL;
- if (!GetCadObjectFromSegment(_SegmentIn, &_pCadObjectIn))
- continue;
-
- std::vector<DPOINT2> _vectorTemp;
- if (pvectorIntersect_ != NULL)
- _nResult += GetIntersection(_pCadObjectOut, _pCadObjectIn, &_vectorTemp);
- else
- _nResult += GetIntersection(_pCadObjectOut, _pCadObjectIn, NULL);
-
- if (pvectorIntersect_ != NULL && !_vectorTemp.empty())
- {
- copy(_vectorTemp.begin(), _vectorTemp.end(), back_inserter(*pvectorIntersect_));
- }
- delete _pCadObjectIn;
- }
- delete _pCadObjectOut;
- }
- return _nResult;
- }
-
- bool nce::GetCadObjectFromSegment(IN const SEGMENT& Segment_, OUT CCadObject** ppCadObject_)
- {
- ASSERT(IsValidDouble(Segment_.ptStart.x));
- ASSERT(IsValidDouble(Segment_.ptStart.y));
- ASSERT(IsValidDouble(Segment_.ptEnd.x));
- ASSERT(IsValidDouble(Segment_.ptEnd.y));
- ASSERT(IsValidDouble(Segment_.nBulge));
- ASSERT(*ppCadObject_ == NULL);
-
- switch(Segment_.nType)
- {
- case SEGMENT::LINE:
- {
- CCadLine _CadLine(Segment_.ptStart, Segment_.ptEnd);
- *ppCadObject_ = _CadLine.Clone();
- }
- break;
-
- case SEGMENT::ARC:
- {
- DPOINT2 _ptArcCenter(ncmath::c_nINVALID_DOUBLE, ncmath::c_nINVALID_DOUBLE);
- double _nArcRadius = 0.0;
- double _nArcStartAngle = 0.0, _nArcCentralAngle = 0.0;
-
- SEGMENT::SolveArc(Segment_.ptStart, Segment_.ptEnd, Segment_.nBulge,
- &_ptArcCenter, &_nArcRadius, &_nArcStartAngle, &_nArcCentralAngle);
- CCadArc _CadArc(_ptArcCenter, _nArcRadius, _nArcStartAngle, fabs(_nArcCentralAngle), Segment_.nBulge > 0);
-
- *ppCadObject_ = _CadArc.Clone();
- }
- break;
-
- // 不支持的类型 --- 吴阳明 2010 09 19
- case SEGMENT::BEZIER:
- default:
- return false;
- }
-
- return true;
- }
|