diff --git a/PolyLine.cpp b/PolyLine.cpp index 94f8f2d..212080b 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -1301,10 +1301,10 @@ PolyLine::Trim( const Plane3d& plPlane, bool bInVsOut) //---------------------------------------------------------------------------- bool -ChangePolyLineStart( const Point3d& ptNewStart, PolyLine& Loop, double dTol) +PolyLine::ChangePolyLineStart( const Point3d& ptNewStart, double dTol) { // Rinomino la lista di punti della PolyLine. - PNTULIST& LoopList = Loop.GetUPointList() ; + PNTULIST& LoopList = GetUPointList() ; // Ciclo sui segmenti del loop per cercare il tratto del loop chiuso pi� vicino al punto. double dMinSqDist = DBL_MAX ; auto itMinDist = LoopList.end() ; @@ -1362,11 +1362,10 @@ ChangePolyLineStart( const Point3d& ptNewStart, PolyLine& Loop, double dTol) //---------------------------------------------------------------------------- // nSegNum 0-based bool -PointPositionOnPolyLine( const Point3d& ptPoint, const PolyLine& Loop, int& nSegNum, double& dParOnSeg, double dTol) +PolyLine::PointPositionOnPolyLine( const Point3d& ptPoint, int& nSegNum, double& dParOnSeg, double dTol) const { // Rinomino la lista di punti della PolyLine. - PolyLine& MyLoopRef = const_cast ( Loop) ; - const PNTULIST& LoopList = MyLoopRef.GetUPointList() ; + const PNTULIST& LoopList = GetUPointList() ; // Ciclo sui segmenti del loop per cercare il tratto del loop chiuso pi� vicino al punto. nSegNum = - 1 ; double dMinSqDist = DBL_MAX ; @@ -1406,14 +1405,13 @@ PointPositionOnPolyLine( const Point3d& ptPoint, const PolyLine& Loop, int& nSeg //---------------------------------------------------------------------------- bool -IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly) +PolyLine::IsPointInsidePolyLine( const Point3d& ptP) const { // Se la PolyLine non � chiusa, il punto non pu� essere interno. - if ( ! plPoly.IsClosed()) + if ( ! IsClosed()) return false ; // Lista dei punti - PolyLine& MyPolyRef = const_cast ( plPoly) ; - const PNTULIST& List = MyPolyRef.GetUPointList() ; + const PNTULIST& List = GetUPointList() ; // Ciclo sui segmenti della PolyLine per cercarne il tratto pi� vicino al punto. double dMinSqDist = DBL_MAX ; Point3d ptMinDist ; @@ -1458,7 +1456,7 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly) Vector3d vtTan = itMinDistEn->first - itMinDistSt->first ; vtTan.Normalize() ; Polygon3d AuxPolygon ; - AuxPolygon.FromPolyLine( plPoly) ; + AuxPolygon.FromPolyLine( *this) ; Vector3d vtPolyNorm = AuxPolygon.GetVersN() ; Vector3d vtPrevOut = vtPrevTan ^ vtPolyNorm ; Vector3d vtOut = vtTan ^ vtPolyNorm ; @@ -1488,7 +1486,7 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly) Vector3d vtNextTan = itNextEn->first - itMinDistEn->first ; vtNextTan.Normalize() ; Polygon3d AuxPolygon ; - AuxPolygon.FromPolyLine( plPoly) ; + AuxPolygon.FromPolyLine( *this) ; Vector3d vtPolyNorm = AuxPolygon.GetVersN() ; Vector3d vtOut = vtTan ^ vtPolyNorm ; Vector3d vtNextOut = vtNextTan ^ vtPolyNorm ; @@ -1511,7 +1509,7 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly) Vector3d vtTan = itMinDistEn->first - itMinDistSt->first ; vtTan.Normalize() ; Polygon3d AuxPolygon ; - AuxPolygon.FromPolyLine( plPoly) ; + AuxPolygon.FromPolyLine( *this) ; Vector3d vtPolyNorm = AuxPolygon.GetVersN() ; Vector3d vtOut = vtTan ^ vtPolyNorm ; vtP -= ( vtP * vtTan) * vtTan ; @@ -1523,13 +1521,13 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly) //---------------------------------------------------------------------------- bool -DistPointPolyLine( const Point3d& ptP, const PolyLine& plPoly, double& dPointPolyLineDist) +PolyLine::DistPointPolyLine( const Point3d& ptP, double& dPointPolyLineDist) const { - if ( plPoly.GetPointNbr() == 0) + if ( GetPointNbr() == 0) return false ; dPointPolyLineDist = DBL_MAX ; Point3d ptSt, ptEn ; - bool bContinue = plPoly.GetFirstPoint( ptSt) && plPoly.GetNextPoint( ptEn) ; + bool bContinue = GetFirstPoint( ptSt) && GetNextPoint( ptEn) ; while ( bContinue) { double dPoinLineDist ; DistPointLine PointLineDistCalc( ptP, ptSt, ptEn) ; @@ -1537,17 +1535,17 @@ DistPointPolyLine( const Point3d& ptP, const PolyLine& plPoly, double& dPointPol if ( dPoinLineDist < dPointPolyLineDist) dPointPolyLineDist = dPoinLineDist ; ptSt = ptEn ; - bContinue = plPoly.GetNextPoint( ptEn) ; + bContinue = GetNextPoint( ptEn) ; } return true ; } //---------------------------------------------------------------------------- bool -SplitPolyLineAtPoint( const Point3d& ptPoint, /*const*/ PolyLine& Loop, PolyLine& Loop1, PolyLine& Loop2, double dTol) +PolyLine::SplitPolyLineAtPoint( const Point3d& ptPoint, PolyLine& Loop1, PolyLine& Loop2, double dTol) const { // Rinomino la lista di punti della PolyLine. - /*const*/ PNTULIST& LoopList = Loop.GetUPointList() ; + const PNTULIST& LoopList = GetUPointList() ; // Ciclo sui segmenti del loop per cercare il tratto del loop chiuso pi� vicino al punto. double dMinSqDist = DBL_MAX ; auto itMinDistSt = LoopList.end() ; @@ -1572,6 +1570,7 @@ SplitPolyLineAtPoint( const Point3d& ptPoint, /*const*/ PolyLine& Loop, PolyLine return false ; // Se il punto di stop sta su un vertice non devo aggiungerlo e il // punto di stop sar� uno degli estremi del segmento su cui giace. + bool bPointOnEnd = false ; auto itStop = itMinDistSt ; auto itNext = itMinDistSt ; ++ itNext ; @@ -1580,7 +1579,8 @@ SplitPolyLineAtPoint( const Point3d& ptPoint, /*const*/ PolyLine& Loop, PolyLine else if ( AreSamePointApprox( ptPoint, itNext->first)) itStop = itNext ; else { - itStop = LoopList.emplace( itNext, ptPoint, 0.) ; + bPointOnEnd = true ; + itStop = itNext ; } // Creo i due loop PNTULIST& LoopList1 = Loop1.GetUPointList() ; @@ -1588,7 +1588,10 @@ SplitPolyLineAtPoint( const Point3d& ptPoint, /*const*/ PolyLine& Loop, PolyLine for ( auto it = LoopList.begin() ; it != itStop ; ++ it) { LoopList1.emplace_back( it->first, it->second) ; } - LoopList1.emplace_back( itStop->first, itStop->second) ; + LoopList1.emplace_back( ptPoint, 0) ; + if ( bPointOnEnd) { + LoopList2.emplace_back( ptPoint, 0) ; + } for ( auto it = itStop ; it != LoopList.end() ; ++ it) { LoopList2.emplace_back( it->first, it->second) ; } @@ -1597,10 +1600,10 @@ SplitPolyLineAtPoint( const Point3d& ptPoint, /*const*/ PolyLine& Loop, PolyLine //---------------------------------------------------------------------------- bool -AddPolyLineToPolyLine( PolyLine& Poly, PolyLine& PolyToAdd, double dTol) +PolyLine::AddPolyLineToPolyLine( PolyLine& PolyToAdd, double dTol) { // Se la PolyLine a cui devo aggiungere l'altra � chiusa, non posso aggiungere nulla. - if ( Poly.IsClosed()) + if ( IsClosed()) return false ; // Se la PolyLina che devo aggiungere � vuota, ho finito. PNTULIST& PolyToAddList = PolyToAdd.GetUPointList() ; @@ -1608,16 +1611,16 @@ AddPolyLineToPolyLine( PolyLine& Poly, PolyLine& PolyToAdd, double dTol) return true ; // Se Poly non � vuota e la sua fine non coincide con l'inizio di PolyToAdd, non � possibile aggiungere nulla. Point3d ptLast ; - Poly.GetLastPoint( ptLast) ; + GetLastPoint( ptLast) ; auto it = PolyToAddList.begin() ; - if ( Poly.GetPointNbr() != 0 && ! AreSamePointEpsilon( it->first, ptLast, dTol)) + if ( GetPointNbr() != 0 && ! AreSamePointEpsilon( it->first, ptLast, dTol)) return false ; /*if ( Poly.GetPointNbr() == 0) Poly.AddUPoint( 0., it->first) ; ++ it ;*/ // Aggiungo i punti. for ( ; it != PolyToAddList.end() ; ++ it) { - Poly.AddUPoint( 0., it->first) ; + AddUPoint( 0., it->first) ; } return true ; } \ No newline at end of file diff --git a/Triangulate.cpp b/Triangulate.cpp index bc1b166..6462781 100644 --- a/Triangulate.cpp +++ b/Triangulate.cpp @@ -277,7 +277,7 @@ Triangulate::MakeByDelaunay( const POLYLINEVECTOR& vPL, PNTVECTOR& vPt, INTVECTO pCrvHole->GetCentroid( pt) ; // se il centroide fosse esterno, cerco per tentativi un punto qualsiasi all'interno della curva double dPar = 0.5 ; - while ( ! IsPointInsidePolyLine( pt, vMyPL[i])) { + while ( ! vMyPL[i].IsPointInsidePolyLine( pt)) { double dParS, dParE ; pCrvHole->GetDomain( dParS, dParE) ; if ( dPar > dParE)