diff --git a/Angle.cpp b/Angle.cpp index 180a4a6..e0ebeaa 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -54,11 +54,11 @@ AngleInSpan( double dAngDeg, double dAngRefDeg, double dAngSpanDeg) // differenza dalla posizione a metà dell'intervallo angolare double dAngDiffDeg = DiffAngle( dAngDeg, dAngRefDeg + 0.5 * dAngSpanDeg) ; // se intervallo nullo, anche differenza deve essere nulla - if ( fabs( dAngSpanDeg) < EPS_ANG_ZERO) - return ( fabs( dAngDiffDeg) < EPS_ANG_SMALL) ; + if ( abs( dAngSpanDeg) < EPS_ANG_ZERO) + return ( abs( dAngDiffDeg) < EPS_ANG_SMALL) ; // deve essere non oltre metà intervallo dal suo centro else { - double dHalfAngSpanDeg = fabs( 0.5 * dAngSpanDeg) ; + double dHalfAngSpanDeg = abs( 0.5 * dAngSpanDeg) ; return ( dAngDiffDeg > - dHalfAngSpanDeg - EPS_ANG_SMALL && dAngDiffDeg < dHalfAngSpanDeg + EPS_ANG_SMALL) ; } diff --git a/ArcPntDirTgCurve.cpp b/ArcPntDirTgCurve.cpp index 4ac9db0..4a52a19 100644 --- a/ArcPntDirTgCurve.cpp +++ b/ArcPntDirTgCurve.cpp @@ -104,7 +104,7 @@ GetArcPntDirTgLine( const Point3d& ptP, const Vector3d& vtDir, const CurveLine& return nullptr ; } // se linea parallela all'asse X - else if ( fabs( ptP2.y - ptP1.y) < EPS_SMALL) { + else if ( abs( ptP2.y - ptP1.y) < EPS_SMALL) { Point3d ptTg( 0, ptP1.y, ptP1.z + ( 0 - ptP1.x) * ( ptP2.z - ptP1.z) / ( ptP2.x - ptP1.x)) ; PtrOwner pCrv( GetArc2PD( ORIG, ptTg, 0)) ; if ( ! IsNull( pCrv) && pCrv->ToGlob( frIntr)) { @@ -123,7 +123,7 @@ GetArcPntDirTgLine( const Point3d& ptP, const Vector3d& vtDir, const CurveLine& double dCoeff = ( 0 - ptP1.y) / ( ptP2.y - ptP1.y) ; Point3d ptInt( ptP1.x + dCoeff * ( ptP2.x - ptP1.x), 0, ptP1.z + dCoeff * ( ptP2.z - ptP1.z)) ; // punto distante da intersezione in XY come intersezione da origine - double dLenXY = fabs( ptInt.x) ; + double dLenXY = abs( ptInt.x) ; Vector3d vtDir = ptP2 - ptP1 ; vtDir.Normalize() ; double dLen = dLenXY * vtDir.Len() / vtDir.LenXY() ; @@ -214,7 +214,7 @@ GetArcPntDirTgArc( const Point3d& ptP, const Vector3d& vtDir, const CurveArc& cr Point3d ptEnd1 ; bOk1 = bOk1 && pCrv1->GetEndPoint( ptEnd1) ; // se l'arco di tangenza ha deltaN, devo considerarne quota parte - if ( bOk1 && fabs( crvArc.GetDeltaN()) > EPS_SMALL) { + if ( bOk1 && abs( crvArc.GetDeltaN()) > EPS_SMALL) { double dAngDeg ; if ( crvArc.CalcPointAngle( ptEnd1, dAngDeg)) { ptEnd1 += crvArc.GetNormVersor() * crvArc.GetDeltaN() * dAngDeg / crvArc.GetAngCenter() ; @@ -245,7 +245,7 @@ GetArcPntDirTgArc( const Point3d& ptP, const Vector3d& vtDir, const CurveArc& cr Point3d ptEnd2 ; bOk2 = bOk2 && pCrv2->GetEndPoint( ptEnd2) ; // se l'arco di tangenza ha deltaN, devo considerarne quota parte - if ( bOk2 && fabs( crvArc.GetDeltaN()) > EPS_SMALL) { + if ( bOk2 && abs( crvArc.GetDeltaN()) > EPS_SMALL) { double dAngDeg ; if ( crvArc.CalcPointAngle( ptEnd2, dAngDeg)) { ptEnd2 += crvArc.GetNormVersor() * crvArc.GetDeltaN() * dAngDeg / crvArc.GetAngCenter() ; diff --git a/ArcSpecial.cpp b/ArcSpecial.cpp index 7c147c9..6182eef 100644 --- a/ArcSpecial.cpp +++ b/ArcSpecial.cpp @@ -43,7 +43,7 @@ GetArc2PD( const Point3d& ptStart, const Point3d& ptEnd, double dDirStartDeg) vtDiff.z = 0 ; Vector3d vtDir = FromPolar( 1, dDirStartDeg) ; // verifico se i punti sono allineati con la direzione e nel giusto verso - if ( fabs( CrossXY( vtDiff, vtDir)) < EPS_SMALL && ScalarXY( vtDiff, vtDir) > EPS_SMALL) { + if ( abs( CrossXY( vtDiff, vtDir)) < EPS_SMALL && ScalarXY( vtDiff, vtDir) > EPS_SMALL) { // creo l'oggetto retta ICurveLine* pLine = CreateCurveLine() ; if ( pLine == nullptr) diff --git a/BiArcs.cpp b/BiArcs.cpp index f65e8bb..c3e1477 100644 --- a/BiArcs.cpp +++ b/BiArcs.cpp @@ -111,12 +111,12 @@ GetBiArc( const Point3d& ptP0, double dDir0Deg, const Point3d& ptP1, double dDir ( dSqDistIni < dSqRad && dSqDistFin > dSqRad)) { double dDiffIni = DistXY( ptIni, ptCen) - dRad ; double dDiffFin = DistXY( ptFin, ptCen) - dRad ; - Point3d ptMid = Media( ptIni, ptFin, fabs( dDiffIni) / ( fabs( dDiffIni) + fabs( dDiffFin))) ; + Point3d ptMid = Media( ptIni, ptFin, abs( dDiffIni) / ( abs( dDiffIni) + abs( dDiffFin))) ; int nPos ; double dTmp ; if ( pArc->CalcPointParamPosiz( ptMid, dTmp, nPos)) { if ( nPos != ICurve::PP_START && nPos != ICurve::PP_END && - fabs( dTmp - 0.5) < fabs( dU - 0.5)) + abs( dTmp - 0.5) < abs( dU - 0.5)) dU = dTmp ; } } @@ -159,7 +159,7 @@ CalcJCurve( const Point3d& ptP0, double dDir0Deg, const Point3d& ptP1, double dD double dAngDeg = DiffAngle( dDir1Deg, dDir0Deg) ; // se rotazione nulla, allora segmento di retta tra i due punti - if ( fabs( dAngDeg) < EPS_ANG_SMALL) { + if ( abs( dAngDeg) < EPS_ANG_SMALL) { PtrOwner pLine( CreateCurveLine()) ; if ( IsNull( pLine) || ! pLine->Set( ptP0, ptP1)) return nullptr ; @@ -194,9 +194,9 @@ CalcJCurve( const Point3d& ptP0, double dDir0Deg, const Point3d& ptP1, double dD // direzione iniziale secondo arco limite rispetto a direzione P0->P1 (dalla finale simmetrico e invert) double dDir1RelDeg = - DiffAngle( dDir1Deg, dDirDiffDeg) ; // nel caso di direzioni a 180deg si sceglie la più compatta - if ( fabs( fabs( dDir1RelDeg) - ANG_STRAIGHT) < EPS_SMALL) + if ( abs( abs( dDir1RelDeg) - ANG_STRAIGHT) < EPS_SMALL) dDir1RelDeg = ( dDir0RelDeg > 0 ? ANG_STRAIGHT : - ANG_STRAIGHT) ; - else if ( fabs( fabs( dDir0RelDeg) - ANG_STRAIGHT) < EPS_SMALL) + else if ( abs( abs( dDir0RelDeg) - ANG_STRAIGHT) < EPS_SMALL) dDir0RelDeg = ( dDir1RelDeg > 0 ? ANG_STRAIGHT : - ANG_STRAIGHT) ; // intervallo angolare ammissibile a partire da direzione iniziale primo arco ammissibile ( == Dir0) double dDeltaAngDeg = - dDir0RelDeg + dDir1RelDeg ; diff --git a/CAvToolTriangle.cpp b/CAvToolTriangle.cpp index a34d735..aeef682 100644 --- a/CAvToolTriangle.cpp +++ b/CAvToolTriangle.cpp @@ -1712,8 +1712,8 @@ double TorusPointLeakDistGenMot( const Point3d& ptTorusCen, const Vector3d& vtTorusAx, double dMaxRad, double dMinRad, const Point3d& ptP, const Vector3d& vtMove) { - std::vector vbType ; - std::vector vdPar ; + BOOLVECTOR vbType ; + DBLVECTOR vdPar ; // Intersezione fra semi-retta e corona torica int nIntType = LinCompTorusExtInt( ptP, - vtMove, 1, Ray, ptTorusCen, vtTorusAx, dMinRad, dMaxRad, vbType, vdPar) ; if ( nIntType == T_ERROR) @@ -2043,8 +2043,8 @@ double ConcaveTorusPointLeakDistGenMot( const Point3d& ptTorusCen, const Vector3d& vtTorusAx, double dMaxRad, double dMinRad, const Point3d& ptP, const Vector3d& vtMove) { - std::vector vbType ; - std::vector vdPar ; + BOOLVECTOR vbType ; + DBLVECTOR vdPar ; // Intersezione fra semi-retta e corona torica int nIntType = LinCompTorusInnUpInt( ptP, - vtMove, 1, Ray, ptTorusCen, vtTorusAx, dMinRad, dMaxRad, vbType, vdPar) ; if ( nIntType == T_ERROR) @@ -2414,21 +2414,19 @@ double DiskSegmentLeakDistGenMot( double dDiskRad, const Point3d& ptSeg, const Vector3d& vtSeg, double dSegLen, const Vector3d& vtMove) { - // Quadrato del raggio - double dSqRad = ( dDiskRad - EPS_SMALL) * ( dDiskRad - EPS_SMALL) ; // Il caso in cui il segmento è parallelo al versore del moto è gestito dalla // routine per il calcolo della distanza di allontanamento dei punti. if ( AreSameOrOppositeVectorApprox( vtMove, vtSeg)) return 0. ; - - vector vdCoef(3) ; - vector vdRoots ; // Siamo nel caso in cui il movimento è generico rispetto all'asse del disco, quindi // sicuramente vtMove.z > 0, quindi esiste il rapporto dObCoef double dObCoef = vtMove.x / vtMove.z ; double dSqCoef = dObCoef * dObCoef ; + // Quadrato del raggio + double dSqRad = ( dDiskRad - EPS_SMALL) * ( dDiskRad - EPS_SMALL) ; // Setto i coeficienti dell'equazione + DBLVECTOR vdCoef(3) ; vdCoef[0] = dSqCoef * ptSeg.z * ptSeg.z + ptSeg.x * ptSeg.x + ptSeg.y * ptSeg.y - 2 * dObCoef * ptSeg.z * ptSeg.x - dSqRad ; vdCoef[1] = 2 * ( dSqCoef * vtSeg.z * ptSeg.z + vtSeg.x * ptSeg.x + vtSeg.y * ptSeg.y @@ -2438,9 +2436,10 @@ DiskSegmentLeakDistGenMot( double dDiskRad, const Point3d& ptSeg, const Vector3d // Numero di soluzioni: l'equazione ammette o due soluzioni (eventualmente // coincidenti) oppure nessuna o infinite se la la retta // appartiene alla superficie - double dLenCoef = sqrt( 1 + dSqCoef) ; + DBLVECTOR vdRoots ; int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; + double dLenCoef = sqrt( 1 + dSqCoef) ; double dLeakDist = 0. ; for ( int n = 0 ; n < nRoot ; ++ n) { if ( vdRoots[n] > 0 && vdRoots[n] < dSegLen) { diff --git a/CircleCenTgCurve.cpp b/CircleCenTgCurve.cpp index cd046ce..4b09c91 100644 --- a/CircleCenTgCurve.cpp +++ b/CircleCenTgCurve.cpp @@ -133,7 +133,7 @@ GetCircleCenTgArc( const Point3d& ptCen, const Vector3d& vtN, const CurveArc& cr } // se l'arco di tangenza ha deltaN, devo applicarlo in proporzione a questi punti - if ( fabs( crvArc.GetDeltaN()) > EPS_SMALL) { + if ( abs( crvArc.GetDeltaN()) > EPS_SMALL) { for ( size_t i = 0 ; i < vCenPtg.size() ; ++ i) { double dAngDeg ; if ( crvArc.CalcPointAngle( vCenPtg[i].second, dAngDeg)) diff --git a/CreateCurveAux.cpp b/CreateCurveAux.cpp index c9b7af2..7ad2323 100644 --- a/CreateCurveAux.cpp +++ b/CreateCurveAux.cpp @@ -106,7 +106,7 @@ CalcCircleCenTgCircle( const Point3d& ptC, const Point3d& ptCen, double dRad, BI } // se questa distanza è uguale al raggio, non ci sono soluzioni - if ( fabs( dDist - dRad) < EPS_SMALL) + if ( abs( dDist - dRad) < EPS_SMALL) return 0 ; // altrimenti ci sono due soluzioni else { diff --git a/CurveArc.cpp b/CurveArc.cpp index 92bc855..f242818 100644 --- a/CurveArc.cpp +++ b/CurveArc.cpp @@ -205,10 +205,10 @@ CurveArc::Set3P( const Point3d& ptStart, const Point3d& ptOther, const Point3d& return false ; // deduzione dell'angolo al centro // se uno dei due angoli è nullo, errore - if ( fabs( dAng1Deg) < EPS_ANG_SMALL || fabs( dAng2Deg) < EPS_ANG_SMALL) + if ( abs( dAng1Deg) < EPS_ANG_SMALL || abs( dAng2Deg) < EPS_ANG_SMALL) return false ; // se i due angoli hanno lo stesso segno e Ang1 è minore di Ang2 in modulo - else if ( dAng1Deg * dAng2Deg > 0 && fabs( dAng1Deg) < fabs( dAng2Deg)) + else if ( dAng1Deg * dAng2Deg > 0 && abs( dAng1Deg) < abs( dAng2Deg)) m_dAngCenDeg = dAng2Deg ; // altrimenti hanno segno opposto oppure Ang1 è maggiore di Ang2 in modulo else @@ -244,11 +244,11 @@ CurveArc::Set2PNB( const Point3d& ptIni, const Point3d& ptFin, const Vector3d& v // deltaN eventuale ( è componente parallela a VtN) m_dDeltaN = vtDiff * m_VtN ; vtDiff -= m_dDeltaN * m_VtN ; - if ( fabs( m_dDeltaN) < EPS_SMALL) + if ( abs( m_dDeltaN) < EPS_SMALL) m_dDeltaN = 0 ; // verifico sia un arco (uso la lunghezza della saetta) double dDist = vtDiff.Len() ; - if ( fabs( dBulge * 0.5 * dDist) < EPS_ZERO) + if ( abs( dBulge * 0.5 * dDist) < EPS_ZERO) return false ; // calcolo del centro Vector3d vtOrtho = vtDiff ; @@ -257,7 +257,7 @@ CurveArc::Set2PNB( const Point3d& ptIni, const Point3d& ptFin, const Vector3d& v vtOrtho *= ( 1 - dBulge * dBulge) / ( 4 * dBulge) ; m_PtCen = ptIni + 0.5 * vtDiff + vtOrtho ; // calcolo il raggio - m_dRad = fabs( dDist * ( 1 + dBulge * dBulge) / ( 4 * dBulge)) ; + m_dRad = abs( dDist * ( 1 + dBulge * dBulge) / ( 4 * dBulge)) ; // calcolo il versore iniziale m_VtS = ptIni - m_PtCen ; m_VtS.Normalize() ; @@ -345,7 +345,7 @@ CurveArc::Set2PVN( const Point3d& ptStart, const Point3d& ptEnd, const Vector3d& // porto la direzione in questo riferimento e verifico che definisca un angolo nel piano Vector3d vtSloc = vtDirS ; vtSloc.ToLoc( frOcs) ; - if ( fabs( vtSloc.x) < EPS_SMALL && fabs( vtSloc.y) < EPS_SMALL) + if ( abs( vtSloc.x) < EPS_SMALL && abs( vtSloc.y) < EPS_SMALL) return false ; double dDirStartDeg ; vtSloc.ToSpherical( nullptr, nullptr, &dDirStartDeg) ; @@ -397,7 +397,7 @@ CurveArc::Set2PRS( const Point3d& ptStart, const Point3d& ptEnd, double dRad, bo if ( ! m_VtS.GetRotation( ( ptEnd - m_PtCen), m_VtN, m_dAngCenDeg, bDet) || ! bDet) return false ; // quando è 180deg il segno è determinato solo dal senso - if ( fabs( m_dAngCenDeg - ANG_STRAIGHT) < 10 * EPS_ANG_SMALL && + if ( abs( m_dAngCenDeg - ANG_STRAIGHT) < 10 * EPS_ANG_SMALL && ( ( bCCW && m_dAngCenDeg < 0) || ( ! bCCW && m_dAngCenDeg > 0))) m_dAngCenDeg = - m_dAngCenDeg ; @@ -711,7 +711,7 @@ CurveArc::GetLocalBBox( BBox3d& b3Loc, int nFlag) const while ( aAppr.GetPoint( dU, ptPos)) b3Loc.Add( ptPos) ; // se c'è estrusione, devo tenerne conto - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Point3d ptMinExtr = b3Loc.GetMin() + m_VtExtr * m_dThick ; Point3d ptMaxExtr = b3Loc.GetMax() + m_VtExtr * m_dThick ; b3Loc.Add( ptMinExtr) ; @@ -745,7 +745,7 @@ CurveArc::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const b3Ref.Add( ptPos) ; } // se c'è estrusione, devo tenerne conto - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Vector3d vtFrExtr = m_VtExtr ; vtFrExtr.ToGlob( frRef) ; Point3d ptMinExtr = b3Ref.GetMin() + vtFrExtr * m_dThick ; @@ -763,7 +763,7 @@ CurveArc::Validate( void) { if ( m_nStatus == TO_VERIFY) { // limito l'angolo al centro a un giro se è piatto ( non è elica) - if ( fabs( m_dDeltaN) < EPS_SMALL) { + if ( abs( m_dDeltaN) < EPS_SMALL) { if ( m_dAngCenDeg > ANG_FULL) m_dAngCenDeg = ANG_FULL ; else if ( m_dAngCenDeg < - ANG_FULL) @@ -773,7 +773,7 @@ CurveArc::Validate( void) m_nStatus = ( ( m_VtN.IsNormalized() && m_VtS.IsNormalized() && AreOrthoApprox( m_VtN, m_VtS) && m_dRad > EPS_SMALL && m_dRad < MAX_ARC_RAD && - fabs( m_dAngCenDeg) > EPS_ANG_ZERO) ? OK : ERR) ; + abs( m_dAngCenDeg) > EPS_ANG_ZERO) ? OK : ERR) ; } return ( m_nStatus == OK) ; @@ -828,7 +828,7 @@ CurveArc::GetEndPoint( Point3d& ptEnd) const double dAng = m_dAngCenDeg * DEGTORAD ; Vector3d vtDir = cos( dAng) * m_VtS + sin( dAng) * ( m_VtN ^ m_VtS) ; ptEnd = m_PtCen + m_dRad * vtDir ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) ptEnd += m_dDeltaN * m_VtN ; return true ; @@ -846,7 +846,7 @@ CurveArc::GetMidPoint( Point3d& ptMid) const double dAng = 0.5 * m_dAngCenDeg * DEGTORAD ; Vector3d vtDir = cos( dAng) * m_VtS + sin( dAng) * ( m_VtN ^ m_VtS) ; ptMid = m_PtCen + m_dRad * vtDir ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) ptMid += ( 0.5 * m_dDeltaN) * m_VtN ; return true ; @@ -906,7 +906,7 @@ CurveArc::GetDir( double dU, Vector3d& vtDir) const Vector3d vtRad = cos( dAng) * m_VtS + sin( dAng) * ( m_VtN ^ m_VtS) ; // calcolo della tangente nel punto finale vtDir = ( m_dRad * m_dAngCenDeg * DEGTORAD) * ( m_VtN ^ vtRad) ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) vtDir += m_dDeltaN * m_VtN ; // normalizzo return vtDir.Normalize( EPS_ZERO) ; @@ -932,13 +932,13 @@ CurveArc::GetPointD1D2( double dU, Side nS, Point3d& ptPos, Vector3d* pvtDer1, V // calcolo del punto ptPos = m_PtCen + m_dRad * vtDir ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) ptPos += ( dU * m_dDeltaN) * m_VtN ; // calcolo della derivata prima if ( pvtDer1 != nullptr) { *pvtDer1 = ( m_dRad * m_dAngCenDeg * DEGTORAD) * ( m_VtN ^ vtDir) ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) *pvtDer1 += m_dDeltaN * m_VtN ; } @@ -958,9 +958,9 @@ CurveArc::GetLength( double& dLen) const return false ; // lunghezza dell'arco piano - dLen = m_dRad * fabs( m_dAngCenDeg) * DEGTORAD ; + dLen = m_dRad * abs( m_dAngCenDeg) * DEGTORAD ; // aggiunta eventuale parte ortogonale - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) dLen = sqrt( dLen * dLen + m_dDeltaN * m_dDeltaN) ; return ( dLen > EPS_SMALL) ; @@ -1137,7 +1137,7 @@ CurveArc::ApproxWithArcs( double dLinTol, double dAngTolDeg, PolyArc& PA) const // calcolo il numero di archi con bulge da usare ( ognuno deve avere un angolo al centro <= 240deg) const double MAX_ANG_ARC_BULGE = 240 ; - int nArcs = int( ceil( fabs( m_dAngCenDeg) / MAX_ANG_ARC_BULGE)) ; + int nArcs = int( ceil( abs( m_dAngCenDeg) / MAX_ANG_ARC_BULGE)) ; nArcs = max( nArcs, 1) ; double dBulge = tan( m_dAngCenDeg / ( 4 * nArcs) * DEGTORAD) ; // se direzioni opposte, senso di rotazione contrario @@ -1201,7 +1201,7 @@ CurveArc::Invert( void) return false ; // il centro va spostato di DeltaN - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) m_PtCen += m_dDeltaN * m_VtN ; // il versore normale rimane inalterato // il versore iniziale diventa quello finale @@ -1276,7 +1276,7 @@ CurveArc::MyExtendedOffset( double dDist, bool bAll, int nType) bool bCCW = ( ( m_dAngCenDeg > 0 && m_VtN * vtNref > 0) || ( m_dAngCenDeg < 0 && m_VtN * vtNref < 0)) ; double dNewRad = m_dRad + ( bCCW ? + dDist : - dDist) ; - if ( fabs( dNewRad) < EPS_SMALL) { + if ( abs( dNewRad) < EPS_SMALL) { if ( bAll) dNewRad = 0.1 * EPS_SMALL ; else @@ -1355,7 +1355,7 @@ CurveArc::ModifyEnd( const Point3d& ptNewEnd) m_VtS.ToGlob( frIntr) ; m_dRad = arcAux.m_dRad ; // se elica, devo avere un numero di giri vicino ai precedenti - if ( fabs( dOldAngCenDeg) >= ANG_FULL - EPS_ANG_ZERO) + if ( abs( dOldAngCenDeg) >= ANG_FULL - EPS_ANG_ZERO) m_dAngCenDeg = AngleNearAngle( arcAux.m_dAngCenDeg, dOldAngCenDeg) ; else m_dAngCenDeg = arcAux.m_dAngCenDeg ; @@ -1444,7 +1444,7 @@ CurveArc::TrimStartAtLen( double dLenTrim) dAngRot = m_dAngCenDeg * dLenTrim / dLen ; m_VtS.Rotate( m_VtN, dAngRot) ; m_dAngCenDeg -= dAngRot ; - if ( fabs( m_dDeltaN) > EPS_SMALL) { + if ( abs( m_dDeltaN) > EPS_SMALL) { dMoveN = m_dDeltaN * dLenTrim / dLen ; m_PtCen.Translate( m_VtN * dMoveN) ; m_dDeltaN -= dMoveN ; @@ -1474,7 +1474,7 @@ CurveArc::TrimEndAtLen( double dLenTrim) // eseguo il trim if ( ( dLen - dLenTrim) > EPS_ZERO) { m_dAngCenDeg *= dLenTrim / dLen ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) m_dDeltaN *= dLenTrim / dLen ; } @@ -1518,7 +1518,7 @@ CurveArc::ExtendEndByLen( double dLenExt) m_dAngCenDeg *= dCoeff ; if ( ! IsFlat()) m_dDeltaN *= dCoeff ; - else if ( fabs( m_dAngCenDeg) > ANG_FULL) + else if ( abs( m_dAngCenDeg) > ANG_FULL) m_dAngCenDeg = _copysign( ANG_FULL, m_dAngCenDeg) ; // con i controlli sopra fatti rimane validata, ma la grafica va ricalcolata @@ -1578,11 +1578,11 @@ CurveArc::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dC return false ; // ammessa solo scalatura uniforme - if ( fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL) + if ( abs( dCoeffX - dCoeffY) > EPS_SMALL || abs( dCoeffX - dCoeffZ) > EPS_SMALL) return false ; // verifico non sia nulla - if ( fabs( dCoeffX) < EPS_ZERO || m_dRad * fabs( dCoeffX) <= EPS_SMALL) + if ( abs( dCoeffX) < EPS_ZERO || m_dRad * abs( dCoeffX) <= EPS_SMALL) return false ; // imposto ricalcolo della grafica @@ -1590,7 +1590,7 @@ CurveArc::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dC // scalo il centro e le dimensioni lineari m_PtCen.Scale( frRef, dCoeffX, dCoeffX, dCoeffX) ; - m_dRad *= fabs( dCoeffX) ; + m_dRad *= abs( dCoeffX) ; m_dDeltaN *= dCoeffX ; if ( dCoeffX < 0) m_VtS = - m_VtS ; @@ -1645,7 +1645,7 @@ CurveArc::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vt return false ; // possibile solo se l'arco è piatto e il piano di scorrimento coincide con quello dell'arco - if ( ! ( fabs( m_dDeltaN) < EPS_SMALL) || + if ( ! ( abs( m_dDeltaN) < EPS_SMALL) || ! AreSameOrOppositeVectorExact( m_VtN, vtNorm)) return false ; @@ -1794,12 +1794,12 @@ CurveArc::MyCalcPointParamPosiz( const Point3d& ptP, double& dU, int& nPos, doub dU = dAngDeg / m_dAngCenDeg ; // verifica posizione punto su arco nPos = PP_NULL ; // fuori - if ( fabs( DiffAngle( dAngDeg, 0) * DEGTORAD * m_dRad) < dLinTol) { + if ( abs( DiffAngle( dAngDeg, 0) * DEGTORAD * m_dRad) < dLinTol) { nPos = ( IsACircle() ? PP_MID : PP_START) ; // se cerchio è interno, altrimenti vicino a inizio dU = AngleNearAngle( dAngDeg, 0) / m_dAngCenDeg ; dU = max( dU, 0.) ; } - else if ( fabs( DiffAngle( dAngDeg, m_dAngCenDeg) * DEGTORAD * m_dRad) < dLinTol) { + else if ( abs( DiffAngle( dAngDeg, m_dAngCenDeg) * DEGTORAD * m_dRad) < dLinTol) { nPos = ( IsACircle() ? PP_MID : PP_END) ; // se cerchio è interno, altrimenti vicino a fine dU = AngleNearAngle( dAngDeg, m_dAngCenDeg) / m_dAngCenDeg ; dU = min( dU, 1.) ; @@ -1895,7 +1895,7 @@ CurveArc::ToExplementary( void) if ( m_nStatus != OK) return false ; // l'angolo al centro deve essere minore di un giro - if ( fabs( m_dAngCenDeg) > ( ANG_FULL - EPS_ANG_SMALL)) + if ( abs( m_dAngCenDeg) > ( ANG_FULL - EPS_ANG_SMALL)) return false ; // basta prendere l'angolo al centro che completa il giro @@ -1915,7 +1915,7 @@ CurveArc::Flip( void) if ( m_nStatus != OK) return false ; // l'angolo al centro deve essere minore di un giro - if ( fabs( m_dAngCenDeg) > ( ANG_FULL - EPS_ANG_SMALL)) + if ( abs( m_dAngCenDeg) > ( ANG_FULL - EPS_ANG_SMALL)) return false ; // si calcola l'arco simmetrico rispetto alla linea che unisce gli estremi @@ -1923,7 +1923,7 @@ CurveArc::Flip( void) if ( ! GetStartPoint( ptStart) || ! GetEndPoint( ptEnd)) return false ; // il punto finale mi interessa nel piano dell'arco - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) ptEnd -= m_dDeltaN * m_VtN ; m_PtCen = ptStart + ( ptEnd - m_PtCen) ; m_VtS = ptStart - m_PtCen ; @@ -1976,7 +1976,7 @@ ArcApproxer::ArcApproxer( double dLinTol, double dAngTolDeg, bool bInside, const dAngStepDeg = min( dAngStepDeg, dAngTolDeg) ; // dall'angolo al centro ricavo il numero di passi - nStep = (int) ( fabs( arArc.GetAngCenter()) / dAngStepDeg + 0.999) ; + nStep = (int) ( abs( arArc.GetAngCenter()) / dAngStepDeg + 0.999) ; nStep = max( nStep, 1) ; // sistemo lo step (per il numero intero di passi) @@ -2025,7 +2025,7 @@ ArcApproxer::GetPoint( double& dU, Point3d& ptP) if ( ! m_bInside && m_nCurrPnt == m_nTotPnt - 1) { dU = 1 ; ptP = m_PtCen + m_vtA1 * m_dRad ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) ptP += ( dU * m_dDeltaN) * m_VtN ; return true ; } @@ -2046,7 +2046,7 @@ ArcApproxer::GetPoint( double& dU, Point3d& ptP) ptP = m_PtCen + m_vtA1 * m_dRad ; else ptP = m_PtCen + ( vtA1p + m_vtA1) * ( m_dRad / ( 1 + m_dCosA)) ; - if ( fabs( m_dDeltaN) > EPS_SMALL) + if ( abs( m_dDeltaN) > EPS_SMALL) ptP += ( dU * m_dDeltaN) * m_VtN ; return true ; diff --git a/CurveArc.h b/CurveArc.h index e9c961d..717c6fc 100644 --- a/CurveArc.h +++ b/CurveArc.h @@ -141,7 +141,7 @@ class CurveArc : public ICurveArc, public IGeoObjRW bool SetC2P( const Point3d& ptCen, const Point3d& ptStart, const Point3d& ptNearEnd) override ; bool SetC2PN( const Point3d& ptCen, const Point3d& ptStart, const Point3d& ptNearEnd, const Vector3d& vtN) override ; bool IsFlat( double dToler = EPS_SMALL) const override - { return ( fabs( m_dDeltaN) < dToler) ; } + { return ( abs( m_dDeltaN) < dToler) ; } bool IsACircle( void) const override { return ( IsFlat() && IsClosed()) ; } bool IsInPlaneXY( void) const override diff --git a/CurveAux.cpp b/CurveAux.cpp index 338235b..cfb31c3 100644 --- a/CurveAux.cpp +++ b/CurveAux.cpp @@ -65,7 +65,7 @@ IsStartParam( const ICurve& crvC, double dPar) if ( ! crvC.GetDomain( dStart, dEnd)) return false ; // se il parametro non è nell'intorno dell'inizio - if ( fabs( dPar - dStart) > EPS_PARAM) + if ( abs( dPar - dStart) > EPS_PARAM) return false ; return true ; } @@ -79,7 +79,7 @@ IsEndParam( const ICurve& crvC, double dPar) if ( ! crvC.GetDomain( dStart, dEnd)) return false ; // se il parametro non è nell'intorno della fine - if ( fabs( dPar - dEnd) > EPS_PARAM) + if ( abs( dPar - dEnd) > EPS_PARAM) return false ; return true ; } @@ -367,7 +367,7 @@ CurveDump( const ICurve& crvC, string& sOut, bool bMM, const char* szNewLine) if ( CurveGetAreaXY( crvC, dAreaXY)) { bool bCCW = ( dAreaXY > 0) ; sOut += string( "Closed") + ( bCCW ? " CCW" : " CW") + " AreaXY=" + - ToString( GetAreaInUiUnits( fabs( dAreaXY), bMM),1) + szNewLine ; + ToString( GetAreaInUiUnits( abs( dAreaXY), bMM),1) + szNewLine ; } return true ; @@ -411,7 +411,7 @@ ArcToBezierCurve( const ICurve* pCrv) return nullptr ; // se angolo al centro sotto il limite, basta una curva - if ( fabs( pArc->GetAngCenter()) < BEZARC_ANG_CEN_MAX + EPS_ANG_SMALL) { + if ( abs( pArc->GetAngCenter()) < BEZARC_ANG_CEN_MAX + EPS_ANG_SMALL) { // creo la curva di Bezier equivalente all'arco PtrOwner pCrvBez( CreateBasicCurveBezier()) ; if ( IsNull( pCrvBez) || ! pCrvBez->FromArc( *pArc)) @@ -426,7 +426,7 @@ ArcToBezierCurve( const ICurve* pCrv) if ( IsNull( pCrvCompo)) return nullptr ; // inserisco nella CC le curve di Bezier equivalenti alle parti dell'arco - int nParts = (int) ceil( fabs( pArc->GetAngCenter()) / ( BEZARC_ANG_CEN_MAX + EPS_ANG_SMALL)) ; + int nParts = (int) ceil( abs( pArc->GetAngCenter()) / ( BEZARC_ANG_CEN_MAX + EPS_ANG_SMALL)) ; nParts = max( nParts, 2) ; for ( int i = 0 ; i < nParts ; ++ i) { // copio l'arco originale @@ -606,7 +606,7 @@ NurbsToBezierCurve( const CNurbsData& cnData) // ciclo while ( b < nU - 1) { int i = b ; - while ( b < nU - 1 && fabs( cnData.vU[b+1] - cnData.vU[b]) < EPS_ZERO) + while ( b < nU - 1 && abs( cnData.vU[b+1] - cnData.vU[b]) < EPS_ZERO) ++ b ; int mult = min( b - i + 1, cnData.nDeg) ; if ( mult < cnData.nDeg) { diff --git a/CurveBezier.cpp b/CurveBezier.cpp index 3e0f717..5721537 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -190,13 +190,13 @@ CurveBezier::FromArc( const ICurveArc& crArc) if ( ! crArc.IsValid()) return false ; dAngCen = crArc.GetAngCenter() ; - if ( fabs( dAngCen) > MAX_ANG_CEN_DEG) + if ( abs( dAngCen) > MAX_ANG_CEN_DEG) return false ; dCosAhalf = cos( 0.5 * dAngCen * DEGTORAD) ; // se arco piatto, basta quadrica razionale // algoritmo di Sederberg (BYU) CAGD cap. 2 pag. 33 - if ( fabs( crArc.GetDeltaN()) < EPS_ZERO) { + if ( abs( crArc.GetDeltaN()) < EPS_ZERO) { // peso del punto di controllo intermedio dW = dCosAhalf ; // calcolo dei punti di controllo @@ -505,7 +505,7 @@ CurveBezier::GetLocalBBox( BBox3d& b3Loc, int nFlag) const } } // se c'è estrusione, devo tenerne conto - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Point3d ptMinExtr = b3Loc.GetMin() + m_VtExtr * m_dThick ; Point3d ptMaxExtr = b3Loc.GetMax() + m_VtExtr * m_dThick ; b3Loc.Add( ptMinExtr) ; @@ -549,7 +549,7 @@ CurveBezier::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const } } // se c'è estrusione, devo tenerne conto - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Vector3d vtFrExtr = m_VtExtr ; vtFrExtr.ToGlob( frRef) ; Point3d ptMinExtr = b3Ref.GetMin() + vtFrExtr * m_dThick ; @@ -707,7 +707,7 @@ CurveBezier::GetPointD1D2( double dU, Side nS, Point3d& ptPos, Vector3d* pvtDer1 // verifico se punto singolare double dSingU ; - if ( GetSingularParam( dSingU) > 0 && fabs( dU - dSingU) < EPS_PARAM) { + if ( GetSingularParam( dSingU) > 0 && abs( dU - dSingU) < EPS_PARAM) { if ( nS == ICurve::FROM_MINUS) dU -= 100 * EPS_PARAM ; else @@ -1407,7 +1407,7 @@ CurveBezier::FlatOrSplit( int nLev, const CurveBezier& crvBez, double dParStart, vtDirI.GetAngle( vtDirF, dAngDeg) ; // se deviazione angolare entro tolleranza oppure lunghezza poligono controllo entro tolleranza double dPolLen ; - if ( fabs( dAngDeg) <= dAngTolDeg || + if ( abs( dAngDeg) <= dAngTolDeg || ( crvBez.GetControlPolygonLength( dPolLen) && dPolLen <= dLinTol)) { // considero la curva piatta (inserisco il punto se abbastanza lontano dal precedente) ed esco Point3d ptLast ; @@ -1951,7 +1951,7 @@ CurveBezier::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double return false ; // verifico non sia nulla - if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO) + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; // verifico che la scalatura dei punti non li porti tutti a coincidere diff --git a/CurveComposite.cpp b/CurveComposite.cpp index b2f55a9..050bc50 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -363,7 +363,7 @@ CurveComposite::FromPolyArc( const PolyArc& PA) if ( AreSamePointApprox( ptIni, ptFin)) continue ; // se retta - if ( fabs( dBulge) < EPS_SMALL) { + if ( abs( dBulge) < EPS_SMALL) { // creo la retta PtrOwner pCrvLine( CreateBasicCurveLine()) ; if ( IsNull( pCrvLine)) @@ -724,7 +724,7 @@ CurveComposite::GetLocalBBox( BBox3d& b3Loc, int nFlag) const pCrvSmpl = GetNextCurve() ; } // se c'è estrusione, devo tenerne conto (curve componenti sempre con vtExtr e dThick nulli) - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Point3d ptMinExtr = b3Loc.GetMin() + m_VtExtr * m_dThick ; Point3d ptMaxExtr = b3Loc.GetMax() + m_VtExtr * m_dThick ; b3Loc.Add( ptMinExtr) ; @@ -758,7 +758,7 @@ CurveComposite::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const pCrvSmpl = GetNextCurve() ; } // se c'è estrusione, devo tenerne conto (curve componenti sempre con vtExtr e dThick nulli) - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Vector3d vtFrExtr = m_VtExtr ; vtFrExtr.ToGlob( frRef) ; Point3d ptMinExtr = b3Ref.GetMin() + vtFrExtr * m_dThick ; @@ -1062,11 +1062,11 @@ CurveComposite::GetIndSCurveAndLocPar( double dU, Side nS, int& nSCrv, double& d // determino la curva di appartenenza e il valore locale (ovvero nella curva) del parametro nSCrv = static_cast( dU) ; dLocU = dU - nSCrv ; - if ( fabs( dLocU) < 5 * EPS_PARAM && nSCrv > 0 && nS == ICurve::FROM_MINUS) { + if ( abs( dLocU) < 5 * EPS_PARAM && nSCrv > 0 && nS == ICurve::FROM_MINUS) { -- nSCrv ; dLocU = 1 ; } - else if ( fabs( dLocU) > 1 - 5 * EPS_PARAM && nSCrv < dMaxU - 1 && nS == ICurve::FROM_PLUS) { + else if ( abs( dLocU) > 1 - 5 * EPS_PARAM && nSCrv < dMaxU - 1 && nS == ICurve::FROM_PLUS) { ++ nSCrv ; dLocU = 0 ; } @@ -1490,7 +1490,7 @@ bool CurveComposite::SimpleOffset( double dDist, int nType) { // se distanza di offset nulla, non devo fare alcunché - if ( fabs( dDist) < EPS_SMALL) + if ( abs( dDist) < EPS_SMALL) return true ; // --- l'offset va effettuato in un piano perpendicolare al vettore estrusione --- @@ -2131,7 +2131,7 @@ bool CurveComposite::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) { // verifico non sia nulla - if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO) + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; // calcolo bbox allineato con riferimento di scalatura e senza tener conto dello spessore @@ -2143,16 +2143,16 @@ CurveComposite::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, dou return false ; swap( dOriThick, m_dThick) ; Vector3d vtDelta = b3Ref.GetMax() - b3Ref.GetMin() ; - if ( fabs( vtDelta.x * dCoeffX) < EPS_SMALL && - fabs( vtDelta.y * dCoeffY) < EPS_SMALL && - fabs( vtDelta.z * dCoeffZ) < EPS_SMALL) + if ( abs( vtDelta.x * dCoeffX) < EPS_SMALL && + abs( vtDelta.y * dCoeffY) < EPS_SMALL && + abs( vtDelta.z * dCoeffZ) < EPS_SMALL) return false ; // imposto ricalcolo della grafica m_OGrMgr.Reset() ; // se scalatura non omogenea, devo trasformare tutti gli archi in curve di Bezier - if ( fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL) { + if ( abs( dCoeffX - dCoeffY) > EPS_SMALL || abs( dCoeffX - dCoeffZ) > EPS_SMALL) { if ( ! ArcsToBezierCurves()) return false ; } @@ -2435,9 +2435,9 @@ CurveComposite::IsParamAtJoint( double dU) const { // se aperta e all'inizio o alla fine o lontano dagli interi non è giunzione bool bClosed = IsClosed() ; - if ( ( ! bClosed && fabs( dU) < EPS_PARAM) || - ( ! bClosed && fabs( dU - double( m_CrvSmplS.size())) < EPS_PARAM) || - fabs( dU - (int) ( dU + EPS_PARAM)) > EPS_PARAM) + if ( ( ! bClosed && abs( dU) < EPS_PARAM) || + ( ! bClosed && abs( dU - double( m_CrvSmplS.size())) < EPS_PARAM) || + abs( dU - (int) ( dU + EPS_PARAM)) > EPS_PARAM) return false ; else return true ; @@ -2633,7 +2633,7 @@ CurveComposite::MergeTwoCurves( ICurve* pCrvP, ICurve* pCrvC, double& dCurrLinTo if ( ! AreSamePointEpsilon( ptC1Fin, ptC2Ini, dCurrLinTol)) return false ; // verifico la coincidenza dei raggi - if ( fabs( pArcP->GetRadius() - pArcC->GetRadius()) > dCurrLinTol) + if ( abs( pArcP->GetRadius() - pArcC->GetRadius()) > dCurrLinTol) return false ; // verifico la collinearità delle normali (tenendo conto del raggio) if ( ! (( pArcP->GetNormVersor() - pArcC->GetNormVersor()) * pArcP->GetRadius()).IsSmall() && @@ -2672,7 +2672,7 @@ CurveComposite::MergeTwoCurves( ICurve* pCrvP, ICurve* pCrvC, double& dCurrLinTo } // verifico coincidenza pendenza sulla normale double dN = pArcP->GetNormVersor() * pArcC->GetNormVersor() ; - if ( fabs(( pArcC->GetDeltaN() * pArcP->GetAngCenter() - dN * pArcP->GetDeltaN() * pArcC->GetAngCenter()) / + if ( abs(( pArcC->GetDeltaN() * pArcP->GetAngCenter() - dN * pArcP->GetDeltaN() * pArcC->GetAngCenter()) / ( pArcP->GetAngCenter() + pArcC->GetAngCenter())) < dCurrLinTol) { // se calcolo nuovo arco ok, procedo con l'unione Point3d ptP1 ; diff --git a/CurveCompositeOffset.cpp b/CurveCompositeOffset.cpp index c6ee50d..a65c939 100644 --- a/CurveCompositeOffset.cpp +++ b/CurveCompositeOffset.cpp @@ -188,7 +188,7 @@ VerifyAndAdjustSamePoint( ICurve* pCrv1, ICurve* pCrv2, CurveComposite& ccAux) if ( ! AreSamePointXYEpsilon( ptP1, ptP2, 10 * EPS_SMALL)) return false ; // se punti quasi coincidenti in Z - if ( fabs( ptP1.z - ptP2.z) < 10 * EPS_SMALL) { + if ( abs( ptP1.z - ptP2.z) < 10 * EPS_SMALL) { // se coincidono esattamente, va bene così if ( AreSamePointExact( ptP1, ptP2)) return true ; @@ -238,7 +238,7 @@ VerifyAndAdjustInternalAngle( ICurve* pCrv1, ICurve* pCrv2, CurveComposite& ccAu ! intCC.GetIntersPointNearTo( 1, ptMid, ptNew2)) return false ; // se punti coincidenti in Z - if ( fabs( ptNew1.z - ptNew2.z) < EPS_SMALL) { + if ( abs( ptNew1.z - ptNew2.z) < EPS_SMALL) { // modifico le due curve sul punto medio Point3d ptNew = 0.5 * ( ptNew1 + ptNew2) ; return ( pCrv1->ModifyEnd( ptNew) && pCrv2->ModifyStart( ptNew)) ; @@ -277,8 +277,8 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT if ( ! pCrv1->GetEndDir( vtDir1) || ! pCrv2->GetStartDir( vtDir2)) return false ; // verifico se presente componente in Z - bool bDZ1 = fabs( vtDir1.z) > EPS_ANG_ZERO ; - bool bDZ2 = fabs( vtDir2.z) > EPS_ANG_ZERO ; + bool bDZ1 = abs( vtDir1.z) > EPS_ANG_ZERO ; + bool bDZ2 = abs( vtDir2.z) > EPS_ANG_ZERO ; // le porto nel piano XY vtDir1.z = 0 ; vtDir2.z = 0 ; @@ -290,7 +290,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT if ( ! vtDir1.GetAngleXY( vtDir2, dAngDeg)) return false ; // se vicino all'angolo piatto, si devono ricalcolare usando le curve originali e spostandosi un poco - if ( fabs( dAngDeg) > ( ANG_STRAIGHT - EPS_ANG_SMALL)) { + if ( abs( dAngDeg) > ( ANG_STRAIGHT - EPS_ANG_SMALL)) { // ritorno alle curve originali PtrOwner pCrvOri1( pCrv1->Clone()) ; PtrOwner pCrvOri2( pCrv2->Clone()) ; @@ -314,18 +314,18 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT } // verifico sia angolo esterno (accetto se entità quasi esattamente sovrapposto) - if ( fabs( dAngDeg) < ( ANG_STRAIGHT - 10 * EPS_ANG_ZERO) && + if ( abs( dAngDeg) < ( ANG_STRAIGHT - 10 * EPS_ANG_ZERO) && ( ( dDist < 0 && dAngDeg > 0) || ( dDist > 0 && dAngDeg < 0))) return false ; // se l'angolo esterno supera il retto, offset extend diventa offset chamfer - if ( nType == ICurve::OFF_EXTEND && fabs( dAngDeg) > ANG_RIGHT + EPS_ANG_SMALL) + if ( nType == ICurve::OFF_EXTEND && abs( dAngDeg) > ANG_RIGHT + EPS_ANG_SMALL) nType = ICurve::OFF_CHAMFER ; // se angolo esterno molto piccolo, semplifico tutto const double SMALL_EXT_ANG = 1.0 ; - bool bAngSmall = ( fabs( dAngDeg) < SMALL_EXT_ANG) ; + bool bAngSmall = ( abs( dAngDeg) < SMALL_EXT_ANG) ; if ( bAngSmall) nType = ICurve::OFF_EXTEND ; @@ -348,7 +348,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT case ICurve::OFF_CHAMFER : { // lunghezza aggiuntiva in tangenza - double dLen = fabs( dDist) * tan( fabs( dAngDeg) / 4 * DEGTORAD) ; + double dLen = abs( dDist) * tan( abs( dAngDeg) / 4 * DEGTORAD) ; // punti di costruzione smusso Point3d ptP1, ptP1a, ptP2a, ptP2 ; if ( ! pCrv1->GetEndPoint( ptP1) || ! pCrv2->GetStartPoint( ptP2)) @@ -357,7 +357,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT ptP2a = ptP2 - vtDir2 * dLen ; // se sull'angolo c'era un dislivello (linea verticale eliminata) double dDeltaZ = ptP2.z - ptP1.z ; - if ( fabs( dDeltaZ) > EPS_SMALL) { + if ( abs( dDeltaZ) > EPS_SMALL) { ptP1a.z += dDeltaZ / 4 ; ptP2a.z -= dDeltaZ / 4 ; bDZ1 = true ; @@ -399,7 +399,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT case ICurve::OFF_EXTEND : { // lunghezza aggiuntiva in tangenza - double dLen = fabs( dDist) * tan( fabs( dAngDeg) / 2 * DEGTORAD) ; + double dLen = abs( dDist) * tan( abs( dAngDeg) / 2 * DEGTORAD) ; // punti di costruzione estensione Point3d ptP1, ptPc, ptP2 ; if ( ! pCrv1->GetEndPoint( ptP1) || ! pCrv2->GetStartPoint( ptP2)) @@ -407,7 +407,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dDist, int nT ptPc = ptP1 + vtDir1 * dLen ; // se sull'angolo c'era un dislivello (linea verticale eliminata) double dDeltaZ = ptP2.z - ptP1.z ; - if ( fabs( dDeltaZ) > EPS_SMALL) { + if ( abs( dDeltaZ) > EPS_SMALL) { ptPc.z += dDeltaZ / 2 ; bDZ1 = true ; bDZ2 = true ; @@ -445,7 +445,7 @@ bool AddFirstLastVerticalLines( CurveComposite& ccOffs, double dLenVertFirst, double dLenVertLast) { // se richiesto inserimento prima retta verticale - if ( fabs( dLenVertFirst) > EPS_SMALL) { + if ( abs( dLenVertFirst) > EPS_SMALL) { Point3d ptP2 ; if ( ! ccOffs.GetStartPoint( ptP2)) return false ; @@ -458,7 +458,7 @@ AddFirstLastVerticalLines( CurveComposite& ccOffs, double dLenVertFirst, double return false ; } // se richiesto inserimento ultima retta verticale - if ( fabs( dLenVertLast) > EPS_SMALL) { + if ( abs( dLenVertLast) > EPS_SMALL) { Point3d ptP1 ; if ( ! ccOffs.GetEndPoint( ptP1)) return false ; diff --git a/CurveLine.cpp b/CurveLine.cpp index 252569e..6e5e23b 100644 --- a/CurveLine.cpp +++ b/CurveLine.cpp @@ -211,7 +211,7 @@ CurveLine::GetLocalBBox( BBox3d& b3Loc, int nFlag) const // assegno il box in locale b3Loc.Set( m_PtStart, m_PtEnd) ; // se c'è estrusione, devo tenerne conto - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Point3d ptMinExtr = b3Loc.GetMin() + m_VtExtr * m_dThick ; Point3d ptMaxExtr = b3Loc.GetMax() + m_VtExtr * m_dThick ; b3Loc.Add( ptMinExtr) ; @@ -239,7 +239,7 @@ CurveLine::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const // assegno il box nel riferimento b3Ref.Set( ptFrStart, ptFrEnd) ; // se c'è estrusione, devo tenerne conto - if ( ! m_VtExtr.IsSmall() && fabs( m_dThick) > EPS_SMALL) { + if ( ! m_VtExtr.IsSmall() && abs( m_dThick) > EPS_SMALL) { Vector3d vtFrExtr = m_VtExtr ; vtFrExtr.ToGlob( frRef) ; Point3d ptMinExtr = b3Ref.GetMin() + vtFrExtr * m_dThick ; @@ -822,7 +822,7 @@ CurveLine::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double d if ( m_nStatus != OK) return false ; // verifico non sia nulla - if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO) + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; // verifico che la scalatura dei punti non li porti a coincidere diff --git a/DistPointArc.cpp b/DistPointArc.cpp index 75c1bb2..485008a 100644 --- a/DistPointArc.cpp +++ b/DistPointArc.cpp @@ -82,7 +82,7 @@ DistPointArc::DistPointFlatArc( const Point3d& ptP, const ICurveArc& arArc) // se non tutti i punti e il parametro è sui bordi, li verifico entrambi if ( m_Info[0].nFlag != MDPCI_START_CONT && - ( fabs( m_Info[0].dPar) < EPS_ZERO || fabs( m_Info[0].dPar - 1) < EPS_ZERO)) { + ( abs( m_Info[0].dPar) < EPS_ZERO || abs( m_Info[0].dPar - 1) < EPS_ZERO)) { for ( int i = 0 ; i <= 1 ; i ++) { // eseguo il calcolo double dU = i ; @@ -90,7 +90,7 @@ DistPointArc::DistPointFlatArc( const Point3d& ptP, const ICurveArc& arArc) arArc.GetPointD1D2( dU, ICurve::FROM_MINUS, ptTest) ; double dDist = Dist( ptP, ptTest) ; // altro punto con la stessa minima distanza - if ( i == 1 && fabs( dDist - m_dDist) < EPS_SMALL) { + if ( i == 1 && abs( dDist - m_dDist) < EPS_SMALL) { // lo aggiungo m_Info.emplace_back( MDPCI_NORMAL, dU, ptTest) ; } diff --git a/DistPointCrvAux.cpp b/DistPointCrvAux.cpp index 827998c..95324fd 100644 --- a/DistPointCrvAux.cpp +++ b/DistPointCrvAux.cpp @@ -46,7 +46,7 @@ CalcMinDistPointPolyLine( const Point3d& ptP, PolyLine& PL, double dLinTol, MDCV if ( ! dstPtLn.GetSqDist( dSqDist)) continue ; // altro punto con la stessa minima distanza già trovata - if ( bFound && fabs( dSqDist - dSqMinDist) < 2 * dMinDist * dLinTol) { + if ( bFound && abs( dSqDist - dSqMinDist) < 2 * dMinDist * dLinTol) { // salvo i dati nella struttura approxMin.dDist = dMinDist ; dstPtLn.GetMinDistPoint( approxMin.ptQ) ; @@ -111,20 +111,20 @@ PolishMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve, // contatore iterazioni nCount ++ ; // calcolo P, D1 e D2 - nSide = ( fabs( dPar - approxMin.dParMin) < EPS_PARAM) ? ICurve::FROM_PLUS : ICurve::FROM_MINUS ; + nSide = ( abs( dPar - approxMin.dParMin) < EPS_PARAM) ? ICurve::FROM_PLUS : ICurve::FROM_MINUS ; cCurve.GetPointD1D2( dPar, nSide, ptQ, &vtDer1, &vtDer2) ; // vettore dal punto al piede sulla curva vtDiff = ptQ - ptP ; // angolo tra vettore e tangente dTemp = vtDer1 * vtDiff ; - if ( fabs( dTemp) > EPS_ZERO) + if ( abs( dTemp) > EPS_ZERO) dSqCosA = dTemp * dTemp / ( vtDer1.SqLen() * vtDiff.SqLen()) ; else dSqCosA = 0 ; // stima prossimo valore del parametro (Newton : Unext = U - F(U) / F'(U)) dPrevPar = dPar ; dTemp = vtDer2 * vtDiff + vtDer1.SqLen() ; - if ( fabs( dTemp) > EPS_ZERO) + if ( abs( dTemp) > EPS_ZERO) dPar = dPrevPar - ( vtDer1 * vtDiff) / dTemp ; // clipping parametro if ( dPar < approxMin.dParMin) { @@ -143,8 +143,8 @@ PolishMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve, else dPar = approxMin.dParMax ; } - } while ( nCount < MAX_COUNT && fabs( dPar - dPrevPar) > EPS_PARAM && - fabs( dSqCosA) > COS_ORTO_ANG_ZERO * COS_ORTO_ANG_ZERO) ; + } while ( nCount < MAX_COUNT && abs( dPar - dPrevPar) > EPS_PARAM && + abs( dSqCosA) > COS_ORTO_ANG_ZERO * COS_ORTO_ANG_ZERO) ; if ( nCount == MAX_COUNT) LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") ; @@ -165,17 +165,17 @@ FilterMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve, bool bLastOnEnd = false ; // flag per ultimo punto su fine del suo intervallo for ( Iter = vApproxMin.begin() ; Iter != vApproxMin.end() ; ++Iter) { // altro punto con la stessa minima distanza - if ( bFound && fabs( (*Iter).dDist - dMinDist) < EPS_SMALL) { + if ( bFound && abs( (*Iter).dDist - dMinDist) < EPS_SMALL) { // se abbastanza lontano e non su bordi intervallino lo aggiungo if ( SqDist( (*Iter).ptQ, Info.back().ptQ) > MIN_LEN_CONT_MDPC && - ! bLastOnEnd && fabs( (*Iter).dPar - (*Iter).dParMin) > EPS_PARAM) { + ! bLastOnEnd && abs( (*Iter).dPar - (*Iter).dParMin) > EPS_PARAM) { Info.emplace_back( MDPCI_NORMAL, (*Iter).dPar, (*Iter).ptQ) ; - bLastOnEnd = fabs( (*Iter).dPar - (*Iter).dParMax) < EPS_PARAM ; + bLastOnEnd = abs( (*Iter).dPar - (*Iter).dParMax) < EPS_PARAM ; } // altrimenti lo sostituisco se distanza minore else if ( (*Iter).dDist < dMinDist) { Info.back() = MinDistPCInfo( MDPCI_NORMAL, (*Iter).dPar, (*Iter).ptQ) ; - bLastOnEnd = fabs( (*Iter).dPar - (*Iter).dParMax) < EPS_PARAM ; + bLastOnEnd = abs( (*Iter).dPar - (*Iter).dParMax) < EPS_PARAM ; } } // primo punto o punto con minima distanza più bassa @@ -186,7 +186,7 @@ FilterMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve, // il nuovo vettore deve contenere solo quest'ultimo minimo Info.clear() ; Info.emplace_back( MDPCI_NORMAL, (*Iter).dPar, (*Iter).ptQ) ; - bLastOnEnd = fabs( (*Iter).dPar - (*Iter).dParMax) < EPS_PARAM ; + bLastOnEnd = abs( (*Iter).dPar - (*Iter).dParMax) < EPS_PARAM ; } } if ( Info.empty()) @@ -201,7 +201,7 @@ FilterMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve, for ( int i = 1 ; i < (int) Info.size() ; ++ i) { dU = 0.5 * ( Info[i-1].dPar + Info[i].dPar) ; cCurve.GetPointD1D2( dU, ICurve::FROM_MINUS, ptQ) ; - if ( fabs( SqDist( ptP, ptQ) - dMinDist * dMinDist) > 2 * dMinDist * EPS_SMALL) { + if ( abs( SqDist( ptP, ptQ) - dMinDist * dMinDist) > 2 * dMinDist * EPS_SMALL) { bCont = false ; break ; } diff --git a/DistPointCrvBezier.cpp b/DistPointCrvBezier.cpp index 3fb2de5..7fc2f70 100644 --- a/DistPointCrvBezier.cpp +++ b/DistPointCrvBezier.cpp @@ -54,8 +54,8 @@ DistPointCrvBezier::DistPointCrvBezier( const Point3d& ptP, const ICurveBezier& dSingP = - 1 ; for ( Iter = vApproxMin.begin() ; Iter != vApproxMin.end() ; ++Iter) { // imposto flag per singolarità agli estremi - (*Iter).bParMinSing = fabs( (*Iter).dParMin - dSingP) < EPS_SMALL ; - (*Iter).bParMaxSing = fabs( (*Iter).dParMax - dSingP) < EPS_SMALL ; + (*Iter).bParMinSing = abs( (*Iter).dParMin - dSingP) < EPS_SMALL ; + (*Iter).bParMaxSing = abs( (*Iter).dParMax - dSingP) < EPS_SMALL ; } // raffino i punti trovati diff --git a/DistPointCrvComposite.cpp b/DistPointCrvComposite.cpp index 1ef8248..5ca251a 100644 --- a/DistPointCrvComposite.cpp +++ b/DistPointCrvComposite.cpp @@ -60,7 +60,7 @@ DistPointCrvComposite::DistPointCrvComposite( const Point3d& ptP, const ICurveCo if ( ! dstPC.GetDist( dCurrDist)) return ; // con la stessa minima distanza - if ( fabs( dCurrDist - m_dDist) < EPS_SMALL) { + if ( abs( dCurrDist - m_dDist) < EPS_SMALL) { // aggiungo int i = 0 ; MinDistPCInfo aInfo ; @@ -68,7 +68,7 @@ DistPointCrvComposite::DistPointCrvComposite( const Point3d& ptP, const ICurveCo // porto la parametrizzazione da locale a globale aInfo.dPar += dIniCrvPar ; // se il primo nuovo punto coincide con l'ultimo dei precedenti - if ( i == 0 && fabs( m_Info.back().dPar - aInfo.dPar) < EPS_SMALL && + if ( i == 0 && abs( m_Info.back().dPar - aInfo.dPar) < EPS_SMALL && AreSamePointApprox( m_Info.back().ptQ, aInfo.ptQ)) { if ( m_Info.back().nFlag == MDPCI_NORMAL) { // START deve sostituire il vecchio diff --git a/DistPointCurve.cpp b/DistPointCurve.cpp index 458c7c6..4e25078 100644 --- a/DistPointCurve.cpp +++ b/DistPointCurve.cpp @@ -154,7 +154,7 @@ DistPointCurve::GetMinDistPoint( double dNearParam, Point3d& ptMinDist, int& nFl double dParam ; for ( int i = 0 ; i < (int) m_Info.size() ; ++ i) { if ( i == 0 || - fabs( m_Info[i].dPar - dNearParam) < fabs( dParam - dNearParam)) { + abs( m_Info[i].dPar - dNearParam) < abs( dParam - dNearParam)) { dParam = m_Info[i].dPar ; ptMinDist = m_Info[i].ptQ ; nFlag = m_Info[i].nFlag ; @@ -198,7 +198,7 @@ DistPointCurve::GetParamAtMinDistPoint( double dNearParam, double& dParam, int& // cerco punto discreto più vicino (anche estremi di zone continue) for ( int i = 0 ; i < (int) m_Info.size() ; ++ i) { if ( i == 0 || - fabs( m_Info[i].dPar - dNearParam) < fabs( dParam - dNearParam)) { + abs( m_Info[i].dPar - dNearParam) < abs( dParam - dNearParam)) { dParam = m_Info[i].dPar ; nFlag = m_Info[i].nFlag ; } @@ -246,7 +246,7 @@ DistPointCurve::GetSideAtMinDistPoint( int nInd, const Vector3d& vtN, int& nSide // determino il lato di giacitura del punto double dSide = vtRef * ( m_ptP - ptQ) ; - if ( fabs( dSide) < EPS_SMALL) + if ( abs( dSide) < EPS_SMALL) nSide = MDS_ON ; else if ( dSide > 0) nSide = MDS_LEFT ; @@ -267,7 +267,7 @@ DistPointCurve::GetSideAtMinDistPoint( double dNearParam, const Vector3d& vtN, i double dParam ; for ( int i = 0 ; i < (int) m_Info.size() ; ++ i) { if ( i == 0 || - fabs( m_Info[i].dPar - dNearParam) < fabs( dParam - dNearParam)) { + abs( m_Info[i].dPar - dNearParam) < abs( dParam - dNearParam)) { nInd = i ; dParam = m_Info[i].dPar ; } diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index b0c67ea..51c385c 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/ExtText.cpp b/ExtText.cpp index 2b60012..0bdbfdd 100644 --- a/ExtText.cpp +++ b/ExtText.cpp @@ -406,7 +406,7 @@ bool ExtText::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) { // verifico non sia nulla - if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO) + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; // imposto ricalcolo della grafica diff --git a/Frame3d.cpp b/Frame3d.cpp index e4039a5..5967945 100644 --- a/Frame3d.cpp +++ b/Frame3d.cpp @@ -96,7 +96,7 @@ Frame3d::Set( const Point3d& ptOrig, const Vector3d& vtDirZ) if ( ! m_vtVersZ.Normalize()) return false ; // versore X (metodo OCS di DXF) - if ( fabs( m_vtVersZ.x) < 1./64. && fabs( m_vtVersZ.y) < 1./64.) + if ( abs( m_vtVersZ.x) < 1./64. && abs( m_vtVersZ.y) < 1./64.) m_vtVersX = Y_AX ^ m_vtVersZ ; else m_vtVersX = Z_AX ^ m_vtVersZ ; @@ -461,9 +461,9 @@ Frame3d::Verify( void) double dOrtZX = m_vtVersZ * m_vtVersX ; Vector3d vtTmp = m_vtVersX ^ m_vtVersY ; double dRight = vtTmp * m_vtVersZ ; - if ( fabs( dOrtXY) > EPS_ZERO || - fabs( dOrtYZ) > EPS_ZERO || - fabs( dOrtZX) > EPS_ZERO || + if ( abs( dOrtXY) > EPS_ZERO || + abs( dOrtYZ) > EPS_ZERO || + abs( dOrtZX) > EPS_ZERO || dRight < EPS_ZERO) return false ; else @@ -479,14 +479,14 @@ Frame3d::CalculateType( void) m_nZType = ERR ; // se la Zloc non ha componenti x e y globali allora é diretta come Zglob - if ( fabs( m_vtVersZ.x) < EPS_ZERO && fabs( m_vtVersZ.y) < EPS_ZERO) { + if ( abs( m_vtVersZ.x) < EPS_ZERO && abs( m_vtVersZ.y) < EPS_ZERO) { // se inoltre ha lo stesso verso di Zglob if ( m_vtVersZ.z > 0) m_nZType = TOP ; else m_nZType = BOTTOM ; // se la Xloc coincide con Xglob Type coincide con ZType - if ( fabs( m_vtVersX.y) < EPS_ZERO && fabs( m_vtVersX.z) < EPS_ZERO && + if ( abs( m_vtVersX.y) < EPS_ZERO && abs( m_vtVersX.z) < EPS_ZERO && m_vtVersX.x > 0) m_nType = m_nZType ; else @@ -494,14 +494,14 @@ Frame3d::CalculateType( void) } // se la Zloc non ha componenti y e z globali allora é diretta come Xglob - else if ( fabs( m_vtVersZ.y) < EPS_ZERO && fabs( m_vtVersZ.z) < EPS_ZERO) { + else if ( abs( m_vtVersZ.y) < EPS_ZERO && abs( m_vtVersZ.z) < EPS_ZERO) { // se inoltre ha lo stesso verso di Xglob if ( m_vtVersZ.x > 0) m_nZType = RIGHT ; else m_nZType = LEFT ; // se la Yloc coincide con Zglob Type coincide con ZType - if ( fabs( m_vtVersY.x) < EPS_ZERO && fabs( m_vtVersY.y) < EPS_ZERO && + if ( abs( m_vtVersY.x) < EPS_ZERO && abs( m_vtVersY.y) < EPS_ZERO && m_vtVersY.z > 0) m_nType = m_nZType ; else @@ -509,14 +509,14 @@ Frame3d::CalculateType( void) } // se la Zloc non ha componenti z e x globali allora é diretta come Yglob - else if ( fabs( m_vtVersZ.z) < EPS_ZERO && fabs( m_vtVersZ.x) < EPS_ZERO) { + else if ( abs( m_vtVersZ.z) < EPS_ZERO && abs( m_vtVersZ.x) < EPS_ZERO) { // se inoltre ha lo stesso verso di Yglob if ( m_vtVersZ.y > 0) m_nZType = BACK ; else m_nZType = FRONT ; // se la Yloc coincide con Zglob Type coincide con ZType - if ( fabs( m_vtVersY.x) < EPS_ZERO && fabs( m_vtVersY.y) < EPS_ZERO && + if ( abs( m_vtVersY.x) < EPS_ZERO && abs( m_vtVersY.y) < EPS_ZERO && m_vtVersY.z > 0) m_nType = m_nZType ; else diff --git a/GdbExecutor.cpp b/GdbExecutor.cpp index 6272d26..8912b54 100644 --- a/GdbExecutor.cpp +++ b/GdbExecutor.cpp @@ -7483,7 +7483,7 @@ GdbExecutor::CurveCopyBySplitClass( const STRVECTOR& vsParams) if ( nIdGrp[nGrp] < GDB_ID_ROOT) continue ; // se curva praticamente nulla, vado oltre - if ( fabs( ccClass[i].dParE - ccClass[i].dParS) < 10 * EPS_PARAM) + if ( abs( ccClass[i].dParE - ccClass[i].dParS) < 10 * EPS_PARAM) continue ; // copio la parte di curva che interessa e la porto nel riferimento del gruppo PtrOwner pSplit( pCrv->CopyParamRange( ccClass[i].dParS, ccClass[i].dParE)) ; diff --git a/GdbGeo.cpp b/GdbGeo.cpp index 20c4c08..794b0f4 100644 --- a/GdbGeo.cpp +++ b/GdbGeo.cpp @@ -295,7 +295,7 @@ GdbGeo::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoe // se arco e scalatura non omogenea if ( m_pGeoObj->GetType() == CRV_ARC && - (fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL)) { + (abs( dCoeffX - dCoeffY) > EPS_SMALL || abs( dCoeffX - dCoeffZ) > EPS_SMALL)) { // curva originale ICurve* pCrv = GetCurve( m_pGeoObj) ; // trasformo in curva di Bezier (semplice o composta) diff --git a/IntersArcArc.cpp b/IntersArcArc.cpp index 1d8f40a..16873e8 100644 --- a/IntersArcArc.cpp +++ b/IntersArcArc.cpp @@ -30,8 +30,8 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) if ( ! Arc1.IsValid() || ! Arc2.IsValid()) return ; // verifico che l'angolo al centro non superi il giro - if ( fabs( Arc1.GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO || - fabs( Arc2.GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) + if ( abs( Arc1.GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO || + abs( Arc2.GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) return ; // ne faccio una copia m_Arc1.CopyFrom( &Arc1) ; @@ -63,13 +63,13 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) return ; // cerchi interni -> nessuna intersezione - if ( dDist < fabs( m_Arc1.GetRadius() - m_Arc2.GetRadius()) - EPS_SMALL) + if ( dDist < abs( m_Arc1.GetRadius() - m_Arc2.GetRadius()) - EPS_SMALL) return ; // cerchi coincidenti -> sovrapposizioni e/o intersezioni agli estremi - if ( dDist < EPS_SMALL && fabs( m_Arc1.GetRadius() - m_Arc2.GetRadius()) < EPS_SMALL) { + if ( dDist < EPS_SMALL && abs( m_Arc1.GetRadius() - m_Arc2.GetRadius()) < EPS_SMALL) { // coefficiente da parametro dell'arco 1 a lunghezza - double dU2L = fabs( m_Arc1.GetAngCenter()) * DEGTORAD * m_Arc1.GetRadius() ; + double dU2L = abs( m_Arc1.GetAngCenter()) * DEGTORAD * m_Arc1.GetRadius() ; // determino se sono equiversi o controversi bool bEqVers = (( m_Arc1.GetAngCenter() * m_Arc1.GetNormVersor().z * m_Arc2.GetAngCenter() * m_Arc2.GetNormVersor().z) > 0) ; @@ -89,9 +89,9 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) if ( ! m_Arc1.CalcPointParamPosiz( ptS2, dUS2, nPosS2)) return ; // calcolo dell'ampiezza parametrica dell'arco 2 nel riferimento dell'arco 1 - double dDeltaU2 = fabs( m_Arc2.GetAngCenter() / m_Arc1.GetAngCenter()) * ( bEqVers ? 1 : -1) ; + double dDeltaU2 = abs( m_Arc2.GetAngCenter() / m_Arc1.GetAngCenter()) * ( bEqVers ? 1 : -1) ; // calcolo dell'ampiezza parametrica di un giro nel riferimento dell'arco 1 - double dTurnU = fabs( ANG_FULL / m_Arc1.GetAngCenter()) ; + double dTurnU = abs( ANG_FULL / m_Arc1.GetAngCenter()) ; // determinazione del minimo e massimo parametro dell'arco 2 nel riferimento dell'arco 1 double dU2min = dUS2 ; double dU2max = dUS2 + dDeltaU2 ; @@ -103,7 +103,7 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) dU2max += dTurnU ; } // se il minimo di 2 coincide con il massimo di 1 nel primo giro -> un punto estremo - if ( fabs( 1 - dU2min) * dU2L < EPS_SMALL) { + if ( abs( 1 - dU2min) * dU2L < EPS_SMALL) { m_Info[0].IciA[0].dU = 1 ; m_Info[0].IciB[0].dU = ( bEqVers ? 0 : 1) ; m_Info[0].IciA[0].ptI = ptE1 ; @@ -161,7 +161,7 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) m_nNumInters = 1 ; } // se il massimo di 2 coincide con il minimo di 1 nel secondo giro e 1 e 2 non completi -> un punto estremo - if ( fabs( dTurnU - dU2max) * dU2L < EPS_SMALL && ! bClosed1 && ! bClosed2) { + if ( abs( dTurnU - dU2max) * dU2L < EPS_SMALL && ! bClosed1 && ! bClosed2) { m_Info[m_nNumInters].IciA[0].dU = 0 ; m_Info[m_nNumInters].IciB[0].dU = ( bEqVers ? 1 : 0) ; m_Info[m_nNumInters].IciA[0].ptI = ptS1 ; @@ -235,7 +235,7 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) double dSqH = m_Arc1.GetRadius() * m_Arc1.GetRadius() - dA * dA ; // cerchi tangenti esterni -> una intersezione - if ( fabs( dDist - ( m_Arc1.GetRadius() + m_Arc2.GetRadius())) < EPS_SMALL) { + if ( abs( dDist - ( m_Arc1.GetRadius() + m_Arc2.GetRadius())) < EPS_SMALL) { // tolleranza tangenziale sull'intersezione double dTgTol = ( dSqH > SQ_EPS_SMALL ? sqrt( dSqH) : EPS_SMALL) ; // calcolo il punto di intersezione @@ -357,7 +357,7 @@ IntersArcArc::IntersArcArc( const CurveArc& Arc1, const CurveArc& Arc2) } // cerchi tangenti interni -> una intersezione - if ( fabs( dDist - fabs( m_Arc1.GetRadius() - m_Arc2.GetRadius())) < EPS_SMALL) { + if ( abs( dDist - abs( m_Arc1.GetRadius() - m_Arc2.GetRadius())) < EPS_SMALL) { // tolleranza tangenziale sull'intersezione double dTgTol = ( dSqH > SQ_EPS_SMALL ? sqrt( dSqH) : EPS_SMALL) ; // determino quale dei due contiene l'altro diff --git a/IntersCrvCompoCrvCompo.cpp b/IntersCrvCompoCrvCompo.cpp index 75dfc4d..07884b7 100644 --- a/IntersCrvCompoCrvCompo.cpp +++ b/IntersCrvCompoCrvCompo.cpp @@ -127,10 +127,10 @@ IntersCrvCompoCrvCompo::IntersCrvCompoCrvCompo( const ICurveComposite& CCompoA, // se intersezioni puntuali if ( ! m_Info[i].bOverlap && ! m_Info[j].bOverlap) { // se coincidono U e ptInt tra A e B - if ( fabs( m_Info[i].IciA[0].dU - m_Info[j].IciB[0].dU) < EPS_SMALL && + if ( abs( m_Info[i].IciA[0].dU - m_Info[j].IciB[0].dU) < EPS_SMALL && AreSamePointXYEpsilon( m_Info[i].IciA[0].ptI, m_Info[j].IciB[0].ptI, 10 * EPS_SMALL)) { // se non è alla fine di curva chiusa - if ( ! bCrvAClosed || fabs( m_Info[j].IciA[0].dU - dCrvBSpan) > EPS_SMALL) + if ( ! bCrvAClosed || abs( m_Info[j].IciA[0].dU - dCrvBSpan) > EPS_SMALL) // elimino la seconda EraseOtherInfo( i, j) ; else @@ -144,8 +144,8 @@ IntersCrvCompoCrvCompo::IntersCrvCompoCrvCompo( const ICurveComposite& CCompoA, // se equiverse if ( m_Info[i].bCBOverEq && m_Info[j].bCBOverEq) { // se coincidono U e ptInt tra A e B - if ( fabs( m_Info[i].IciA[0].dU - m_Info[j].IciB[0].dU) < EPS_SMALL && - fabs( m_Info[i].IciA[1].dU - m_Info[j].IciB[1].dU) < EPS_SMALL && + if ( abs( m_Info[i].IciA[0].dU - m_Info[j].IciB[0].dU) < EPS_SMALL && + abs( m_Info[i].IciA[1].dU - m_Info[j].IciB[1].dU) < EPS_SMALL && AreSamePointXYEpsilon( m_Info[i].IciA[0].ptI, m_Info[j].IciB[0].ptI, 10 * EPS_SMALL) && AreSamePointXYEpsilon( m_Info[i].IciA[1].ptI, m_Info[j].IciB[1].ptI, 10 * EPS_SMALL)) { // elimino la seconda @@ -156,8 +156,8 @@ IntersCrvCompoCrvCompo::IntersCrvCompoCrvCompo( const ICurveComposite& CCompoA, // se controverse else if ( ! m_Info[i].bCBOverEq && ! m_Info[j].bCBOverEq) { // se coincidono U e ptInt tra A e B invertiti - if ( fabs( m_Info[i].IciA[0].dU - m_Info[j].IciB[1].dU) < EPS_SMALL && - fabs( m_Info[i].IciA[1].dU - m_Info[j].IciB[0].dU) < EPS_SMALL && + if ( abs( m_Info[i].IciA[0].dU - m_Info[j].IciB[1].dU) < EPS_SMALL && + abs( m_Info[i].IciA[1].dU - m_Info[j].IciB[0].dU) < EPS_SMALL && AreSamePointXYEpsilon( m_Info[i].IciA[0].ptI, m_Info[j].IciB[1].ptI, 10 * EPS_SMALL) && AreSamePointXYEpsilon( m_Info[i].IciA[1].ptI, m_Info[j].IciB[0].ptI, 10 * EPS_SMALL)) { // elimino la seconda @@ -810,8 +810,8 @@ CompatibleParamA( const IntCrvCrvInfo& Icci1, const IntCrvCrvInfo& Icci2, bool bCrvAClosed, double dCrvASpan) { int k = ( Icci1.bOverlap ? 1 : 0) ; // del precedente si prende il secondo se overlap - if ( fabs( Icci1.IciA[k].dU - Icci2.IciA[0].dU) > 0.1 * SPAN_PARAM && - ( ! bCrvAClosed || fabs( fabs( Icci1.IciA[k].dU - Icci2.IciA[0].dU) - dCrvASpan) > 0.1 * SPAN_PARAM)) + if ( abs( Icci1.IciA[k].dU - Icci2.IciA[0].dU) > 0.1 * SPAN_PARAM && + ( ! bCrvAClosed || abs( abs( Icci1.IciA[k].dU - Icci2.IciA[0].dU) - dCrvASpan) > 0.1 * SPAN_PARAM)) return false ; return true ; } @@ -822,8 +822,8 @@ CompatibleParamB( const IntCrvCrvInfo& Icci1, const IntCrvCrvInfo& Icci2, bool bCrvBClosed, double dCrvBSpan) { int k = ( Icci1.bOverlap ? 1 : 0) ; // del precedente si prende il secondo se overlap - if ( fabs( Icci1.IciB[k].dU - Icci2.IciB[0].dU) > 0.1 * SPAN_PARAM && - ( ! bCrvBClosed || fabs( fabs( Icci1.IciB[k].dU - Icci2.IciB[0].dU) - dCrvBSpan) > 0.1 * SPAN_PARAM)) + if ( abs( Icci1.IciB[k].dU - Icci2.IciB[0].dU) > 0.1 * SPAN_PARAM && + ( ! bCrvBClosed || abs( abs( Icci1.IciB[k].dU - Icci2.IciB[0].dU) - dCrvBSpan) > 0.1 * SPAN_PARAM)) return false ; return true ; } @@ -834,7 +834,7 @@ MediaParamPoints( IntCrvInfo& Ici1, IntCrvInfo& Ici2) { // medio i parametri e i punti // per non mediare i parametri tra gli estremi di curva chiusa - if ( fabs( Ici1.dU - Ici2.dU) < 0.1 * SPAN_PARAM) { + if ( abs( Ici1.dU - Ici2.dU) < 0.1 * SPAN_PARAM) { Ici1.dU = 0.5 * ( Ici1.dU + Ici2.dU) ; Ici2.dU = Ici1.dU ; } diff --git a/IntersCurveCurve.cpp b/IntersCurveCurve.cpp index 862f226..556f9f7 100644 --- a/IntersCurveCurve.cpp +++ b/IntersCurveCurve.cpp @@ -121,7 +121,7 @@ IntersCurveCurve::IsArcToApprox( const ICurve& Curve) return false ; // verifico se non è nel piano XY o ha più di un giro al centro return ( ( ! pArc->GetNormVersor().IsZplus() && ! pArc->GetNormVersor().IsZminus()) || - fabs( pArc->GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) ; + abs( pArc->GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) ; } //---------------------------------------------------------------------------- diff --git a/IntersLineArc.cpp b/IntersLineArc.cpp index 971bd5b..eac0c34 100644 --- a/IntersLineArc.cpp +++ b/IntersLineArc.cpp @@ -32,7 +32,7 @@ IntersLineArc::IntersLineArc( const CurveLine& Line, const CurveArc& Arc) if ( ! Arc.GetNormVersor().IsZplus() && ! Arc.GetNormVersor().IsZminus()) return ; // verifico che l'angolo al centro non superi il giro - if ( fabs( Arc.GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) + if ( abs( Arc.GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) return ; // !!! Gestire l'arco proiettato come ellisse diff --git a/IntersLineLine.cpp b/IntersLineLine.cpp index de58ef5..ff96ce4 100644 --- a/IntersLineLine.cpp +++ b/IntersLineLine.cpp @@ -24,7 +24,7 @@ bool IsPointOutFatSegment( const Point3d& ptP, const Point3d& ptS, const Vector3d& vtDir, double dLenXY, double dTol) { // distanza del punto dalla linea del segmento (con compensazione piccolissimi errori) - if ( fabs( CrossXY( ( ptP - ptS), vtDir)) < ( dTol + EPS_ZERO) * dLenXY) + if ( abs( CrossXY( ( ptP - ptS), vtDir)) < ( dTol + EPS_ZERO) * dLenXY) return false ; // distanza con segno della proiezione del punto sul segmento dall'inizio per lunghezza segmento double dDistXY = ScalarXY( ( ptP - ptS), vtDir) ; @@ -77,7 +77,7 @@ IntersLineLine::IntersInfiniteLines( const ICurveLine& Line1, const ICurveLine& double dCrossXY = CrossXY( vtDir1, vtDir2) ; // se le linee non sono parallele - if ( fabs( dCrossXY) > SIN_EPS_ANG_ZERO * ( dLen1XY * dLen2XY)) { + if ( abs( dCrossXY) > SIN_EPS_ANG_ZERO * ( dLen1XY * dLen2XY)) { // posizioni parametriche dell'intersezione sulle linee m_Info.IciA[0].dU = CrossXY( ( ptS2 - ptS1), vtDir2) / dCrossXY ; m_Info.IciB[0].dU = CrossXY( ( ptS2 - ptS1), vtDir1) / dCrossXY ; @@ -108,7 +108,7 @@ IntersLineLine::IntersInfiniteLines( const ICurveLine& Line1, const ICurveLine& } // se le linee sono parallele e non coincidenti - if ( fabs( CrossXY( ( ptS2 - ptS1), vtDir1)) > EPS_SMALL * dLen1XY) + if ( abs( CrossXY( ( ptS2 - ptS1), vtDir1)) > EPS_SMALL * dLen1XY) return ; // non ci sono intersezioni // le linee sono parallele e coincidenti e sono infinite @@ -147,9 +147,9 @@ IntersLineLine::IntersFiniteLines( const ICurveLine& Line1, const ICurveLine& Li // prodotto vettoriale nel piano XY tra le direzioni delle linee double dCrossXY = CrossXY( vtDir1, vtDir2) ; // flag per linee parallele - bool bParallel = ( fabs( dCrossXY) < SIN_EPS_ANG_ZERO * ( dLen1XY * dLen2XY)) ; + bool bParallel = ( abs( dCrossXY) < SIN_EPS_ANG_ZERO * ( dLen1XY * dLen2XY)) ; // flag per segmenti che si allontanano significativamente - bool bFarEnds = ( ( fabs( dCrossXY) > SIN_EPS_ANG_SMALL * ( dLen1XY * dLen2XY)) || + bool bFarEnds = ( ( abs( dCrossXY) > SIN_EPS_ANG_SMALL * ( dLen1XY * dLen2XY)) || IsPointOutFatSegment( ptS1, ptS2, vtDir2, dLen2XY, EPS_SMALL) || IsPointOutFatSegment( ptE1, ptS2, vtDir2, dLen2XY, EPS_SMALL) || IsPointOutFatSegment( ptS2, ptS1, vtDir1, dLen1XY, EPS_SMALL) || diff --git a/IntersLinePlane.cpp b/IntersLinePlane.cpp index 85e9b07..d119b9d 100644 --- a/IntersLinePlane.cpp +++ b/IntersLinePlane.cpp @@ -40,9 +40,9 @@ IntersLinePlane( const Point3d& ptL, const Vector3d& vtL, double dLen, const Pla // posizione del punto rispetto al piano double dPosL = ( ptL - ORIG) * plPlane.GetVersN() - plPlane.GetDist() ; // verifico se linea parallela al piano (ovvero ortogonale alla normale) - if ( fabs( dCosAng) < COS_ORTO_ANG_ZERO) { + if ( abs( dCosAng) < COS_ORTO_ANG_ZERO) { // se il punto giace nel piano, vi giace anche la linea - if ( fabs( dPosL) < EPS_SMALL) + if ( abs( dPosL) < EPS_SMALL) return ILPT_INPLANE ; // alrimenti paralleli e non ci sono intersezioni else @@ -55,10 +55,10 @@ IntersLinePlane( const Point3d& ptL, const Vector3d& vtL, double dLen, const Pla if ( ! bFinite) return ILPT_YES ; // intersezione sul primo estremo - if ( fabs( dDistI) < EPS_SMALL) + if ( abs( dDistI) < EPS_SMALL) return ILPT_START ; // intersezione sul secondo estremo - else if ( fabs( dDistI - dLen) < EPS_SMALL) + else if ( abs( dDistI - dLen) < EPS_SMALL) return ILPT_END ; // intersezione interna else if ( dDistI > 0 && dDistI < dLen) diff --git a/LinePntTgCurve.cpp b/LinePntTgCurve.cpp index 391695d..97cb09c 100644 --- a/LinePntTgCurve.cpp +++ b/LinePntTgCurve.cpp @@ -106,7 +106,7 @@ GetLinePointTgArc( const Point3d& ptP, const CurveArc& crvArc, const Point3d& pt } // se l'arco di tangenza ha deltaN, devo applicarlo in proporzione a questi punti - if ( fabs( crvArc.GetDeltaN()) > EPS_SMALL) { + if ( abs( crvArc.GetDeltaN()) > EPS_SMALL) { for ( size_t i = 0 ; i < vBiPnt.size() ; ++ i) { double dAngDeg ; if ( crvArc.CalcPointAngle( vBiPnt[i].second, dAngDeg)) diff --git a/LineTgTwoCurves.cpp b/LineTgTwoCurves.cpp index 155e344..bb690e8 100644 --- a/LineTgTwoCurves.cpp +++ b/LineTgTwoCurves.cpp @@ -132,7 +132,7 @@ GetLineTgLineArc( const CurveLine& crvLine1, const Point3d& ptNear1, // il centro deve distare dalla linea quanto il raggio DistPointLine dstPL( ptCen, crvLine1, false) ; double dDist ; - if ( ! dstPL.GetDist( dDist) || fabs( dDist - crvArc2.GetRadius()) > EPS_SMALL) + if ( ! dstPL.GetDist( dDist) || abs( dDist - crvArc2.GetRadius()) > EPS_SMALL) return nullptr ; // sposto il punto sulla circonferenza e verifico appartenga all'arco Point3d ptP2 ; diff --git a/OffsetCurve.cpp b/OffsetCurve.cpp index 5ec0e76..ef8d708 100644 --- a/OffsetCurve.cpp +++ b/OffsetCurve.cpp @@ -228,19 +228,19 @@ OffsetCurve::Make( const ICurve* pCrv, double dDist, int nType) // calcolo la massima estensione di offset (Voronoi con entità adiacenti) double dMaxDist = INFINITO ; if ( bPrevInt && bNextInt) { - double dTgA = tan( 0.5 * ( ANG_STRAIGHT - fabs( vAngs[nInd1-1])) * DEGTORAD) ; - double dTgB = tan( 0.5 * ( ANG_STRAIGHT - fabs( vAngs[nInd1])) * DEGTORAD) ; + double dTgA = tan( 0.5 * ( ANG_STRAIGHT - abs( vAngs[nInd1-1])) * DEGTORAD) ; + double dTgB = tan( 0.5 * ( ANG_STRAIGHT - abs( vAngs[nInd1])) * DEGTORAD) ; dMaxDist = dTgA * dTgB / ( dTgA + dTgB) * vLens[nInd1-1] ; } else if ( bPrevInt) { - double dTgA = tan( 0.5 * ( ANG_STRAIGHT - fabs( vAngs[nInd1-1])) * DEGTORAD) ; + double dTgA = tan( 0.5 * ( ANG_STRAIGHT - abs( vAngs[nInd1-1])) * DEGTORAD) ; dMaxDist = dTgA * vLens[nInd1-1] ; } else if ( bNextInt) { - double dTgB = tan( 0.5 * ( ANG_STRAIGHT - fabs( vAngs[nInd1])) * DEGTORAD) ; + double dTgB = tan( 0.5 * ( ANG_STRAIGHT - abs( vAngs[nInd1])) * DEGTORAD) ; dMaxDist = dTgB * vLens[nInd1-1] ; } - if ( fabs( dDist) > dMaxDist + 5 * EPS_SMALL) { + if ( abs( dDist) > dMaxDist + 5 * EPS_SMALL) { delete pCrv ; iIter = m_CrvLst.erase( iIter) ; continue ; @@ -656,7 +656,7 @@ CalcAngle( const ICurve* pCrv1, const ICurve* pCrv2, double& dAngDeg) if ( ! vtDir1.GetAngleXY( vtDir2, dAngDeg)) return false ; // se vicino all'angolo piatto, si devono ricalcolare spostandosi un poco - if ( fabs( dAngDeg) > ( ANG_STRAIGHT - EPS_ANG_SMALL)) { + if ( abs( dAngDeg) > ( ANG_STRAIGHT - EPS_ANG_SMALL)) { // eseguo calcolo spostato double dU1 = 1 ; double dU2 = 0 ; @@ -750,18 +750,18 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dAngDeg, doub } // verifico sia angolo esterno (accetto se entità quasi esattamente sovrapposte) - if ( fabs( dAngDeg) < ( ANG_STRAIGHT - 10 * EPS_ANG_ZERO) && + if ( abs( dAngDeg) < ( ANG_STRAIGHT - 10 * EPS_ANG_ZERO) && ( ( dDist < 0 && dAngDeg > 0) || ( dDist > 0 && dAngDeg < 0))) return false ; // se l'angolo esterno supera il retto, offset extend diventa offset chamfer - if ( nType == ICurve::OFF_EXTEND && fabs( dAngDeg) > ANG_RIGHT + EPS_ANG_SMALL) + if ( nType == ICurve::OFF_EXTEND && abs( dAngDeg) > ANG_RIGHT + EPS_ANG_SMALL) nType = ICurve::OFF_CHAMFER ; // se angolo esterno molto piccolo, semplifico tutto const double SMALL_EXT_ANG = 1.0 ; - bool bAngSmall = ( fabs( dAngDeg) < SMALL_EXT_ANG) ; + bool bAngSmall = ( abs( dAngDeg) < SMALL_EXT_ANG) ; if ( bAngSmall) nType = ICurve::OFF_EXTEND ; @@ -784,7 +784,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dAngDeg, doub case ICurve::OFF_CHAMFER : { // lunghezza aggiuntiva in tangenza - double dLen = fabs( dDist) * tan( fabs( dAngDeg) / 4 * DEGTORAD) ; + double dLen = abs( dDist) * tan( abs( dAngDeg) / 4 * DEGTORAD) ; // punti di costruzione smusso Point3d ptP1, ptP1a, ptP2a, ptP2 ; if ( ! pCrv1->GetEndPoint( ptP1) || ! pCrv2->GetStartPoint( ptP2)) @@ -827,7 +827,7 @@ VerifyAndAdjustExternalAngle( ICurve* pCrv1, ICurve* pCrv2, double dAngDeg, doub case ICurve::OFF_EXTEND : { // lunghezza aggiuntiva in tangenza - double dLen = fabs( dDist) * tan( fabs( dAngDeg) / 2 * DEGTORAD) ; + double dLen = abs( dDist) * tan( abs( dAngDeg) / 2 * DEGTORAD) ; // punti di costruzione estensione Point3d ptP1, ptPc, ptP2 ; if ( ! pCrv1->GetEndPoint( ptP1) || ! pCrv2->GetStartPoint( ptP2)) @@ -885,7 +885,7 @@ IsFillet( ICurve* pCrv, double dDist) return false ; CurveArc* pArc = GetBasicCurveArc( pCrv) ; // deve avere raggio uguale alla distanza di offset - if ( fabs( pArc->GetRadius() - fabs( dDist)) > EPS_SMALL) + if ( abs( pArc->GetRadius() - abs( dDist)) > EPS_SMALL) return false ; // deve essere CCW se offset a destra e CW se offset a sinistra return ( pArc->GetAngCenter() * dDist > 0) ; @@ -907,12 +907,12 @@ ModifyFillet( ICurve* pCrv, double dDist, int nType, CurveComposite& ccAux) nType &= ( ICurve::OFF_FILLET | ICurve::OFF_CHAMFER | ICurve::OFF_EXTEND) ; // se l'angolo esterno supera il retto, offset extend diventa offset chamfer - if ( nType == ICurve::OFF_EXTEND && fabs( dAngDeg) > ANG_RIGHT + EPS_ANG_SMALL) + if ( nType == ICurve::OFF_EXTEND && abs( dAngDeg) > ANG_RIGHT + EPS_ANG_SMALL) nType = ICurve::OFF_CHAMFER ; // se angolo esterno molto piccolo, semplifico tutto const double SMALL_EXT_ANG = 1.0 ; - bool bAngSmall = ( fabs( dAngDeg) < SMALL_EXT_ANG) ; + bool bAngSmall = ( abs( dAngDeg) < SMALL_EXT_ANG) ; if ( bAngSmall) nType = ICurve::OFF_EXTEND ; @@ -920,7 +920,7 @@ ModifyFillet( ICurve* pCrv, double dDist, int nType, CurveComposite& ccAux) case ICurve::OFF_CHAMFER : { // lunghezza aggiuntiva in tangenza - double dLen = fabs( dDist) * tan( fabs( dAngDeg) / 4 * DEGTORAD) ; + double dLen = abs( dDist) * tan( abs( dAngDeg) / 4 * DEGTORAD) ; // punti di costruzione smusso Point3d ptP1, ptP1a, ptP2a, ptP2 ; if ( ! pArc->GetStartPoint( ptP1) || ! pArc->GetEndPoint( ptP2)) @@ -954,7 +954,7 @@ ModifyFillet( ICurve* pCrv, double dDist, int nType, CurveComposite& ccAux) case ICurve::OFF_EXTEND : { // lunghezza aggiuntiva in tangenza - double dLen = fabs( dDist) * tan( fabs( dAngDeg) / 2 * DEGTORAD) ; + double dLen = abs( dDist) * tan( abs( dAngDeg) / 2 * DEGTORAD) ; // punti di costruzione estensione Point3d ptP1, ptPc, ptP2 ; if ( ! pArc->GetStartPoint( ptP1) || ! pArc->GetEndPoint( ptP2)) diff --git a/OutTsc.cpp b/OutTsc.cpp index 4941432..977e9b2 100644 --- a/OutTsc.cpp +++ b/OutTsc.cpp @@ -335,7 +335,7 @@ OutTsc::ArcCPA( const Point3d& ptCen, const Point3d& ptMed, double dAngCenDeg) dAngIniDeg -= 0.5 * dAngCenDeg ; // verifico non sia praticamente nulla - if ( fabs( dRad) < EPS_SMALL || fabs( dAngCenDeg) < EPS_ANG_SMALL) + if ( abs( dRad) < EPS_SMALL || abs( dAngCenDeg) < EPS_ANG_SMALL) return true ; // incremento indice corrente @@ -378,7 +378,7 @@ bool OutTsc::ArcCurvOrTgOrNone( const CrvPointDiffGeom& oDiffG) { // curvatura - if ( oDiffG.nStatus == CrvPointDiffGeom::NCRV && fabs( oDiffG.dCurv) > EPS_ZERO) { + if ( oDiffG.nStatus == CrvPointDiffGeom::NCRV && abs( oDiffG.dCurv) > EPS_ZERO) { // tratto di arco Point3d ptCen = oDiffG.ptP + oDiffG.vtN / oDiffG.dCurv ; bool bCCW = ( oDiffG.vtT ^ oDiffG.vtN).z > 0 ; @@ -405,7 +405,7 @@ OutTsc::NormalOrNone( const CrvPointDiffGeom& oDiffG) // normale - if ( oDiffG.nStatus == CrvPointDiffGeom::NCRV && fabs( oDiffG.dCurv) > EPS_ZERO) { + if ( oDiffG.nStatus == CrvPointDiffGeom::NCRV && abs( oDiffG.dCurv) > EPS_ZERO) { double dLen = min( NORM_LEN, 1 / oDiffG.dCurv) ; Line2P( oDiffG.ptP - NORM_LEN * oDiffG.vtN, oDiffG.ptP + dLen * oDiffG.vtN) ; } diff --git a/PointGrid3d.cpp b/PointGrid3d.cpp index 6b360c9..a01cde1 100644 --- a/PointGrid3d.cpp +++ b/PointGrid3d.cpp @@ -268,7 +268,7 @@ PointGrid3d::FindNearest( const Point3d& ptTest, INTVECTOR& vnIds) const // quadrato della distanza double dSqDist = SqDist( ptTest, PntI.second.first) ; // altro punto con la stessa minima distanza già trovata - if ( bFound && fabs( dSqDist - dSqMinDist) < 2 * dMinDist * NEAR_TOL + NEAR_TOL * NEAR_TOL) { + if ( bFound && abs( dSqDist - dSqMinDist) < 2 * dMinDist * NEAR_TOL + NEAR_TOL * NEAR_TOL) { // inserisco il punto nel vettore dei risultati vnIds.push_back( PntI.second.second) ; } @@ -322,7 +322,7 @@ PointGrid3d::FindNearest( const Point3d& ptTest, INTVECTOR& vnIds) const // se distanza inferiore al minimo, aggiorno... double dSqDist = SqDist( (*MMrange.first).second.first, ptTest) ; // altro punto con la stessa minima distanza già trovata - if ( bFound && fabs( dSqDist - dSqMinDist) < 2 * dMinDist * NEAR_TOL + NEAR_TOL * NEAR_TOL) { + if ( bFound && abs( dSqDist - dSqMinDist) < 2 * dMinDist * NEAR_TOL + NEAR_TOL * NEAR_TOL) { // inserisco il punto nel vettore dei risultati vnIds.push_back( (*MMrange.first).second.second) ; } diff --git a/PointsPCA.cpp b/PointsPCA.cpp index 6b99f13..9d51956 100644 --- a/PointsPCA.cpp +++ b/PointsPCA.cpp @@ -89,33 +89,33 @@ PointsPCA::Finalize( void) int j = ( i + 1) % 3 ; int k = ( i + 2) % 3 ; // se l'autovalore corrente è il più grande in modulo - if ( fabs( es.eigenvalues()(i)) >= fabs( es.eigenvalues()(j)) && - fabs( es.eigenvalues()(i)) >= fabs( es.eigenvalues()(k)) && - fabs( es.eigenvalues()(i)) > SQ_EPS_SMALL) { + if ( abs( es.eigenvalues()(i)) >= abs( es.eigenvalues()(j)) && + abs( es.eigenvalues()(i)) >= abs( es.eigenvalues()(k)) && + abs( es.eigenvalues()(i)) > SQ_EPS_SMALL) { // il suo autovettore è il primo ++ m_nRank ; m_vtPC[0].Set( es.eigenvectors()(0,i), es.eigenvectors()(1,i), es.eigenvectors()(2,i)) ; // se il successivo autovalore è maggiore del rimanente in modulo - if ( fabs( es.eigenvalues()(j)) >= fabs(es.eigenvalues()(k)) && - fabs( es.eigenvalues()(j)) > SQ_EPS_SMALL) { + if ( abs( es.eigenvalues()(j)) >= abs(es.eigenvalues()(k)) && + abs( es.eigenvalues()(j)) > SQ_EPS_SMALL) { // il suo autovettore è il secondo ++ m_nRank ; m_vtPC[1].Set( es.eigenvectors()(0,j), es.eigenvectors()(1,j), es.eigenvectors()(2,j)) ; // se il rimanente autovalore è non nullo - if ( fabs( es.eigenvalues()(k)) > SQ_EPS_SMALL) { + if ( abs( es.eigenvalues()(k)) > SQ_EPS_SMALL) { // il suo autovettore è il terzo ++ m_nRank ; m_vtPC[2].Set( es.eigenvectors()(0,k), es.eigenvectors()(1,k), es.eigenvectors()(2,k)) ; } } // altrimenti, se il rimanente autovalore è maggiore del successivo in modulo - else if ( fabs( es.eigenvalues()(k)) >= fabs( es.eigenvalues()(j)) && - fabs( es.eigenvalues()(k)) > SQ_EPS_SMALL) { + else if ( abs( es.eigenvalues()(k)) >= abs( es.eigenvalues()(j)) && + abs( es.eigenvalues()(k)) > SQ_EPS_SMALL) { // il suo autovettore è il secondo ++ m_nRank ; m_vtPC[1].Set( es.eigenvectors()(0,k), es.eigenvectors()(1,k), es.eigenvectors()(2,k)) ; // se il rimanente autovalore è non nullo - if ( fabs( es.eigenvalues()(j)) > SQ_EPS_SMALL) { + if ( abs( es.eigenvalues()(j)) > SQ_EPS_SMALL) { // il suo autovettore è il terzo ++ m_nRank ; m_vtPC[2].Set( es.eigenvectors()(0,j), es.eigenvectors()(1,j), es.eigenvectors()(2,j)) ; diff --git a/PolyArc.cpp b/PolyArc.cpp index d330054..603a162 100644 --- a/PolyArc.cpp +++ b/PolyArc.cpp @@ -165,9 +165,9 @@ PolyArc::ParamLinearTransform( double dStartU, double dEndU) double dOriEndU = m_lUPointBs.back().dU ; // determino i coefficienti di riparametrizzazione double dCoeff ; - if ( fabs( dEndU - dStartU) < EPS_PARAM) + if ( abs( dEndU - dStartU) < EPS_PARAM) dCoeff = 0 ; - else if ( fabs( dOriEndU - dOriStartU) > EPS_PARAM) + else if ( abs( dOriEndU - dOriStartU) > EPS_PARAM) dCoeff = ( dEndU - dStartU) / ( dOriEndU - dOriStartU) ; else return false ; @@ -303,7 +303,7 @@ PolyArc::Join( PolyArc& PA, double dOffsetPar) // cancello l'ultimo di questo EraseLastUPoint() ; // aggiungo eventuale offset all'altro - if ( fabs( dOffsetPar) > EPS_PARAM) + if ( abs( dOffsetPar) > EPS_PARAM) PA.AddOffsetToU( dOffsetPar) ; // sposto i punti dall'altra polilinea a questa e aggiorno i contatori m_lUPointBs.splice( m_lUPointBs.end(), PA.m_lUPointBs) ; @@ -473,7 +473,7 @@ PolyArc::IsFlat( int& nRank, Point3d& ptCen, Vector3d& vtDir, double dToler) con nRank += 2 ; } // se la componente parallela è non nulla, punto non nel piano - if ( fabs( dPar) > dToler) { + if ( abs( dPar) > dToler) { if ( nRank == 0 || nRank == 2) nRank += 1 ; } diff --git a/PolyLine.cpp b/PolyLine.cpp index 4a755b0..135aabc 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -233,7 +233,7 @@ PolyLine::Join( PolyLine& PL, double dOffsetPar) // cancello l'ultimo di questa EraseLastUPoint() ; // aggiungo eventuale offset all'altra - if ( fabs( dOffsetPar) > EPS_PARAM) + if ( abs( dOffsetPar) > EPS_PARAM) PL.AddOffsetToU( dOffsetPar) ; // sposto i punti dall'altra polilinea a questa m_lUPoints.splice( m_lUPoints.end(), PL.m_lUPoints) ; @@ -533,7 +533,7 @@ PolyLine::IsFlat( int& nRank, Point3d& ptCen, Vector3d& vtDir, double dToler) co // Test each vertex to see if it is farther from plane than allowed max distance for ( bool bFound = GetFirstPoint( ptP) ; bFound ; bFound = GetNextPoint( ptP)) { double dDist = ( ( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist() ; - if ( fabs( dDist) > dToler) + if ( abs( dDist) > dToler) return false ; } return true ; @@ -556,7 +556,7 @@ PolyLine::IsClosedAndFlat( Plane3d& plPlane, double& dArea, double dToler) const // Test each vertex to see if it is farther from plane than allowed max distance for ( bool bFound = GetFirstPoint( ptP) ; bFound ; bFound = GetNextPoint( ptP)) { double dDist = ( ( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist() ; - if ( fabs( dDist) > dToler) + if ( abs( dDist) > dToler) return false ; } // All points passed distance test, so polygon is considered planar diff --git a/Polygon3d.cpp b/Polygon3d.cpp index 8f78ab8..515ab78 100644 --- a/Polygon3d.cpp +++ b/Polygon3d.cpp @@ -128,7 +128,7 @@ Polygon3d::Trim( const Plane3d& plPlane, bool bInVsOut, bool bOnEq) // verifico se il poligono giace nel piano bool bOnPlane = true ; for ( auto& dDist : vDist) { - if ( fabs( dDist) > EPS_SMALL) + if ( abs( dDist) > EPS_SMALL) bOnPlane = false ; } if ( bOnPlane) { @@ -145,7 +145,7 @@ Polygon3d::Trim( const Plane3d& plPlane, bool bInVsOut, bool bOnEq) // se il lato attraversa il piano, inserisco il punto di intersezione nel poligono if ( ( vDist[i] > EPS_SMALL && vDist[j] < - EPS_SMALL) || ( vDist[i] < - EPS_SMALL && vDist[j] > EPS_SMALL)) { - double dCoeff = fabs( vDist[i]) / ( fabs( vDist[i]) + fabs( vDist[j])) ; + double dCoeff = abs( vDist[i]) / ( abs( vDist[i]) + abs( vDist[j])) ; Point3d ptInt = Media( m_vVert[i], m_vVert[j], dCoeff) ; m_vVert.insert( m_vVert.begin() + i + 1, ptInt) ; vDist.insert( vDist.begin() + i + 1, 0.0) ; @@ -166,7 +166,7 @@ Polygon3d::Trim( const Plane3d& plPlane, bool bInVsOut, bool bOnEq) // se i punti rimasti giacciono tutti sul piano (quindi su una linea), annullo il poligono bool bIsLine = true ; for ( auto& dDist : vDist) { - if ( fabs( dDist) > EPS_SMALL) + if ( abs( dDist) > EPS_SMALL) bIsLine = false ; } if ( bIsLine) @@ -228,7 +228,7 @@ bool Polygon3d::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) { // verifico validità della scalatura - if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO) + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; // scalo il piano if ( ! m_Plane.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ)) diff --git a/PolygonPlane.cpp b/PolygonPlane.cpp index 73ed98e..5e3564b 100644 --- a/PolygonPlane.cpp +++ b/PolygonPlane.cpp @@ -90,14 +90,14 @@ PolygonPlane::GetCentroid( Point3d& ptCen) if ( ! Finalize()) return false ; // assegno i dati del centro geometrico - if ( fabs( m_vtN.z) > fabs( m_vtN.x) && - fabs( m_vtN.z) > fabs( m_vtN.y)) { + if ( abs( m_vtN.z) > abs( m_vtN.x) && + abs( m_vtN.z) > abs( m_vtN.y)) { // calcoli nel piano xy perpendicolare a Z ptCen.x = m_dSZx / ( 3 * m_vtN.z * m_dLenN) ; ptCen.y = m_dSZy / ( 3 * m_vtN.z * m_dLenN) ; ptCen.z = (( m_ptMid.x - ptCen.x) * m_vtN.x + ( m_ptMid.y - ptCen.y) * m_vtN.y + m_ptMid.z * m_vtN.z) / m_vtN.z ; } - else if ( fabs( m_vtN.x) > fabs( m_vtN.y)) { + else if ( abs( m_vtN.x) > abs( m_vtN.y)) { // calcoli nel piano yz perpendicolare a X ptCen.y = m_dSXy / ( 3 * m_vtN.x * m_dLenN) ; ptCen.z = m_dSXz / ( 3 * m_vtN.x * m_dLenN) ; diff --git a/PolynomialPoint3d.cpp b/PolynomialPoint3d.cpp index 6520dd5..743da65 100644 --- a/PolynomialPoint3d.cpp +++ b/PolynomialPoint3d.cpp @@ -170,9 +170,9 @@ PolynomialPoint3d::AdjustDegree( void) { // se il coefficiente del grado più alto è zero, diminuisco il grado while ( m_nDegree >= 0 && - fabs( m_Coeff[m_nDegree].x) < DBL_EPSILON && - fabs( m_Coeff[m_nDegree].y) < DBL_EPSILON && - fabs( m_Coeff[m_nDegree].z) < DBL_EPSILON) { + abs( m_Coeff[m_nDegree].x) < DBL_EPSILON && + abs( m_Coeff[m_nDegree].y) < DBL_EPSILON && + abs( m_Coeff[m_nDegree].z) < DBL_EPSILON) { m_Coeff.pop_back() ; -- m_nDegree ; } @@ -200,9 +200,9 @@ PolynomialPoint3d::FindMainComponentRoots( DBLVECTOR& vdRoot) // cerco la componente più significativa tra x, y e z Point3d ptSumm ; for ( int i = 0 ; i <= m_nDegree ; ++ i) { - ptSumm.x += fabs( m_Coeff[i].x) ; - ptSumm.y += fabs( m_Coeff[i].y) ; - ptSumm.z += fabs( m_Coeff[i].z) ; + ptSumm.x += abs( m_Coeff[i].x) ; + ptSumm.y += abs( m_Coeff[i].y) ; + ptSumm.z += abs( m_Coeff[i].z) ; } // la copio in un polinomio numerico Polynomial polP ; diff --git a/ProjPlane.h b/ProjPlane.h index e90f5f2..60b5050 100644 --- a/ProjPlane.h +++ b/ProjPlane.h @@ -117,22 +117,22 @@ PointInTria( const Point3d& ptP, const Triangle3d& Tria) double dPosBC = TwoAreaInPlane( nPlane, ptP, Tria.GetP( 1), Tria.GetP( 2)) / dLenBC ; double dPosCA = TwoAreaInPlane( nPlane, ptP, Tria.GetP( 2), Tria.GetP( 0)) / dLenCA ; // se tre valori nulli, triangolo non definito correttamente - if ( fabs( dPosAB) < EPS_SMALL && fabs( dPosBC) < EPS_SMALL && fabs( dPosCA) < EPS_SMALL) + if ( abs( dPosAB) < EPS_SMALL && abs( dPosBC) < EPS_SMALL && abs( dPosCA) < EPS_SMALL) return PTT_OUT ; // se un valore nullo e gli altri due con lo stesso segno - if ( fabs( dPosAB) < EPS_SMALL && ( dPosBC * dPosCA) > 0) { + if ( abs( dPosAB) < EPS_SMALL && ( dPosBC * dPosCA) > 0) { // se la proiezione del punto sta sul lato AB double dPro = ProScaInPlane( nPlane, ptP, Tria.GetP( 0), Tria.GetP( 1)) / dLenAB ; if ( dPro > 0 && dPro < dLenAB) return PTT_EDGE ; } - if ( fabs( dPosBC) < EPS_SMALL && ( dPosCA * dPosAB) > 0) { + if ( abs( dPosBC) < EPS_SMALL && ( dPosCA * dPosAB) > 0) { // se la proiezione del punto sta sul lato BC double dPro = ProScaInPlane( nPlane, ptP, Tria.GetP( 1), Tria.GetP( 2)) / dLenBC ; if ( dPro > 0 && dPro < dLenBC) return PTT_EDGE ; } - if ( fabs( dPosCA) < EPS_SMALL && ( dPosAB * dPosBC) > 0) { + if ( abs( dPosCA) < EPS_SMALL && ( dPosAB * dPosBC) > 0) { // se la proiezione del punto sta sul lato CA double dPro = ProScaInPlane( nPlane, ptP, Tria.GetP( 2), Tria.GetP( 0)) / dLenCA ; if ( dPro > 0 && dPro < dLenCA) diff --git a/SelfIntersCurve.cpp b/SelfIntersCurve.cpp index 880741b..0ef0b40 100644 --- a/SelfIntersCurve.cpp +++ b/SelfIntersCurve.cpp @@ -103,7 +103,7 @@ SelfIntersCurve::IsArcToApprox( const ICurve& Curve) return false ; // verifico se non è nel piano XY o ha più di un giro al centro return ( ( ! pArc->GetNormVersor().IsZplus() && ! pArc->GetNormVersor().IsZminus()) || - fabs( pArc->GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) ; + abs( pArc->GetAngCenter()) > ANG_FULL + EPS_ANG_ZERO) ; } //---------------------------------------------------------------------------- diff --git a/SfrCreate.cpp b/SfrCreate.cpp index 6a4e091..752d7a0 100644 --- a/SfrCreate.cpp +++ b/SfrCreate.cpp @@ -59,7 +59,7 @@ GetSurfFlatRegionStadium( double dWidth, double dLen) if ( dWidth < EPS_SMALL || dLen < EPS_SMALL) return nullptr ; // se dimensioni praticamente uguali, è un disco - if ( fabs( dWidth - dLen) < 10 * EPS_SMALL) + if ( abs( dWidth - dLen) < 10 * EPS_SMALL) return GetSurfFlatRegionDisk( ( dWidth + dLen) / 4) ; // creo il contorno PolyArc PA ; @@ -328,7 +328,7 @@ SurfFlatRegionByContours::Prepare( void) } // ordino in senso decrescente sull'area sort( m_vArea.begin(), m_vArea.end(), - []( const INDAREA& a, const INDAREA& b) { return ( fabs( a.second) > fabs( b.second)) ; }) ; + []( const INDAREA& a, const INDAREA& b) { return ( abs( a.second) > abs( b.second)) ; }) ; return true ; } diff --git a/StmFromCurves.cpp b/StmFromCurves.cpp index 1bbe8c5..6be3d84 100644 --- a/StmFromCurves.cpp +++ b/StmFromCurves.cpp @@ -88,7 +88,7 @@ GetSurfTriMeshByExtrusion( const ICurve* pCurve, const Vector3d& vtExtr, if ( PL.IsClosedAndFlat( plPlane, dArea, 50 * EPS_SMALL)) { // componente dell'estrusione perpendicolare al piano della curva double dOrthoExtr = plPlane.GetVersN() * vtExtr ; - if ( ( fabs( dOrthoExtr) > EPS_SMALL)) { + if ( ( abs( dOrthoExtr) > EPS_SMALL)) { bDoCapEnds = true ; // se negativa, inverto il senso del contorno if ( dOrthoExtr < 0) @@ -141,7 +141,7 @@ GetSurfTriMeshByRegionExtrusion( const CICURVEPVECTOR& vpCurve, const Vector3d& return nullptr ; // verifico la direzione di estrusione double dOrthoExtr = vtN * vtExtr ; - if ( ( fabs( dOrthoExtr) < EPS_SMALL)) + if ( ( abs( dOrthoExtr) < EPS_SMALL)) return nullptr ; // se componente estrusione negativa, inverto tutti i percorsi if ( dOrthoExtr < 0) { @@ -267,8 +267,8 @@ GetSurfTriMeshByScrewing( const ICurve* pCurve, const Point3d& ptAx, const Vecto return nullptr ; double dStepRotDeg = sqrt( 8 * dLinTol / dMaxRad) * RADTODEG ; // se superficie rototraslata, necessari limiti sulla lunghezza dei segmenti - if ( fabs( dAngRotDeg) > EPS_ANG_SMALL && fabs( dMove) > EPS_SMALL){ - double dLenMax = 2.5 * fabs( dMove * dStepRotDeg / dAngRotDeg) ; + if ( abs( dAngRotDeg) > EPS_ANG_SMALL && abs( dMove) > EPS_SMALL){ + double dLenMax = 2.5 * abs( dMove * dStepRotDeg / dAngRotDeg) ; if ( ! PL.AdjustForMaxSegmentLen( dLenMax)) return nullptr ; } @@ -365,7 +365,7 @@ CalcRegionPolyLines( const CICURVEPVECTOR& vpCurve, double dLinTol, vArea.emplace_back( i, - dArea) ; } sort( vArea.begin(), vArea.end(), - []( const INDAREA& a, const INDAREA& b) { return ( fabs( a.second) > fabs( b.second)) ; }) ; + []( const INDAREA& a, const INDAREA& b) { return ( abs( a.second) > abs( b.second)) ; }) ; // sposto le polilinee nel vettore da restituire secondo l'ordine vPL.clear() ; vPL.resize( vPLtmp.size()) ; diff --git a/StmStandard.cpp b/StmStandard.cpp index 4031eb3..b32142e 100644 --- a/StmStandard.cpp +++ b/StmStandard.cpp @@ -26,7 +26,7 @@ ISurfTriMesh* GetSurfTriMeshBox( double dDimX, double dDimY, double dHeight) { // le dimensioni devono essere significative - if ( dDimX < EPS_SMALL || dDimY < EPS_SMALL || fabs( dHeight) < EPS_SMALL) + if ( dDimX < EPS_SMALL || dDimY < EPS_SMALL || abs( dHeight) < EPS_SMALL) return nullptr ; // creo la polilinea del contorno della base PolyLine PL ; @@ -67,7 +67,7 @@ ISurfTriMesh* GetSurfTriMeshPyramid( double dDimX, double dDimY, double dHeight) { // le dimensioni devono essere significative - if ( dDimX < EPS_SMALL || dDimY < EPS_SMALL || fabs( dHeight) < EPS_SMALL) + if ( dDimX < EPS_SMALL || dDimY < EPS_SMALL || abs( dHeight) < EPS_SMALL) return nullptr ; // creo la polilinea del contorno della base PolyLine PL ; @@ -101,7 +101,7 @@ ISurfTriMesh* GetSurfTriMeshCylinder( double dRadius, double dHeight, double dLinTol) { // le dimensioni devono essere significative - if ( dRadius < EPS_SMALL || fabs( dHeight) < EPS_SMALL) + if ( dRadius < EPS_SMALL || abs( dHeight) < EPS_SMALL) return nullptr ; // creo la circonferenza di base CurveArc cArc ; @@ -117,7 +117,7 @@ ISurfTriMesh* GetSurfTriMeshCone( double dRadius, double dHeight, double dLinTol) { // le dimensioni devono essere significative - if ( dRadius < EPS_SMALL || fabs( dHeight) < EPS_SMALL) + if ( dRadius < EPS_SMALL || abs( dHeight) < EPS_SMALL) return nullptr ; // creo la circonferenza di base CurveArc cArc ; diff --git a/SurfFlatRegion.cpp b/SurfFlatRegion.cpp index 15990d3..d00372b 100644 --- a/SurfFlatRegion.cpp +++ b/SurfFlatRegion.cpp @@ -142,7 +142,7 @@ SurfFlatRegion::AddSimpleExtLoop( ICurve* pCrv) else { // verifico che il piano della curva coincida con quello XY intrinseco plPlane.ToLoc( m_frF) ; - if ( ! ( plPlane.GetVersN().IsZplus() || plPlane.GetVersN().IsZminus()) || fabs( plPlane.GetDist()) > EPS_SMALL) + if ( ! ( plPlane.GetVersN().IsZplus() || plPlane.GetVersN().IsZminus()) || abs( plPlane.GetDist()) > EPS_SMALL) return false ; // sistemo il senso di rotazione (deve essere CCW -> area > 0) if ( ( plPlane.GetVersN().IsZplus() && dArea < 0) || @@ -284,7 +284,7 @@ SurfFlatRegion::AddSimpleIntLoop( ICurve* pCrv) Plane3d plPlane ; if ( ! pMyCrv->GetArea( plPlane, dArea)) return false ; - if ( ! ( plPlane.GetVersN().IsZplus() || plPlane.GetVersN().IsZminus()) || fabs( plPlane.GetDist()) > EPS_SMALL) + if ( ! ( plPlane.GetVersN().IsZplus() || plPlane.GetVersN().IsZminus()) || abs( plPlane.GetDist()) > EPS_SMALL) return false ; // sistemo il senso di rotazione (deve essere CW -> se N==Z+ area < 0, se N==Z- area>0) if ( ( plPlane.GetVersN().IsZplus() && dArea > 0) || ( plPlane.GetVersN().IsZminus() && dArea < 0)) @@ -610,7 +610,7 @@ SurfFlatRegion::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, dou m_OGrMgr.Reset() ; // se scalatura non uniforme, sostituisco eventuali archi con curve di Bezier - if ( fabs( dCoeffX - dCoeffY) > EPS_SMALL || fabs( dCoeffX - dCoeffZ) > EPS_SMALL) { + if ( abs( dCoeffX - dCoeffY) > EPS_SMALL || abs( dCoeffX - dCoeffZ) > EPS_SMALL) { if ( ! ConvertArcsToBezierCurves()) return false ; } diff --git a/SurfFlatRegionBooleans.cpp b/SurfFlatRegionBooleans.cpp index 19e7a35..c658c10 100644 --- a/SurfFlatRegionBooleans.cpp +++ b/SurfFlatRegionBooleans.cpp @@ -432,7 +432,7 @@ SurfFlatRegion::MyNewSurfFromLoops( PCRV_DEQUE& vpLoop) if ( vArea[k].first < 0) continue ; // salto gli interni con area maggiore dell'esterno corrente - if ( fabs( vArea[k].second) > dExtArea) + if ( abs( vArea[k].second) > dExtArea) continue ; int l = vArea[k].first ; // verifico che sia interno all'esterno corrente diff --git a/SurfTriMesh.cpp b/SurfTriMesh.cpp index 2cdc31d..1cdce68 100644 --- a/SurfTriMesh.cpp +++ b/SurfTriMesh.cpp @@ -315,7 +315,7 @@ SurfTriMesh::GetCentroid( Point3d& ptCen) const nId = GetNextTriangle( nId, Tria) ; } dVolume /= 6 ; - if ( fabs( dVolume) < EPS_SMALL * EPS_SMALL * EPS_SMALL) + if ( abs( dVolume) < EPS_SMALL * EPS_SMALL * EPS_SMALL) return false ; ptCen /= ( 24 * 2 * dVolume) ; } @@ -330,7 +330,7 @@ SurfTriMesh::GetCentroid( Point3d& ptCen) const ptCen += Tria.GetCentroid() * dTriaArea ; nId = GetNextTriangle( nId, Tria) ; } - if ( fabs( dArea) < SQ_EPS_SMALL) + if ( abs( dArea) < SQ_EPS_SMALL) return false ; ptCen /= dArea ; } @@ -2064,20 +2064,20 @@ SurfTriMesh::CreateByScrewing( const PolyLine& PL, const Point3d& ptAx, const Ve if ( vtAx.IsSmall()) return false ; // verifico se solo rivoluzione - bool bOnlyRev = ( fabs( dMove) < EPS_SMALL) ; + bool bOnlyRev = ( abs( dMove) < EPS_SMALL) ; // verifico che l'angolo di rotazione sia significativo e, se solo rivoluzione, non superi un giro - if ( fabs( dAngRot) < EPS_ANG_SMALL) + if ( abs( dAngRot) < EPS_ANG_SMALL) return false ; - if ( bOnlyRev && fabs( dAngRot) > ANG_FULL) + if ( bOnlyRev && abs( dAngRot) > ANG_FULL) dAngRot = _copysign( ANG_FULL, dAngRot) ; // verifico se rotazione completa - bool bFullRev = bOnlyRev && ( fabs( fabs( dAngRot) - ANG_FULL) < EPS_ANG_SMALL) ; + bool bFullRev = bOnlyRev && ( abs( abs( dAngRot) - ANG_FULL) < EPS_ANG_SMALL) ; // aggiusto il valore dell'angolo di step const double MIN_STEP_ROT = 1 ; const double MAX_STEP_ROT = 90 ; - if ( fabs( dStepRot) < MIN_STEP_ROT) + if ( abs( dStepRot) < MIN_STEP_ROT) dStepRot = _copysign( MIN_STEP_ROT, dAngRot) ; - else if ( fabs( dStepRot) > MAX_STEP_ROT) + else if ( abs( dStepRot) > MAX_STEP_ROT) dStepRot = _copysign( MAX_STEP_ROT, dAngRot) ; else dStepRot = _copysign( dStepRot, dAngRot) ; @@ -2604,7 +2604,7 @@ SurfTriMesh::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double return false ; // verifico non sia nulla - if ( fabs( dCoeffX) < EPS_ZERO && fabs( dCoeffY) < EPS_ZERO && fabs( dCoeffZ) < EPS_ZERO) + if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; // calcolo bbox allineato con riferimento di scalatura e senza tener conto dello spessore @@ -2613,9 +2613,9 @@ SurfTriMesh::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double if ( ! GetBBox( frRef, b3Ref)) return false ; Vector3d vtDelta = b3Ref.GetMax() - b3Ref.GetMin() ; - bool bZeroX = ( fabs( vtDelta.x * dCoeffX) < EPS_SMALL) ; - bool bZeroY = ( fabs( vtDelta.y * dCoeffY) < EPS_SMALL) ; - bool bZeroZ = ( fabs( vtDelta.z * dCoeffZ) < EPS_SMALL) ; + bool bZeroX = ( abs( vtDelta.x * dCoeffX) < EPS_SMALL) ; + bool bZeroY = ( abs( vtDelta.y * dCoeffY) < EPS_SMALL) ; + bool bZeroZ = ( abs( vtDelta.z * dCoeffZ) < EPS_SMALL) ; if ( ( bZeroX && bZeroY) || ( bZeroX && bZeroZ) || ( bZeroY && bZeroZ)) return false ; @@ -2635,7 +2635,7 @@ SurfTriMesh::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double bMirror = ( bMirror ? ( dCoeffZ > 0) : ( dCoeffZ < 0)) ; // aggiorno le facce - bool bRecalc = ( fabs( dCoeffX) < EPS_ZERO || fabs( dCoeffY) < EPS_ZERO || fabs( dCoeffZ) < EPS_ZERO) ; + bool bRecalc = ( abs( dCoeffX) < EPS_ZERO || abs( dCoeffY) < EPS_ZERO || abs( dCoeffZ) < EPS_ZERO) ; for ( int i = 0 ; i < GetTriangleSize() ; ++ i) { if ( m_vTria[i].nIdVert[0] != SVT_DEL) { // se c'è mirror, devo invertire la faccia diff --git a/SurfTriMeshFaceting.cpp b/SurfTriMeshFaceting.cpp index 524513e..ea67f31 100644 --- a/SurfTriMeshFaceting.cpp +++ b/SurfTriMeshFaceting.cpp @@ -17,6 +17,7 @@ #include "GeoConst.h" #include "PolygonPlane.h" #include "/EgtDev/Include/EgtPointerOwner.h" +#include #include using namespace std ; @@ -50,27 +51,38 @@ SurfTriMesh::UpdateFaceting( void) // ricostruisco le sfaccettature bool bOk = true ; - int nFacet = 0 ; + int nFacet = -1 ; for ( int i = 0 ; i < int( m_vTria.size()) ; ++ i) { if ( m_vTria[i].nIdVert[0] != SVT_DEL && m_vTria[i].nIdFacet == SVT_NULL) { // assegno indice di faccia al triangolo - m_vTria[i].nIdFacet = nFacet ; + m_vTria[i].nIdFacet = ++ nFacet ; m_vFacet.push_back( i) ; - ++ nFacet ; // piano del triangolo Plane3d plPlane ; if ( ! plPlane.Set( m_vVert[m_vTria[i].nIdVert[0]].ptP, m_vTria[i].vtN)) { LOG_ERROR( GetEGkLogger(), "SurfTM : UpdateFaceting error in triangle data") return false ; } - // aggiorno i triangoli adiacenti - for ( int j = 0 ; j < 3 ; ++ j) { - int nAdjT = m_vTria[i].nIdAdjac[j] ; - if ( nAdjT != SVT_NULL && - m_vTria[nAdjT].nIdFacet == SVT_NULL) { - if ( ! UpdateTriaFaceting( i, m_vTria[i].nIdFacet, plPlane, nAdjT)) - bOk = false ; + // set di triangoli da aggiornare + set stTria ; + stTria.insert( i) ; + // finchè set non vuoto + while ( ! stTria.empty()) { + // tolgo un triangolo dal set + const auto iIt = stTria.begin() ; + int nT = *iIt ; + stTria.erase( iIt) ; + // aggiorno i triangoli adiacenti + for ( int j = 0 ; j < 3 ; ++ j) { + int nAdjT = m_vTria[nT].nIdAdjac[j] ; + if ( nAdjT != SVT_NULL && + m_vTria[nAdjT].nIdFacet == SVT_NULL) { + if ( ! UpdateTriaFaceting( nT, nFacet, plPlane, nAdjT)) + bOk = false ; + if ( m_vTria[nAdjT].nIdFacet == nFacet) + stTria.insert( nAdjT) ; + } } } } @@ -106,17 +118,7 @@ SurfTriMesh::UpdateTriaFaceting( int nRefT, int nFacet, const Plane3d& plPlane, return true ; // il triangolo fa parte della faccia m_vTria[nT].nIdFacet = nFacet ; - // aggiorno i triangoli adiacenti - bool bOk = true ; - for ( int j = 0 ; j < 3 ; ++ j) { - int nAdjT = m_vTria[nT].nIdAdjac[j] ; - if ( nAdjT != SVT_NULL && - m_vTria[nAdjT].nIdFacet == SVT_NULL) { - if ( ! UpdateTriaFaceting( nT, nFacet, plPlane, nAdjT)) - bOk = false ; - } - } - return bOk ; + return true ; } //---------------------------------------------------------------------------- diff --git a/Triangulate.cpp b/Triangulate.cpp index 8b75c29..7c851c2 100644 --- a/Triangulate.cpp +++ b/Triangulate.cpp @@ -582,7 +582,7 @@ Triangulate::CalcTriangleAspectRatio( const Point3d& ptPa, const Point3d& ptPb, double dSqDistA = SquareDist( ptPa, ptPb) ; double dSqDistB = SquareDist( ptPb, ptPc) ; double dSqDistC = SquareDist( ptPc, ptPa) ; - double dTwoArea = fabs( TwoArea( ptPa, ptPb, ptPc)) ; + double dTwoArea = abs( TwoArea( ptPa, ptPb, ptPc)) ; if ( dTwoArea < SQ_EPS_SMALL) return INFINITO ; else @@ -646,7 +646,7 @@ Triangulate::SameDirection( const Point3d& ptA, const Point3d& ptB, const Point3 bool Triangulate::Collinear( const Point3d& ptA, const Point3d& ptB, const Point3d& ptC, double dToler) { - return ( fabs( TwoArea( ptA, ptB, ptC)) < dToler * dToler) ; + return ( abs( TwoArea( ptA, ptB, ptC)) < dToler * dToler) ; } //---------------------------------------------------------------------------- @@ -796,13 +796,13 @@ Triangulate::GetOuterPntToJoin( const PNTVECTOR& vPt, const Point3d& ptP, int& n switch (m_nPlane) { default : // PL_XY // se i punti coincidono - if ( fabs( vPt[i].x - ptP.x) < EPS_SMALL && fabs( vPt[i].y - ptP.y) < EPS_SMALL) { + if ( abs( vPt[i].x - ptP.x) < EPS_SMALL && abs( vPt[i].y - ptP.y) < EPS_SMALL) { dMinDist = 0 ; nI = i ; ptInt = vPt[i] ; } // se punto esattamente sul raggio e raggio interno al settore - else if ( vPt[i].x > ptP.x && fabs( vPt[i].y - ptP.y) < EPS_SMALL && + else if ( vPt[i].x > ptP.x && abs( vPt[i].y - ptP.y) < EPS_SMALL && PointInSector( ptP, vPt[h], vPt[i], vPt[j])) { // se distanza minore della minima, nuovo minimo if ( ( vPt[i].x - ptP.x) < dMinDist) { @@ -827,13 +827,13 @@ Triangulate::GetOuterPntToJoin( const PNTVECTOR& vPt, const Point3d& ptP, int& n break ; case PL_YZ : // se i punti coincidono - if ( fabs( vPt[i].y - ptP.y) < EPS_SMALL && fabs( vPt[i].z - ptP.z) < EPS_SMALL) { + if ( abs( vPt[i].y - ptP.y) < EPS_SMALL && abs( vPt[i].z - ptP.z) < EPS_SMALL) { dMinDist = 0 ; nI = i ; ptInt = vPt[i] ; } // se punto esattamente sul raggio e raggio interno al settore - else if ( vPt[i].y > ptP.y && fabs( vPt[i].z - ptP.z) < EPS_SMALL && + else if ( vPt[i].y > ptP.y && abs( vPt[i].z - ptP.z) < EPS_SMALL && PointInSector( ptP, vPt[h], vPt[i], vPt[j])) { // se distanza minore della minima, nuovo minimo if ( ( vPt[i].y - ptP.y) < dMinDist) { @@ -858,13 +858,13 @@ Triangulate::GetOuterPntToJoin( const PNTVECTOR& vPt, const Point3d& ptP, int& n break ; case PL_ZX : // se i punti coincidono - if ( fabs( vPt[i].z - ptP.z) < EPS_SMALL && fabs( vPt[i].x - ptP.x) < EPS_SMALL) { + if ( abs( vPt[i].z - ptP.z) < EPS_SMALL && abs( vPt[i].x - ptP.x) < EPS_SMALL) { dMinDist = 0 ; nI = i ; ptInt = vPt[i] ; } // se punto esattamente sul raggio e raggio interno al settore - else if ( vPt[i].z > ptP.z && fabs( vPt[i].x - ptP.x) < EPS_SMALL && + else if ( vPt[i].z > ptP.z && abs( vPt[i].x - ptP.x) < EPS_SMALL && PointInSector( ptP, vPt[h], vPt[i], vPt[j])) { // se distanza minore della minima, nuovo minimo if ( ( vPt[i].z - ptP.z) < dMinDist) { @@ -919,9 +919,9 @@ Triangulate::GetOuterPntToJoin( const PNTVECTOR& vPt, const Point3d& ptP, int& n if ( TestPointInTriangle( vPt[i], ptPa, ptPb, ptPc)) { double dTan = INFINITO ; switch ( m_nPlane) { - default : /* PL_XY */ dTan = fabs(vPt[i].y - ptP.y) / (vPt[i].x - ptP.x) ; break ; - case PL_YZ : dTan = fabs(vPt[i].z - ptP.z) / (vPt[i].y - ptP.y) ; break ; - case PL_ZX : dTan = fabs(vPt[i].x - ptP.x) / (vPt[i].z - ptP.z) ; break ; + default : /* PL_XY */ dTan = abs(vPt[i].y - ptP.y) / (vPt[i].x - ptP.x) ; break ; + case PL_YZ : dTan = abs(vPt[i].z - ptP.z) / (vPt[i].y - ptP.y) ; break ; + case PL_ZX : dTan = abs(vPt[i].x - ptP.x) / (vPt[i].z - ptP.z) ; break ; } if ( dTan < dMinTan + EPS_ZERO) { // indice punto precedente diff --git a/Vector3d.cpp b/Vector3d.cpp index efb3504..432ac05 100644 --- a/Vector3d.cpp +++ b/Vector3d.cpp @@ -71,12 +71,12 @@ FromUprightOrtho( const Vector3d& vtV) double Vector3d::Len( void) const { - if ( fabs( y) < EPS_ZERO && fabs( z) < EPS_ZERO) - return fabs( x) ; - if ( fabs( z) < EPS_ZERO && fabs( x) < EPS_ZERO) - return fabs( y) ; - if ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO) - return fabs( z) ; + if ( abs( y) < EPS_ZERO && abs( z) < EPS_ZERO) + return abs( x) ; + if ( abs( z) < EPS_ZERO && abs( x) < EPS_ZERO) + return abs( y) ; + if ( abs( x) < EPS_ZERO && abs( y) < EPS_ZERO) + return abs( z) ; return sqrt( x * x + y * y + z * z) ; } @@ -87,10 +87,10 @@ Vector3d::Len( void) const double Vector3d::LenXY( void) const { - if ( fabs( y) < EPS_ZERO) - return fabs( x) ; - if ( fabs( x) < EPS_ZERO) - return fabs( y) ; + if ( abs( y) < EPS_ZERO) + return abs( x) ; + if ( abs( x) < EPS_ZERO) + return abs( y) ; return sqrt( x * x + y * y) ; } @@ -114,12 +114,12 @@ Vector3d::ToSpherical( double* pdLen, double* pdAngVertDeg, double* pdAngOrizzDe // altrimenti else { // se diretto come Z - if ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO) { + if ( abs( x) < EPS_ZERO && abs( y) < EPS_ZERO) { dAngVertDeg = (( z > 0) ? 0 : ANG_STRAIGHT) ; dAngOrizzDeg = 0 ; } // se altrimenti nel piano XY - else if ( fabs( z) < EPS_ZERO) { + else if ( abs( z) < EPS_ZERO) { dAngVertDeg = ANG_RIGHT ; dAngOrizzDeg = atan2( y, x) * RADTODEG ; if ( dAngOrizzDeg < 0) @@ -151,7 +151,7 @@ Vector3d::Normalize( double dEps) { // se già normalizzato, ok double dSqLen = x * x + y * y + z * z ; - if ( fabs( 1.0 - dSqLen) < ( 2 * 1000 * DBL_EPSILON)) + if ( abs( 1.0 - dSqLen) < ( 2 * 1000 * DBL_EPSILON)) return true ; // se troppo piccolo, errore @@ -160,7 +160,7 @@ Vector3d::Normalize( double dEps) // eseguo la normalizzazione double dLen = sqrt( dSqLen) ; - *this = *this / dLen ; + *this /= dLen ; return true ; } @@ -402,7 +402,7 @@ Vector3d::GetAngle( const Vector3d& vtEnd, double& dAngDeg) const double dProVett = ( *this ^ vtEnd).Len() ; // se entrambe nulle - if ( fabs( dProSca) < EPS_ZERO && fabs( dProVett) < EPS_ZERO) { + if ( abs( dProSca) < EPS_ZERO && abs( dProVett) < EPS_ZERO) { dAngDeg = 0 ; return false ; } @@ -423,7 +423,7 @@ Vector3d::GetAngleXY( const Vector3d& vtEnd, double& dAngDeg) const double dProVett = CrossXY( *this, vtEnd) ; // se entrambe nulle - if ( fabs( dProSca) < EPS_ZERO && fabs( dProVett) < EPS_ZERO) { + if ( abs( dProSca) < EPS_ZERO && abs( dProVett) < EPS_ZERO) { dAngDeg = 0 ; return false ; } diff --git a/VolZmap.cpp b/VolZmap.cpp index 1e8e251..75a4324 100644 --- a/VolZmap.cpp +++ b/VolZmap.cpp @@ -41,6 +41,7 @@ VolZmap::VolZmap(void) m_dMaxZ[i] = 0 ; m_nFracLin[i] = 0 ; } + m_Tool.SetTolerances( 0.2, ANG_TOL_APPROX_DEG) ; } //---------------------------------------------------------------------------- diff --git a/VolZmap.h b/VolZmap.h index a64b4de..367d167 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -285,18 +285,18 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool IntersRayDexel( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, unsigned int nI, unsigned int nJ, double& dU1, double& dU2) const ; bool IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, - const Frame3d& CylFrame, double dL, double dR, bool bTapO, bool bTapL, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) ; - bool IntersLineEllipticalCylinder( const Vector3d& vtLineDir, const Point3d& ptLineSt, + const Frame3d& CylFrame, double dH, double dRad, bool bTapLow, bool bTapUp, + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) ; + bool IntersLineEllipticalCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& CircFrame, double dRad, double dLongMvLen, double dOrtMvLen, bool bTapLow, bool bTapUp, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) ; + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) ; bool IntersLineConus( const Point3d& ptLineSt, const Vector3d& vtLineDir, - const Frame3d& ConusFrame, double dTan, double dl, double dL, bool bTapLow, bool bTapUp, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) ; + const Frame3d& ConusFrame, double dTan, double dMinH, double dMaxH, bool bTapLow, bool bTapUp, + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) ; bool IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& PolyFrame, double dLenX, double dLenY, double dLenZ, double dDeltaX, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) ; + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) ; bool TestIntersPlaneZmapBBox( const Plane3d& plPlane) const ; // Voxel: esistenza e passaggio da N a ijk per i voxel bool IsValidVoxel( int nN) const ; @@ -356,13 +356,13 @@ class VolZmap : public IVolZmap, public IGeoObjRW double m_dMaxZ[N_MAPS] ; // massimo in Zlocale di ciascuna griglia struct Data { // Tratto di dexel : dati estremi, versori normali e corpo di appartenenza - double dMin ; - int nToolMin ; + double dMin ; Vector3d vtMinN ; - double dMax ; - int nToolMax ; + int nToolMin ; + double dMax ; Vector3d vtMaxN ; - int nCompo ; + int nToolMax ; + int nCompo ; } ; std::vector> m_Values[N_MAPS] ; // dexel delle 3 griglie @@ -378,7 +378,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW // Se >= 0 è il numero di componenti connesse mutable std::vector m_InterBlockVox ; - mutable TriaMatrix m_InterBlockTria ; + mutable TriaMatrix m_InterBlockTria ; mutable std::vector m_SliceXY ; mutable std::vector m_SliceXZ ; diff --git a/VolZmapCalculus.cpp b/VolZmapCalculus.cpp index 8c30061..5acfd78 100644 --- a/VolZmapCalculus.cpp +++ b/VolZmapCalculus.cpp @@ -693,312 +693,259 @@ VolZmap::AvoidCylinder( const Frame3d& frCyl, double dL, double dR) const } //---------------------------------------------------------------------------- -// NB: L'origine del sistema di riferimento è nel centro della circonferenza di base -// e l'asse di simmetria coincide con l'asse z. +// Riferimento con origine nel centro della base e asse di simmetria coincidente con l'asse Z. // La funzione restituisce true in caso di intersezione, false altrimenti. +//---------------------------------------------------------------------------- bool VolZmap::IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, - const Frame3d& CylFrame, double dH, double dR, bool bTapB, bool bTapT, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) + const Frame3d& CylFrame, double dH, double dRad, bool bTapLow, bool bTapUp, + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) { - Point3d ptP = ptLineSt ; - Vector3d vtV = vtLineDir ; + // Porto la linea nel riferimento del cilindro + Point3d ptP = ptLineSt ; ptP.ToLoc( CylFrame) ; + Vector3d vtV = vtLineDir ; vtV.ToLoc( CylFrame) ; - // Trasformazione delle coordinate: - // l'asse del cilindro corrisponde con - // l'asse z del sistema di riferimento - ptP.ToLoc( CylFrame) ; - vtV.ToLoc( CylFrame) ; + // Determino le eventuali intersezioni con le due basi a quota minima e massima (solo se linea non parallela ad esse) + int nBasInt = 0 ; + if ( abs( vtV.z) > EPS_ZERO) { + // le linee tangenti al cilindro non sono considerate intersecanti + double EpsRad = ( vtV.IsZeroXY() ? - EPS_SMALL : EPS_SMALL) ; + ptInt1 = ptP + ( ( 0 - ptP.z) / vtV.z) * vtV ; + if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y < dRad * dRad + 2 * dRad * EpsRad) { + nBasInt += 1 ; + vtN1 = Z_AX ; + } + ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; + if ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y < dRad * dRad + 2 * dRad * EpsRad) { + nBasInt += 2 ; + vtN2 = - Z_AX ; + } + } + // Se la linea interseca entrambe le basi, si sono trovate le due intersezioni + if ( nBasInt == 3) { + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( CylFrame) ; + vtN1.ToGlob( CylFrame) ; + ptInt2.ToGlob( CylFrame) ; + vtN2.ToGlob( CylFrame) ; + // Trovate intersezioni + return true ; + } + + // Determino le intersezioni con la superficie laterale del cilindro DBLVECTOR vdCoef(3) ; - DBLVECTOR vdRoots ; - // Non vogliamo che i dexel a filo vengano tagliati - double dSqRad = dR * dR ; - double dSqRadSafe = dSqRad - 2 * dR * EPS_SMALL ; - + double dSqRad = dRad * dRad ; vdCoef[0] = ptP.x * ptP.x + ptP.y * ptP.y - dSqRad ; vdCoef[1] = 2 * ( ptP.x * vtV.x + ptP.y * vtV.y) ; vdCoef[2] = vtV.x * vtV.x + vtV.y * vtV.y ; - - // Computo radici + DBLVECTOR vdRoots ; int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; - // Nessuna soluzione - if ( nRoot == 0 || nRoot == 1) { - if ( abs( vtV.z) > EPS_ZERO) { - // Intersezioni con i piani che limitano il cilindro in altezza - ptInt1 = ptP - ( ptP.z / vtV.z) * vtV ; - ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - // Normali nei punti di interseione - vtN1 = Z_AX ; - vtN2 = - Z_AX ; - // Se le soluzioni sono all'interno delle circonferenze - if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y <= dSqRadSafe && - ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y <= dSqRadSafe) { - // Trasformiamo le coordinate nel sistema Zmap e abbiamo finito - ptInt1.ToGlob( CylFrame) ; - ptInt2.ToGlob( CylFrame) ; - vtN1.ToGlob( CylFrame) ; - vtN2.ToGlob( CylFrame) ; - return true ; - } - // Nessuna intersezione - else - return false ; + // Epsilon per piani di tappo + double dEpsLow = ( bTapLow ? - EPS_SMALL : EPS_SMALL) ; + double dEpsUp = ( bTapUp ? EPS_SMALL : - EPS_SMALL) ; + + // Elimino le soluzioni cha danno intersezioni fuori dai limiti in Z del cilindro + if ( nRoot == 2) { + double dIntZ2 = ptP.z + vdRoots[1] * vtV.z ; + if ( dIntZ2 < 0 + dEpsLow || dIntZ2 > dH + dEpsUp) + nRoot = 1 ; + } + if ( nRoot >= 1) { + double dIntZ1 = ptP.z + vdRoots[0] * vtV.z ; + if ( dIntZ1 < 0 + dEpsLow || dIntZ1 > dH + dEpsUp) { + if ( nRoot == 2) + vdRoots[0] = vdRoots[1] ; + -- nRoot ; } - // Nessuna intersezione - else - return false ; } - // L'equazione ammette o due soluzioni (eventualmente - // coincidenti) oppure nessuna o infinite se la la retta - // appartiene alla superficie - + // Due soluzioni: la retta interseca due volte la superficie laterale if ( nRoot == 2) { - // Ordino i parametri di intersezione - double dUmin = vdRoots[0] ; - double dUmax = vdRoots[1] ; - if ( dUmin > dUmax) - swap( dUmin, dUmax) ; - // Calcolo i punti d'intersezione (ordinati secondo Z crescente) + // Punti di intersezione con la superficie del cilindro ptInt1 = ptP + vdRoots[0] * vtV ; ptInt2 = ptP + vdRoots[1] * vtV ; - if ( ptInt1.z > ptInt2.z) - swap( ptInt1, ptInt2) ; - // Quote limitazione, dipendenti dalla tappatura estremità - double dZbot = ( bTapB ? -EPS_SMALL : EPS_SMALL) ; - double dZtop = ( bTapT ? dH + EPS_SMALL : dH - EPS_SMALL) ; - // Se intersezioni entrambe fuori dal cilindro limitato, non vanno considerate - if ( ptInt2.z < dZbot || ptInt1.z > dZtop) - return false ; - // Calcolo le normali - vtN1.Set( ( ORIG - ptInt1).x, ( ORIG - ptInt1).y, 0) ; + if ( ptInt1.z > ptInt2.z) + swap( ptInt1, ptInt2) ; + // Determino le normali + vtN1.Set( -ptInt1.x, -ptInt1.y, 0) ; vtN1.Normalize() ; - vtN2.Set( ( ORIG - ptInt2).x, ( ORIG - ptInt2).y, 0) ; + vtN2.Set( -ptInt2.x, -ptInt2.y, 0) ; vtN2.Normalize() ; - // Limitazioni per intersezione con piano basso - if ( ptInt1.z < dZbot - EPS_ZERO) { - ptInt1 = ptP + Clamp( ( dZbot - ptP.z / vtV.z), dUmin, dUmax) * vtV ; - vtN1.Set( 0, 0, 1) ; - } - // Limitazioni per intersezione con piano alto - if ( ptInt2.z > dZtop + EPS_ZERO) { - ptInt2 = ptP + Clamp( ( ( dZtop - ptP.z) / vtV.z), dUmin, dUmax) * vtV ; - vtN2.Set( 0, 0, -1) ; - } - // Riporto le coordinate nel sistema di riferimento griglia + // Porto i punti e i versori nel riferimento globale ptInt1.ToGlob( CylFrame) ; - ptInt2.ToGlob( CylFrame) ; vtN1.ToGlob( CylFrame) ; + ptInt2.ToGlob( CylFrame) ; vtN2.ToGlob( CylFrame) ; + // Trovate intersezioni + return true ; } - return true ; + + // Una soluzione : la retta interseca la superficie laterale e un piano + else if ( nRoot == 1) { + // Se piano superiore + if ( nBasInt == 2) { + // Punto di intersezione + ptInt1 = ptP + vdRoots[0] * vtV ; + // Normale alla superficie del cilindro verso l'interno + vtN1.Set( -ptInt1.x, -ptInt1.y, 0) ; + vtN1.Normalize() ; + } + // altrimenti piano inferiore + else if ( nBasInt == 1) { + // Punto di intersezione + ptInt2 = ptP + vdRoots[0] * vtV ; + // Normale alla superficie del cilindro verso l'interno + vtN2.Set( -ptInt2.x, -ptInt2.y, 0) ; + vtN2.Normalize() ; + } + // altrimenti niente + else + return false ; + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( CylFrame) ; + vtN1.ToGlob( CylFrame) ; + ptInt2.ToGlob( CylFrame) ; + vtN2.ToGlob( CylFrame) ; + // Trovate intersezioni + return true ; + } + + // Nessuna soluzione : nessuna intersezione + else + return false ; } +//---------------------------------------------------------------------------- +// Riferimento con origine nel vertice del cono e asse di simmetria coincidente con l'asse Z. +// La funzione restituisce true in caso di intersezione, false altrimenti. //---------------------------------------------------------------------------- bool VolZmap::IntersLineConus( const Point3d& ptLineSt, const Vector3d& vtLineDir, - const Frame3d& ConusFrame, double dTan, double dh, double dH, bool bTapLow, bool bTapUp, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) + const Frame3d& ConusFrame, double dTan, double dMinH, double dMaxH, bool bTapLow, bool bTapUp, + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) { - // NB: L'origine del sistema di riferimento deve essere - // nel vertice del cono e l'asse di simmetria deve coincidere con l'asse x. - // La funzione restituisce true in caso di intersezione, false altrimenti. + // Porto la linea nel riferimento del cono + Point3d ptP = ptLineSt ; ptP.ToLoc( ConusFrame) ; + Vector3d vtV = vtLineDir ; vtV.ToLoc( ConusFrame) ; - Point3d ptP = ptLineSt ; - Vector3d vtV = vtLineDir ; + // Raggi delle due basi + double dMinRad = dTan * dMinH ; + double dMaxRad = dTan * dMaxH ; - // Trasformazione delle coordinate - ptP.ToLoc( ConusFrame) ; - vtV.ToLoc( ConusFrame) ; + // Epsilon per piani di tappo + double dEpsLow = ( bTapLow ? - EPS_SMALL : EPS_SMALL) ; + double dEpsUp = ( bTapUp ? EPS_SMALL : - EPS_SMALL) ; - DBLVECTOR vdCoef(3) ; - DBLVECTOR vdRoots ; + // Determino le eventuali intersezioni con le due basi a quota minima e massima (solo se linea non parallela ad esse) + int nBasInt = 0 ; + if ( abs( vtV.z) > EPS_ZERO) { + ptInt1 = ptP + ( ( dMinH - ptP.z) / vtV.z) * vtV ; + if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y < dMinRad * dMinRad + 2 * dMinRad * dTan * dEpsLow) { + nBasInt += 1 ; + vtN1 = Z_AX ; + } + ptInt2 = ptP + ( ( dMaxH - ptP.z) / vtV.z) * vtV ; + if ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y < dMaxRad * dMaxRad + 2 * dMaxRad * dTan * dEpsUp) { + nBasInt += 2 ; + vtN2 = - Z_AX ; + } + } + // Se la linea interseca entrambe le basi, si sono trovate le due intersezioni + if ( nBasInt == 3) { + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( ConusFrame) ; + vtN1.ToGlob( ConusFrame) ; + ptInt2.ToGlob( ConusFrame) ; + vtN2.ToGlob( ConusFrame) ; + // Trovate intersezioni + return true ; + } + + // Determino le intersezioni con la superficie laterale del cono + DBLVECTOR vdCoef( 3) ; double dSqTan = dTan * dTan ; - double dMinRad = dTan * dh ; - double dMaxRad = dTan * dH ; - double dDeltaR = dMaxRad - dMinRad ; - double dHei = dH - dh ; - vdCoef[0] = dSqTan * ptP.z * ptP.z - ptP.x * ptP.x - ptP.y * ptP.y ; vdCoef[1] = 2 * ( dSqTan * ptP.z * vtV.z - ptP.x * vtV.x - ptP.y * vtV.y) ; vdCoef[2] = dSqTan * vtV.z * vtV.z - vtV.x * vtV.x - vtV.y * vtV.y ; - - // Computo radici + DBLVECTOR vdRoots ; int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; - - // Nessuna soluzione - if ( nRoot == 0) - return false ; - double dEpsLow = ( bTapLow ? - EPS_SMALL : EPS_SMALL) ; - double dEpsUp = ( bTapUp ? EPS_SMALL : - EPS_SMALL) ; - - // Una soluzione: la retta iterseca superficie - // laterale e un piano - if ( nRoot == 1) { - - ptInt1 = ptP + vdRoots[0] * vtV ; - - Vector3d vtU = ( ptInt1 - ORIG) - ( ptInt1 - ORIG).z * Z_AX ; - - vtU.Normalize() ; - - vtN1 = dDeltaR * Z_AX - dHei * vtU ; - - vtN1.Normalize() ; - - if ( ptInt1.z < dH + dEpsUp) { - - if ( ptInt1.z > dh + dEpsLow) { - - ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - - vtN2 = - Z_AX ; - - } - else if ( ptInt1.z > - EPS_SMALL) { - - ptInt1 = ptP + ( ( dh - ptP.z) / vtV.z) * vtV ; - ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - - vtN1 = Z_AX ; - vtN2 = - Z_AX ; - - if ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y > dMaxRad * dMaxRad) - - return false ; - } - else - return false ; - - ptInt1.ToGlob( ConusFrame) ; - ptInt2.ToGlob( ConusFrame) ; - - vtN1.ToGlob( ConusFrame) ; - vtN2.ToGlob( ConusFrame) ; - - return true ; - } - else - return false ; - + // Elimino le soluzioni cha danno intersezioni fuori dai limiti in Z del tronco + if ( nRoot == 2) { + double dIntZ2 = ptP.z + vdRoots[1] * vtV.z ; + if ( dIntZ2 < dMinH + dEpsLow || dIntZ2 > dMaxH + dEpsUp) + nRoot = 1 ; + } + if ( nRoot >= 1) { + double dIntZ1 = ptP.z + vdRoots[0] * vtV.z ; + if ( dIntZ1 < dMinH + dEpsLow || dIntZ1 > dMaxH + dEpsUp) { + if ( nRoot == 2) + vdRoots[0] = vdRoots[1] ; + -- nRoot ; + } } - // Due soluzioni: la retta interseca due volte la - // superficie laterale - else if ( nRoot == 2) { + // Due soluzioni: la retta interseca due volte la superficie laterale + if ( nRoot == 2) { + // Punti di intersezione con la superficie del cono ptInt1 = ptP + vdRoots[0] * vtV ; ptInt2 = ptP + vdRoots[1] * vtV ; - if ( ptInt1.z > ptInt2.z) swap( ptInt1, ptInt2) ; - - Vector3d vtU1 = ( ptInt1 - ORIG) - ( ptInt1 - ORIG).z * Z_AX ; - Vector3d vtU2 = ( ptInt2 - ORIG) - ( ptInt2 - ORIG).z * Z_AX ; - - vtU1.Normalize() ; - vtU2.Normalize() ; - - vtN1 = dDeltaR * Z_AX - dHei * vtU1 ; - vtN2 = dDeltaR * Z_AX - dHei * vtU2 ; - + // Determino le normali + vtN1.Set( -ptInt1.x, -ptInt1.y, ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y) / ptInt1.z) ; vtN1.Normalize() ; + vtN2.Set( -ptInt2.x, -ptInt2.y, ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y) / ptInt2.z) ; vtN2.Normalize() ; - - if ( abs( vtV.z) < EPS_ZERO) { - - if ( ptInt1.z > dh + dEpsLow && ptInt1.z < dH + dEpsUp) { - - ptInt1.ToGlob( ConusFrame) ; - ptInt2.ToGlob( ConusFrame) ; - - vtN1.ToGlob( ConusFrame) ; - vtN2.ToGlob( ConusFrame) ; - - vtN1.Normalize() ; - vtN2.Normalize() ; - - return true ; - } - else - return false ; - } - - - if ( ptInt1.z < dH + dEpsUp) { - - if ( ptInt1.z > dh + dEpsLow) { - - if ( ptInt2.z > dH + dEpsUp) { - - ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - - vtN2 = - Z_AX ; - } - } - else if ( ptInt1.z > - EPS_SMALL) { - - if ( ptInt2.z > dH + dEpsUp) { - - ptInt1 = ptP + ( ( dh - ptP.z) / vtV.z) * vtV ; - ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - - vtN1 = Z_AX ; - vtN2 = - Z_AX ; - } - else if ( ptInt2.z > dh + dEpsLow) { - - ptInt1 = ptP + ( ( dh - ptP.z) / vtV.z) * vtV ; - vtN1 = Z_AX ; - } - else - return false ; - } - else { - - if ( ptInt2.z < 0) - - return false ; - - else if ( ptInt2.z < dh + dEpsLow) { - - ptInt1 = ptP + ( ( dh - ptP.z) / vtV.z) * vtV ; - ptInt2 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - - vtN1 = Z_AX ; - vtN2 = - Z_AX ; - } - else if ( ptInt2.z < dH + dEpsUp) { - - ptInt1 = ptP + ( ( dH - ptP.z) / vtV.z) * vtV ; - vtN1 = - Z_AX ; - } - else - return false ; - } - - ptInt1.ToGlob( ConusFrame) ; - ptInt2.ToGlob( ConusFrame) ; - - vtN1.ToGlob( ConusFrame) ; - vtN2.ToGlob( ConusFrame) ; - + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( ConusFrame) ; + vtN1.ToGlob( ConusFrame) ; + ptInt2.ToGlob( ConusFrame) ; + vtN2.ToGlob( ConusFrame) ; + // Trovate intersezioni + return true ; + } + + // Una soluzione : la retta interseca la superficie laterale e un piano + else if ( nRoot == 1) { + // Se piano superiore + if ( nBasInt == 2) { + // Punto di intersezione + ptInt1 = ptP + vdRoots[0] * vtV ; + // Normale alla superficie del cono verso l'interno + vtN1.Set( -ptInt1.x, -ptInt1.y, ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y) / ptInt1.z) ; vtN1.Normalize() ; - vtN2.Normalize() ; - - return true ; } + // altrimenti piano inferiore + else if( nBasInt == 1) { + // Punto di intersezione + ptInt2 = ptP + vdRoots[0] * vtV ; + // Normale alla superficie del cono verso l'interno + vtN2.Set( -ptInt2.x, -ptInt2.y, ( ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y) / ptInt2.z) ; + vtN2.Normalize() ; + } + // altrimenti niente else return false ; + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( ConusFrame) ; + vtN1.ToGlob( ConusFrame) ; + ptInt2.ToGlob( ConusFrame) ; + vtN2.ToGlob( ConusFrame) ; + // Trovate intersezioni + return true ; } - return false ; + + // Nessuna soluzione : nessuna intersezione + else + return false ; } //---------------------------------------------------------------------------- -// NB: L'origine del sistema di riferimento deve essere +// L'origine del sistema di riferimento deve essere // nel centro della circonferenza di base, la cui traslazione obliqua // genera il cilindro ellittico, e l'asse z deve essere l'asse // di simmetria di tale circonferenza. @@ -1008,26 +955,25 @@ VolZmap::IntersLineConus( const Point3d& ptLineSt, const Vector3d& vtLineDir, // dOrtMvLen sono rispettivamente le lunghezze delle proiezioni del // movimento su z e x del sistema di riferimento CircFrame. bool -VolZmap::IntersLineEllipticalCylinder( const Vector3d& vtLineDir, const Point3d& ptLineSt, +VolZmap::IntersLineEllipticalCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& CircFrame, double dRad, double dLongMvLen, double dOrtMvLen, bool bTapLow, bool bTapUp, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) { + // Se il cilindrico ellittico degenera in un piano, non bisogna tagliare + if ( abs( dLongMvLen) < EPS_SMALL) + return false ; + + // Porto la linea nel riferimento del cilindro + Point3d ptP = ptLineSt ; ptP.ToLoc( CircFrame) ; + Vector3d vtV = vtLineDir ; vtV.ToLoc( CircFrame) ; + // Quadrato del raggio double dSqRad = dRad * dRad ; - // Punto e vettore individuanti la retta - Point3d ptP = ptLineSt ; - Vector3d vtV = vtLineDir ; // Asse cilindro ellittico Vector3d vtAx( dOrtMvLen, 0, dLongMvLen) ; vtAx.Normalize() ; - // Se il cilindro ellittico degenera in una superficie, - // non bisogna tagliare - if ( abs( vtAx.z) < EPS_SMALL) - return false ; - // Trasformazione delle coordinate - ptP.ToLoc( CircFrame) ; - vtV.ToLoc( CircFrame) ; + // Retta parallela all'asse del cilindro if ( AreSameOrOppositeVectorApprox( vtV, vtAx)) { // Interseco la retta con i piani delle circonferenze @@ -1049,14 +995,12 @@ VolZmap::IntersLineEllipticalCylinder( const Vector3d& vtLineDir, const Point3d& return false ; } - vector vdCoef(3) ; - vector vdRoots ; // Coefficiente angolare della retta di movimento nel - // piano ZX del sistema di riferimento del movimento - // e suo quadrato + // piano ZX del sistema di riferimento del movimento e suo quadrato double dObCoef = dOrtMvLen / dLongMvLen ; double dSqCoef = dObCoef * dObCoef ; // Setto i coeficienti dell'equazione + DBLVECTOR vdCoef(3) ; vdCoef[0] = dSqCoef * ptP.z * ptP.z + ptP.x * ptP.x + ptP.y * ptP.y - 2 * dObCoef * ptP.z * ptP.x - dSqRad ; vdCoef[1] = 2 * ( dSqCoef * vtV.z * ptP.z + vtV.x * ptP.x + vtV.y * ptP.y @@ -1064,120 +1008,103 @@ VolZmap::IntersLineEllipticalCylinder( const Vector3d& vtLineDir, const Point3d& vdCoef[2] = dSqCoef * vtV.z * vtV.z + vtV.x * vtV.x + vtV.y * vtV.y - 2 * dObCoef * vtV.z * vtV.x ; // Numero di soluzioni + DBLVECTOR vdRoots ; int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; // L'equazione ammette o due soluzioni (eventualmente // coincidenti) oppure nessuna o infinite se la la retta // appartiene alla superficie - // Se ci sono intersezioni con i tappi o l'equazione - // degenera in una di primo grado, le eventuali - // soluzioni sono già state trovate. - if ( nRoot == 0 || nRoot == 1) + // Se numero di soluzioni diverso da due le eventuali intersezioni sono già state trovate + if ( nRoot != 2) return false ; + // Due soluzioni trovate - else if ( nRoot == 2) { - // Flag per i tappi - double dEpsLow = ( bTapLow ? - EPS_SMALL : EPS_SMALL) ; - double dEpsUp = ( bTapUp ? EPS_SMALL : - EPS_SMALL) ; - // Vettore di movimento - Vector3d vtMv( dOrtMvLen, 0, dLongMvLen) ; - // Punti di intersezione - ptInt1 = ptP + vdRoots[0] * vtV ; - ptInt2 = ptP + vdRoots[1] * vtV ; - // Simmetria del problema - if ( ptInt1.z > ptInt2.z) - swap( ptInt1, ptInt2) ; - // Determino le normali alla superficie nei punti d'intersezione - Vector3d vtTest1 = ( ptInt1 - ORIG) - ( ptInt1 - ORIG) * vtAx * vtAx ; - Vector3d vtTest2 = ( ptInt2 - ORIG) - ( ptInt2 - ORIG) * vtAx * vtAx ; - double dX0_1, dX0_2 ; - if ( vtTest1.x > 0) { - dX0_1 = ( dSqRad - ptInt1.y * ptInt1.y > 0 ? sqrt( dSqRad - ptInt1.y * ptInt1.y) : 0) ; - } - else { - dX0_1 = ( dSqRad - ptInt1.y * ptInt1.y > 0 ? - sqrt( dSqRad - ptInt1.y * ptInt1.y) : 0) ; - } - Vector3d vtCirc1( - dX0_1, - ptInt1.y, 0) ; - Vector3d vtTan1( vtCirc1.y, - vtCirc1.x, 0) ; - Vector3d vtCross1 = vtTan1 ^ vtMv ; - // Vettore 1 - vtN1 = ( vtCross1 * vtCirc1 > - EPS_ZERO ? vtCross1 : - vtCross1) ; - if ( vtTest2.x > 0) { - dX0_2 = ( dSqRad - ptInt2.y * ptInt2.y > 0 ? sqrt( dSqRad - ptInt2.y * ptInt2.y) : 0) ; - } - else { - dX0_2 = ( dSqRad - ptInt2.y * ptInt2.y > 0 ? - sqrt( dSqRad - ptInt2.y * ptInt2.y) : 0) ; - } - Vector3d vtCirc2( - dX0_2, - ptInt2.y, 0) ; - Vector3d vtTan2( vtCirc2.y, - vtCirc2.x, 0) ; - Vector3d vtCross2 = vtTan2 ^ vtMv ; - // Vettore 2 - vtN2 = ( vtCross2 * vtCirc2 > - EPS_ZERO ? vtCross2 : - vtCross2) ; - // Normalizzo i vettori - vtN1.Normalize() ; - vtN2.Normalize() ; + // Vettore di movimento + Vector3d vtMv( dOrtMvLen, 0, dLongMvLen) ; + // Punti di intersezione + ptInt1 = ptP + vdRoots[0] * vtV ; + ptInt2 = ptP + vdRoots[1] * vtV ; + // Simmetria del problema + if ( ptInt1.z > ptInt2.z) + swap( ptInt1, ptInt2) ; + // Determino le normali alla superficie nei punti d'intersezione + // Vettore 1 + Vector3d vtTest1 = ( ptInt1 - ORIG) - ( ptInt1 - ORIG) * vtAx * vtAx ; + double dX0_1 = ( vtTest1.x > 0 ? 1 : -1) * sqrt( max( dSqRad - ptInt1.y * ptInt1.y, 0.)) ; + Vector3d vtCirc1( - dX0_1, - ptInt1.y, 0) ; + Vector3d vtTan1( vtCirc1.y, - vtCirc1.x, 0) ; + Vector3d vtCross1 = vtTan1 ^ vtMv ; + vtN1 = ( vtCross1 * vtCirc1 > - EPS_ZERO ? vtCross1 : - vtCross1) ; + vtN1.Normalize() ; + // Vettore 2 + Vector3d vtTest2 = ( ptInt2 - ORIG) - ( ptInt2 - ORIG) * vtAx * vtAx ; + double dX0_2 = ( vtTest2.x > 0 ? 1 : -1) * sqrt( max( dSqRad - ptInt2.y * ptInt2.y, 0.)) ; + Vector3d vtCirc2( - dX0_2, - ptInt2.y, 0) ; + Vector3d vtTan2( vtCirc2.y, - vtCirc2.x, 0) ; + Vector3d vtCross2 = vtTan2 ^ vtMv ; + vtN2 = ( vtCross2 * vtCirc2 > - EPS_ZERO ? vtCross2 : - vtCross2) ; + vtN2.Normalize() ; - // Studio le soluzioni: se ua è fuori dalla regione - // ammissibile, vuol dire che la retta esce da un tappo. - if ( ptInt1.z < dLongMvLen + dEpsUp) { - if ( ptInt1.z > + dEpsLow) { - // ptInt2 è sul tappo - if ( ptInt2.z > dLongMvLen + dEpsUp) { - ptInt2 = ptP + ( ( dLongMvLen - ptP.z) / vtV.z) * vtV ; - vtN2 = - Z_AX ; - } - } - else { - // Entrambe le soluzioni sono su un tappo - if ( ptInt2.z > dLongMvLen + dEpsUp) { - ptInt1 = ptP - ( ptP.z / vtV.z) * vtV ; - ptInt2 = ptP + ( ( dLongMvLen - ptP.z) / vtV.z) * vtV ; - vtN1.Set( 0, 0, 1) ; - vtN2.Set( 0, 0, -1) ; - if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y > dSqRad && - ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y > dSqRad) - return false ; - } - // La prima soluzione è sul tappo - else if ( ptInt2.z > dEpsLow) { - ptInt1 = ptP - ( ptP.z / vtV.z) * vtV ; - vtN1.Set( 0, 0, 1) ; - } - else - return false ; + // Flag per i tappi + double dEpsLow = ( bTapLow ? - EPS_SMALL : EPS_SMALL) ; + double dEpsUp = ( bTapUp ? EPS_SMALL : - EPS_SMALL) ; + + // Studio le soluzioni: se una è fuori dalla regione + // ammissibile, vuol dire che la retta esce da un tappo. + if ( ptInt1.z < dLongMvLen + dEpsUp) { + if ( ptInt1.z > + dEpsLow) { + // ptInt2 è sul tappo + if ( ptInt2.z > dLongMvLen + dEpsUp) { + ptInt2 = ptP + ( ( dLongMvLen - ptP.z) / vtV.z) * vtV ; + vtN2 = - Z_AX ; } } - else - return false ; + else { + // Entrambe le soluzioni sono su un tappo + if ( ptInt2.z > dLongMvLen + dEpsUp) { + ptInt1 = ptP - ( ptP.z / vtV.z) * vtV ; + ptInt2 = ptP + ( ( dLongMvLen - ptP.z) / vtV.z) * vtV ; + vtN1.Set( 0, 0, 1) ; + vtN2.Set( 0, 0, -1) ; + if ( ptInt1.x * ptInt1.x + ptInt1.y * ptInt1.y > dSqRad && + ptInt2.x * ptInt2.x + ptInt2.y * ptInt2.y > dSqRad) + return false ; + } + // La prima soluzione è sul tappo + else if ( ptInt2.z > dEpsLow) { + ptInt1 = ptP - ( ptP.z / vtV.z) * vtV ; + vtN1.Set( 0, 0, 1) ; + } + else + return false ; + } + } + else + return false ; - // Riporto le coordinate nel sistema - // di riferimento griglia. - ptInt1.ToGlob( CircFrame) ; - ptInt2.ToGlob( CircFrame) ; - vtN1.ToGlob( CircFrame) ; - vtN2.ToGlob( CircFrame) ; - return true ; - } - return false ; + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( CircFrame) ; + vtN1.ToGlob( CircFrame) ; + ptInt2.ToGlob( CircFrame) ; + vtN2.ToGlob( CircFrame) ; + + return true ; } //---------------------------------------------------------------------------- bool VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& PolyFrame, double dLenX, double dLenY, double dLenZ, double dDeltaZ, - Point3d& ptInt1, Point3d& ptInt2, Vector3d& vtN1, Vector3d& vtN2) + Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) { // Controllo sulle dimensioni lineari affinché sia valido il poliedro - if ( dLenX <= 0 || dLenY <= 0 || dLenZ <= 0) + if ( dLenX <= EPS_SMALL || dLenY <= EPS_SMALL || dLenZ <= EPS_SMALL) return false ; - Point3d ptP = ptLineSt ; - Vector3d vtV = vtLineDir ; - - // Trasformazione delle coordinate - ptP.ToLoc( PolyFrame) ; - vtV.ToLoc( PolyFrame) ; + // Porto la linea nel riferimento del poliedro + Point3d ptP = ptLineSt ; ptP.ToLoc( PolyFrame) ; + Vector3d vtV = vtLineDir ; vtV.ToLoc( PolyFrame) ; // Facce 1 e 2 parallele a XY // Facce 3 e 4 parallele a XZ @@ -1185,13 +1112,27 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine Point3d ptFacet135( 0, dLenY / 2, 0) ; Point3d ptFacet246( dLenX, - dLenY / 2, dLenZ + dDeltaZ) ; - // Servono per descrivere i piani obliqui + // Vettori per descrizione piani obliqui Vector3d vtFacet5 = ptFacet135 - ptP ; Vector3d vtFacet6 = ptFacet246 - ptP ; - Vector3d vtOb( - dDeltaZ, 0, dLenX) ; vtOb.Normalize() ; + // Controlli affinché non vengano tagliati dexel a filo + // con il passaggio dell'utensile: + // Controllo sulle facce 1 e 2 + if ( abs( vtV.y) < EPS_ZERO && abs( ptP.y) > ptFacet135.y) + return false ; + // Controllo sulle facce 3 e 4 + if ( abs( vtV.x) < EPS_ZERO && ( ptP.x < ptFacet135.x || ptP.x > ptFacet246.x)) + return false ; + // Controllo sulle facce 5 e 6 + double dP1 = abs ( ( ptFacet135 - ptP) * vtOb) ; + double dP2 = abs ( ( ptFacet246 - ptP) * vtOb) ; + if ( abs( vtV * vtOb) < EPS_ZERO && ( dP1 < EPS_SMALL || dP2 < EPS_SMALL)) + return false ; + + // Punti notevoli Point3d ptI1 = ptP + ( ( ptFacet135.y - ptP.y) / vtV.y) * vtV ; Point3d ptI2 = ptP + ( ( ptFacet246.y - ptP.y) / vtV.y) * vtV ; Point3d ptI3 = ptP + ( ( ptFacet135.x - ptP.x) / vtV.x) * vtV ; @@ -1199,37 +1140,20 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine Point3d ptI5 = ptP + ( ( vtFacet5 * vtOb) / ( vtV * vtOb)) * vtV ; Point3d ptI6 = ptP + ( ( vtFacet6 * vtOb) / ( vtV * vtOb)) * vtV ; - // Controlli affinché non vengano tagliati dexel a filo - // con il passaggio dell'utensile: - // Controllo sulle facce 1 e 2 - if ( abs( vtV.y) < EPS_ZERO && abs( ptP.y) > ptFacet135.y) - return false ; - // Controllo sulle facce 3 e 4 - if ( abs( vtV.x) < EPS_ZERO && ( ptP.x < ptFacet135.x || ptP.x > ptFacet246.x)) - return false ; - // Controllo sulle facce 5 e 6 - double dDotObV = abs( vtV * vtOb) ; - Vector3d vtP1 = ptFacet135 - ptP ; - Vector3d vtP2 = ptFacet246 - ptP ; - double dP1 = abs ( vtP1 * vtOb) ; - double dP2 = abs ( vtP2 * vtOb) ; - if ( dDotObV < EPS_ZERO && ( dP1 < EPS_SMALL || dP2 < EPS_SMALL)) - return false ; - // Ricerca intersezioni con le facce int nIntNum = 0 ; // Intersezione con la prima faccia - if ( ptI1.x >= 0 && ptI1.x <= dLenX && - ptI1.z * dLenX >= dDeltaZ * ptI1.x && ( ptI1.z - dLenZ) * dLenX <= dDeltaZ * ptI1.x) { + if ( ptI1.x >= 0 && ptI1.x <= dLenX && + ptI1.z * dLenX >= dDeltaZ * ptI1.x && ( ptI1.z - dLenZ) * dLenX <= dDeltaZ * ptI1.x) { ptInt1 = ptI1 ; vtN1 = - Y_AX ; ++ nIntNum ; } // Intersezione con la seconda faccia - if ( ptI2.x >= 0 && ptI2.x <= dLenX && - ptI2.z * dLenX >= dDeltaZ * ptI2.x && ( ptI2.z - dLenZ) * dLenX <= dDeltaZ * ptI2.x) { + if ( ptI2.x >= 0 && ptI2.x <= dLenX && + ptI2.z * dLenX >= dDeltaZ * ptI2.x && ( ptI2.z - dLenZ) * dLenX <= dDeltaZ * ptI2.x) { if ( nIntNum == 0) { ptInt1 = ptI2 ; vtN1 = Y_AX ; @@ -1243,9 +1167,9 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine } // Intersezione con la terza faccia - if ( nIntNum < 2 && - ptI3.z >= 0 && ptI3.z <= dLenZ && - ptI3.y >= - ptFacet135.y && ptI3.y <= ptFacet135.y) { + if ( nIntNum < 2 && + ptI3.z >= 0 && ptI3.z <= dLenZ && + ptI3.y >= - ptFacet135.y && ptI3.y <= ptFacet135.y) { if ( nIntNum == 0) { ptInt1 = ptI3 ; vtN1 = X_AX ; @@ -1259,9 +1183,9 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine } // Intersezione con la quarta faccia - if ( nIntNum < 2 && - ptI4.z >= dDeltaZ && ptI4.z <= dLenZ + dDeltaZ && - ptI4.y >= - ptFacet135.y && ptI4.y <= ptFacet135.y) { + if ( nIntNum < 2 && + ptI4.z >= dDeltaZ && ptI4.z <= dLenZ + dDeltaZ && + ptI4.y >= - ptFacet135.y && ptI4.y <= ptFacet135.y) { if ( nIntNum == 0) { ptInt1 = ptI4 ; vtN1 = - X_AX ; @@ -1275,9 +1199,9 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine } // Intersezione con la quinta faccia - if ( nIntNum < 2 && - ptI5.x >= 0 && ptI5.x <= dLenX && - ptI5.y >= - ptFacet135.y && ptI5.y <= ptFacet135.y) { + if ( nIntNum < 2 && + ptI5.x >= 0 && ptI5.x <= dLenX && + ptI5.y >= - ptFacet135.y && ptI5.y <= ptFacet135.y) { if ( nIntNum == 0) { ptInt1 = ptI5 ; vtN1 = vtOb ; @@ -1291,9 +1215,9 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine } // Intersezione con la sesta faccia - if ( nIntNum < 2 && - ptI6.x >= 0 && ptI6.x <= dLenX && - ptI6.y >= - ptFacet135.y && ptI6.y <= ptFacet135.y) { + if ( nIntNum < 2 && + ptI6.x >= 0 && ptI6.x <= dLenX && + ptI6.y >= - ptFacet135.y && ptI6.y <= ptFacet135.y) { if ( nIntNum == 0) { ptInt1 = ptI6; vtN1 = - vtOb ; @@ -1306,15 +1230,15 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine } } - if ( nIntNum == 2) { - ptInt1.ToGlob( PolyFrame) ; - ptInt2.ToGlob( PolyFrame) ; - vtN1.ToGlob( PolyFrame) ; - vtN2.ToGlob( PolyFrame) ; - return true ; - } - else + if ( nIntNum != 2) return false ; + + // Porto i punti e i versori nel riferimento globale + ptInt1.ToGlob( PolyFrame) ; + ptInt2.ToGlob( PolyFrame) ; + vtN1.ToGlob( PolyFrame) ; + vtN2.ToGlob( PolyFrame) ; + return true ; } //---------------------------------------------------------------------------- diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index e25cccc..fbbeb0a 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -30,29 +30,28 @@ bool VolZmap::SubtractIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ, double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) { - const double dTol = EPS_ZERO ; - // Controllo che dMin e dMax non siano quasi coincidenti - if ( abs( dMax - dMin) < dTol) + if ( abs( dMax - dMin) < EPS_ZERO) return true ; // Controllo che il numero di griglia sia entro i limiti - if ( nGrid < 0 || nGrid > 2) + if ( nGrid < 0 || nGrid > 2) + return false ; + + // Controllo che gli indici nI, nJ siano entro i limiti + if ( nI < 0 || nI >= m_nNx[nGrid] || + nJ < 0 || nJ >= m_nNy[nGrid]) return false ; // Controllo che dMin < dMax - if ( dMin > dMax) - swap( dMin, dMax) ; - - // Controllo che indici nI, nJ siano entro i limiti - if ( nI < 0 && nI >= m_nNx[nGrid] && - nJ < 0 && nJ >= m_nNy[nGrid]) - return false ; - - // Riporto le coordinate cicliche nell'ordine di partenza Vector3d vtNmi = vtNMin ; Vector3d vtNma = vtNMax ; - // Passo dalla griglia al sistema intrinseco + if ( dMin > dMax) { + swap( dMin, dMax) ; + swap( vtNmi, vtNma) ; + } + + // Riporto le coordinate cicliche delle normali nell'ordine di partenza (da griglia a sistema intrinseco) if ( nGrid == 1) { swap( vtNmi.x, vtNmi.z) ; swap( vtNmi.y, vtNmi.z) ; @@ -66,257 +65,171 @@ VolZmap::SubtractIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ swap( vtNma.x, vtNma.z) ; } - // Calcolo nPos + // Recupero dexel da modificare unsigned int nPos = nJ * m_nNx[nGrid] + nI ; + vector& vDexel = m_Values[nGrid][nPos] ; - // Ciclo sugli intervalli del singolo dexel + // Ciclo sugli intervalli del dexel (ordinati in senso crescente) bool bModified = false ; - unsigned int i = 0 ; - - while ( i < m_Values[nGrid][nPos].size()) { - // Casi: - // Intervallo da sottrarre è tutto a sinistra di quello corrente, non vi è intersezione - if ( m_Values[nGrid][nPos][i].dMin > dMax - dTol) { + for ( int i = 0 ; i < int( vDexel.size()) ; ++i) { + // Se interseca l'intervallo corrente + if ( dMin < vDexel[i].dMax - EPS_ZERO && dMax > vDexel[i].dMin + EPS_ZERO) { + bModified = true ; + // se devo limitarlo inferiormente + if ( dMin <= vDexel[i].dMin + EPS_ZERO && dMax < vDexel[i].dMax - EPS_ZERO) { + vDexel[i].dMin = dMax ; + vDexel[i].vtMinN = vtNma ; + vDexel[i].nToolMin = m_Tool.GetCurrentToolNum() ; + } + // se devo limitarlo superiormente + else if ( dMin > vDexel[i].dMin + EPS_ZERO && dMax >= vDexel[i].dMax - EPS_ZERO) { + vDexel[i].dMax = dMin ; + vDexel[i].vtMaxN = vtNmi ; + vDexel[i].nToolMax = m_Tool.GetCurrentToolNum() ; + } + // se devo dividerlo in due parti + else if ( dMin > vDexel[i].dMin + EPS_ZERO && dMax < vDexel[i].dMax - EPS_ZERO) { + // inserisco nuovo intervallo (parte superiore) + vDexel.insert( vDexel.begin() + i + 1, + { dMax, vtNma, m_Tool.GetCurrentToolNum(), + vDexel[i].dMax, vDexel[i].vtMaxN, vDexel[i].nToolMax, + vDexel[i].nCompo}) ; + // aggiorno il vecchio (parte inferiore) + vDexel[i].dMax = dMin ; + vDexel[i].vtMaxN = vtNmi ; + vDexel[i].nToolMax = m_Tool.GetCurrentToolNum() ; + ++ i ; + } + // altrimenti devo eliminarlo + else { + vDexel.erase( vDexel.begin() + i) ; + -- i ; + } + } + // se è tutto minore dell'intervallo corrente, ho finito + else if ( dMax <= vDexel[i].dMin + EPS_ZERO) + break ; + // altrimenti è tutto maggiore dell'intervallo corrente, passo al successivo + else // dMin >= vDexel[i].dMax - EPS_ZERO ; - } - // Intersezione - else if ( m_Values[nGrid][nPos][i].dMax > dMax + dTol) { - // L'intervallo corrente viene limitato a sinistra - if ( m_Values[nGrid][nPos][i].dMin > dMin - dTol) { - bModified = true ; - // Aggiornamento dati del tratto di dexel - m_Values[nGrid][nPos][i].dMin = dMax ; - m_Values[nGrid][nPos][i].vtMinN = vtNma ; - m_Values[nGrid][nPos][i].nToolMin = m_Tool.GetCurrentToolNum() ; - } - // L'intervallo si divide in due intervalli - else { - bModified = true ; - // Aumento la dimensione del dexel - m_Values[nGrid][nPos].resize( m_Values[nGrid][nPos].size() + 1) ; - - size_t nStartT = max( 0, int( m_Values[nGrid][nPos].size()) - 1) ; - - // Sposto i tratti successivi a quello corrente in avanti di una posizione - for ( size_t j = nStartT ; j >= i + 2 ; -- j) { - // Quote estreme - m_Values[nGrid][nPos][j].dMax = m_Values[nGrid][nPos][j - 1].dMax ; - m_Values[nGrid][nPos][j].dMin = m_Values[nGrid][nPos][j - 1].dMin ; - // Normali - m_Values[nGrid][nPos][j].vtMaxN = m_Values[nGrid][nPos][j - 1].vtMaxN ; - m_Values[nGrid][nPos][j].vtMinN = m_Values[nGrid][nPos][j - 1].vtMinN ; - // Numero utensile - m_Values[nGrid][nPos][j].nToolMax = m_Values[nGrid][nPos][j - 1].nToolMax ; - m_Values[nGrid][nPos][j].nToolMin = m_Values[nGrid][nPos][j - 1].nToolMin ; - // Indice di componente - m_Values[nGrid][nPos][j].nCompo = m_Values[nGrid][nPos][j - 1].nCompo ; - } - - // Divido in due il tratto corrente - - // Parte superiore - m_Values[nGrid][nPos][i + 1].dMax = m_Values[nGrid][nPos][i].dMax ; - m_Values[nGrid][nPos][i + 1].vtMaxN = m_Values[nGrid][nPos][i].vtMaxN ; - m_Values[nGrid][nPos][i + 1].nToolMax = m_Values[nGrid][nPos][i].nToolMax ; - m_Values[nGrid][nPos][i + 1].dMin = dMax ; - m_Values[nGrid][nPos][i + 1].vtMinN = vtNma ; - m_Values[nGrid][nPos][i + 1].nToolMin = m_Tool.GetCurrentToolNum() ; - m_Values[nGrid][nPos][i + 1].nCompo = m_Values[nGrid][nPos][i].nCompo ; - - // Parte inferiore - m_Values[nGrid][nPos][i].dMax = dMin ; - m_Values[nGrid][nPos][i].vtMaxN = vtNmi ; - m_Values[nGrid][nPos][i].nToolMax = m_Tool.GetCurrentToolNum() ; - - i = i + 1 ; - } - } - - else { - // L'intervallo corrente viene eliminato - if ( m_Values[nGrid][nPos][i].dMin > dMin - dTol) { - bModified = true ; - // Sposto i tratti successivi a quello corrente indietro di una posizione - for ( unsigned int j = i ; j < m_Values[nGrid][nPos].size() - 1 ; ++ j) { - - m_Values[nGrid][nPos][j].dMin = m_Values[nGrid][nPos][j + 1].dMin ; - m_Values[nGrid][nPos][j].dMax = m_Values[nGrid][nPos][j + 1].dMax ; - - m_Values[nGrid][nPos][j].vtMinN = m_Values[nGrid][nPos][j + 1].vtMinN ; - m_Values[nGrid][nPos][j].vtMaxN = m_Values[nGrid][nPos][j + 1].vtMaxN ; - - m_Values[nGrid][nPos][j].nToolMin = m_Values[nGrid][nPos][j + 1].nToolMin ; - m_Values[nGrid][nPos][j].nToolMax = m_Values[nGrid][nPos][j + 1].nToolMax ; - - m_Values[nGrid][nPos][j].nCompo = m_Values[nGrid][nPos][j + 1].nCompo ; - } - - // Riduco la dimensione del dexel - m_Values[nGrid][nPos].resize( m_Values[nGrid][nPos].size() - 1) ; - - i = i - 1 ; - } - // L'intervallo corrente viene limitato a destra - else if ( m_Values[nGrid][nPos][i].dMax > dMin + dTol) { - bModified = true ; - m_Values[nGrid][nPos][i].dMax = dMin ; - m_Values[nGrid][nPos][i].vtMaxN = vtNmi ; - m_Values[nGrid][nPos][i].nToolMax = m_Tool.GetCurrentToolNum() ; - } - // L'intervallo da sottrarre è tutto a destra di quello corrente, non vi è intersezione - else { - ; - } - } - - i = i + 1 ; } - // Se eseguita modifica, imposto ricalcolo della grafica - if ( bModified) { + // Se nessuna modifica, esco + if ( ! bModified) + return true ; - // Imposto forma generica - m_nShape = GENERIC ; + // Imposto ricalcolo della grafica + m_OGrMgr.Reset() ; + // Imposto forma generica + m_nShape = GENERIC ; + // Imposto ricalcolo numero di componenti connesse + m_nConnectedCompoCount = - 1 ; - // Dichiaro numero di componenti connesse da ricalcolare - m_nConnectedCompoCount = - 1 ; + // Passo da indici di dexel a indici di voxel + nI /= N_DEXVOXRATIO ; + nJ /= N_DEXVOXRATIO ; - // Determino quali blocchi sono stati modificati - int nLayerBlock = m_nFracLin[0] * m_nFracLin[1] ; - - if ( nGrid == 0) { - - int nXStop = 1 ; - int nYStop = 1 ; - - int nXBlock[2] ; - int nYBlock[2] ; - - // Passo dal dexel al voxel - nI /= N_DEXVOXRATIO ; - nJ /= N_DEXVOXRATIO ; - - nXBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[0] - 1) ; - nYBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[1] - 1) ; - - if ( nI % N_VOXBLOCK == 0 && nXBlock[0] > 0) { - nXBlock[1] = nXBlock[0] - 1 ; - ++ nXStop ; - } - - if ( nJ % N_VOXBLOCK == 0 && nYBlock[0] > 0) { - nYBlock[1] = nYBlock[0] - 1 ; - ++ nYStop ; - } - - // Numero di voxel lungo Z - int nVoxNumZ = int( m_nNy[1] / N_DEXVOXRATIO + ( m_nNy[1] % N_DEXVOXRATIO == 0 ? 1 : 2)) ; - - int nMinK = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) - EPS_SMALL))), 0, nVoxNumZ - 2) ; - int nMaxK = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) + EPS_SMALL))), 0, nVoxNumZ - 2) ; - - int nMinZBlock = ( m_nMapNum == 1 ? 0 : Clamp( nMinK / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[2] - 1))) ; - int nMaxZBlock = min( int( m_nFracLin[2] - 1), nMaxK / int( m_nVoxNumPerBlock)) ; - - for ( int tI = 0 ; tI < nXStop ; ++ tI) { - for ( int tJ = 0 ; tJ < nYStop ; ++ tJ) { - for ( int k = nMinZBlock ; k <= nMaxZBlock ; ++ k) { - int nBlockNum = k * nLayerBlock + nYBlock[tJ] * m_nFracLin[0] + nXBlock[tI] ; - m_BlockToUpdate[nBlockNum] = true ; - } + // Determino quali blocchi sono stati modificati + if ( nGrid == 0) { + // Voxel lungo X + int nXStop = 1 ; + int nXBlock[2] ; + nXBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[0] - 1) ; + if ( nI % N_VOXBLOCK == 0 && nXBlock[0] > 0) { + nXBlock[1] = nXBlock[0] - 1 ; + ++ nXStop ; + } + // Voxel lungo Y + int nYStop = 1 ; + int nYBlock[2] ; + nYBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[1] - 1) ; + if ( nJ % N_VOXBLOCK == 0 && nYBlock[0] > 0) { + nYBlock[1] = nYBlock[0] - 1 ; + ++ nYStop ; + } + // Voxel lungo Z + int nVoxNumZ = int( m_nNy[1] / N_DEXVOXRATIO + ( m_nNy[1] % N_DEXVOXRATIO == 0 ? 1 : 2)) ; + int nMinK = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) - EPS_SMALL))), 0, nVoxNumZ - 2) ; + int nMaxK = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) + EPS_SMALL))), 0, nVoxNumZ - 2) ; + int nMinZBlock = ( m_nMapNum == 1 ? 0 : Clamp( nMinK / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[2] - 1))) ; + int nMaxZBlock = min( int( m_nFracLin[2] - 1), nMaxK / int( m_nVoxNumPerBlock)) ; + // Assegno flag ai voxel + for ( int tI = 0 ; tI < nXStop ; ++ tI) { + for ( int tJ = 0 ; tJ < nYStop ; ++ tJ) { + for ( int k = nMinZBlock ; k <= nMaxZBlock ; ++ k) { + int nBlockNum = k * m_nFracLin[0] * m_nFracLin[1] + nYBlock[tJ] * m_nFracLin[0] + nXBlock[tI] ; + m_BlockToUpdate[nBlockNum] = true ; } } } + } - else if ( nGrid == 1) { - - int nYStop = 1 ; - int nZStop = 1 ; - - int nYBlock[2] ; - int nZBlock[2] ; - - // Passo dal dexel al voxel - nI /= N_DEXVOXRATIO ; - nJ /= N_DEXVOXRATIO ; - - nYBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[1] - 1) ; - nZBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[2] - 1) ; - - if ( nI % N_VOXBLOCK == 0 && nYBlock[0] > 0) { - nYBlock[1] = nYBlock[0] - 1 ; - ++ nYStop ; - } - - if ( nJ % N_VOXBLOCK == 0 && nZBlock[0] > 0) { - nZBlock[1] = nZBlock[0] - 1 ; - ++ nZStop ; - } - - // Numero di voxel lungo X - int nVoxNumX = int( m_nNx[0] / N_DEXVOXRATIO + ( m_nNx[0] % N_DEXVOXRATIO == 0 ? 1 : 2)) ; - - int nMinI = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) - EPS_SMALL))), 0, nVoxNumX - 2) ; - int nMaxI = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) + EPS_SMALL))), 0, nVoxNumX - 2) ; - - int nMinXBlock = Clamp( nMinI / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[0] - 1)) ; - int nMaxXBlock = min( int( m_nFracLin[0] - 1), nMaxI / int( m_nVoxNumPerBlock)) ; - - for ( int tI = 0 ; tI < nYStop ; ++ tI) { - for ( int tJ = 0 ; tJ < nZStop ; ++ tJ) { - for ( int k = nMinXBlock ; k <= nMaxXBlock ; ++ k) { - int nBlockNum = nZBlock[tJ] * nLayerBlock + nYBlock[tI] * m_nFracLin[0] + k ; - m_BlockToUpdate[nBlockNum] = true ; - } - } - } + else if ( nGrid == 1) { + // Voxel lungo Y + int nYStop = 1 ; + int nYBlock[2] ; + nYBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[1] - 1) ; + if ( nI % N_VOXBLOCK == 0 && nYBlock[0] > 0) { + nYBlock[1] = nYBlock[0] - 1 ; + ++ nYStop ; } - - else if ( nGrid == 2) { - - int nXStop = 1 ; - int nZStop = 1 ; - - int nXBlock[2] ; - int nZBlock[2] ; - - // Passo dal dexel al voxel - nI /= N_DEXVOXRATIO ; - nJ /= N_DEXVOXRATIO ; - - nXBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[0] - 1) ; - nZBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[2] - 1) ; - - if ( nJ % N_VOXBLOCK == 0 && nXBlock[0] > 0) { - nXBlock[1] = nXBlock[0] - 1 ; - ++ nXStop ; - } - - if ( nI % N_VOXBLOCK == 0 && nZBlock[0] > 0) { - nZBlock[1] = nZBlock[0] - 1 ; - ++ nZStop ; - } - - // Numero di voxel lungo Y - int nVoxNumY = int( m_nNy[0] / N_DEXVOXRATIO + ( m_nNy[0] % N_DEXVOXRATIO == 0 ? 1 : 2)) ; - - int nMinJ = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) - EPS_SMALL))), 0, nVoxNumY - 2) ; - int nMaxJ = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) + EPS_SMALL))), 0, nVoxNumY - 2) ; - - int nMinYBlock = Clamp( nMinJ / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[1] - 1)) ; - int nMaxYBlock = min( int( m_nFracLin[1] - 1), nMaxJ / int( m_nVoxNumPerBlock)) ; - - for ( int tI = 0 ; tI < nZStop ; ++ tI) { - for ( int tJ = 0 ; tJ < nXStop ; ++ tJ) { - for ( int k = nMinYBlock ; k <= nMaxYBlock ; ++ k) { - int nBlockNum = nZBlock[tI] * nLayerBlock + k * m_nFracLin[0] + nXBlock[tJ] ; - m_BlockToUpdate[nBlockNum] = true ; - } - } - } + // Voxel lungo Z + int nZStop = 1 ; + int nZBlock[2] ; + nZBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[2] - 1) ; + if ( nJ % N_VOXBLOCK == 0 && nZBlock[0] > 0) { + nZBlock[1] = nZBlock[0] - 1 ; + ++ nZStop ; } + // Voxel lungo X + int nVoxNumX = int( m_nNx[0] / N_DEXVOXRATIO + ( m_nNx[0] % N_DEXVOXRATIO == 0 ? 1 : 2)) ; + int nMinI = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) - EPS_SMALL))), 0, nVoxNumX - 2) ; + int nMaxI = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) + EPS_SMALL))), 0, nVoxNumX - 2) ; + int nMinXBlock = Clamp( nMinI / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[0] - 1)) ; + int nMaxXBlock = min( int( m_nFracLin[0] - 1), nMaxI / int( m_nVoxNumPerBlock)) ; + // Assegno flag ai voxel + for ( int tI = 0 ; tI < nYStop ; ++ tI) { + for ( int tJ = 0 ; tJ < nZStop ; ++ tJ) { + for ( int k = nMinXBlock ; k <= nMaxXBlock ; ++ k) { + int nBlockNum = nZBlock[tJ] * m_nFracLin[0] * m_nFracLin[1] + nYBlock[tI] * m_nFracLin[0] + k ; + m_BlockToUpdate[nBlockNum] = true ; + } + } + } + } - m_OGrMgr.Reset() ; + else if ( nGrid == 2) { + // Voxel lungo X + int nXStop = 1 ; + int nXBlock[2] ; + nXBlock[0] = min( nJ / m_nVoxNumPerBlock, m_nFracLin[0] - 1) ; + if ( nJ % N_VOXBLOCK == 0 && nXBlock[0] > 0) { + nXBlock[1] = nXBlock[0] - 1 ; + ++ nXStop ; + } + // Voxel lungo Z + int nZStop = 1 ; + int nZBlock[2] ; + nZBlock[0] = min( nI / m_nVoxNumPerBlock, m_nFracLin[2] - 1) ; + if ( nI % N_VOXBLOCK == 0 && nZBlock[0] > 0) { + nZBlock[1] = nZBlock[0] - 1 ; + ++ nZStop ; + } + // Voxel lungo Y + int nVoxNumY = int( m_nNy[0] / N_DEXVOXRATIO + ( m_nNy[0] % N_DEXVOXRATIO == 0 ? 1 : 2)) ; + int nMinJ = Clamp( int( floor( ( ( dMin - 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) - EPS_SMALL))), 0, nVoxNumY - 2) ; + int nMaxJ = Clamp( int( floor( ( ( dMax + 0.5 * m_dStep) / ( N_DEXVOXRATIO * m_dStep) + EPS_SMALL))), 0, nVoxNumY - 2) ; + int nMinYBlock = Clamp( nMinJ / int( m_nVoxNumPerBlock), 0, int( m_nFracLin[1] - 1)) ; + int nMaxYBlock = min( int( m_nFracLin[1] - 1), nMaxJ / int( m_nVoxNumPerBlock)) ; + // Assegno flag ai voxel + for ( int tI = 0 ; tI < nZStop ; ++ tI) { + for ( int tJ = 0 ; tJ < nXStop ; ++ tJ) { + for ( int k = nMinYBlock ; k <= nMaxYBlock ; ++ k) { + int nBlockNum = nZBlock[tI] * m_nFracLin[0] * m_nFracLin[1] + k * m_nFracLin[0] + nXBlock[tJ] ; + m_BlockToUpdate[nBlockNum] = true ; + } + } + } } return true ; @@ -1355,8 +1268,6 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p // Punta a trapano if ( m_Tool.GetTipRadius() < m_Tool.GetRadius()) { - double dMin, dMax ; - Vector3d vtV = vtToolDir ; Point3d ptVS = ptS - vtToolDir * ( dStemHeigth + dL) ; @@ -1385,8 +1296,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p if ( dSqLenS < dSqMinRad || dSqLenE < dSqMinRad || ( abs( dP2) < dMinRad && dP1 >= 0 && dP1 <= dLen)) { - dMin = min( dBaseZ, dTipZ) ; - dMax = max( dBaseZ, dTipZ) ; + double dMin = min( dBaseZ, dTipZ) ; + double dMax = max( dBaseZ, dTipZ) ; SubtractIntervals( nGrid, i, j, dMin, dMax, Z_AX, - Z_AX) ; } @@ -1398,8 +1309,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p double dr = sqrt( dSqLenS) ; - dMin = min( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; - dMax = max( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMin = min( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMax = max( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; if ( vtToolDir.z > 0) { Point3d ptInt( dX, dY, dMin) ; @@ -1423,8 +1334,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p else if ( dP1 <= dLen) { double dr = abs( dP2) ; - dMin = min( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; - dMax = max( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMin = min( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMax = max( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; Point3d ptVtemp = ptVS + vtV1 * dP1 ; if ( vtToolDir.z > 0) { @@ -1452,8 +1363,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p double dr = sqrt( dSqLenE) ; - dMin = min( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; - dMax = max( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMin = min( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMax = max( dBaseZ, dTipZ + ( dStemZ - dTipZ) * ( dr - dMinRad) / dDeltaRad) ; if ( vtToolDir.z > 0) { Point3d ptInt( dX, dY, dMin) ; @@ -1483,7 +1394,6 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p // Coda di rondine else { - double dMin, dMax ; Vector3d vtV = - vtToolDir ; @@ -1512,8 +1422,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p if ( dSqLenS < dSafeSqMinRad || dSqLenE < dSafeSqMinRad || ( abs( dP2) < dSafeMinRad && dP1 >= 0 && dP1 <= dLen)) { - dMin = min( dBaseZ, dTipZ) ; - dMax = max( dBaseZ, dTipZ) ; + double dMin = min( dBaseZ, dTipZ) ; + double dMax = max( dBaseZ, dTipZ) ; SubtractIntervals( nGrid, i, j, dMin, dMax, Z_AX, - Z_AX) ; } @@ -1522,8 +1432,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p if ( dP1 < 0) { double dr = sqrt( dSqLenS) ; - dMin = min( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; - dMax = max( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMin = min( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMax = max( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; if ( vtToolDir.z > 0) { Point3d ptInt( dX, dY, dMax) ; @@ -1548,8 +1458,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p else if ( dP1 <= dLen) { double dr = abs( dP2) ; Point3d ptVtemp = ptVS + vtV1 * dP1 ; - dMin = min( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; - dMax = max( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMin = min( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMax = max( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; if ( vtToolDir.z > 0) { Point3d ptInt( dX, dY, dMax) ; @@ -1574,8 +1484,8 @@ VolZmap::Conus_ZPerp( unsigned int nGrid, const Point3d & ptS, const Point3d & p else { double dr = sqrt( dSqLenE) ; - dMin = min( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; - dMax = max( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMin = min( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; + double dMax = max( dTipZ, dStemZ + ( dTipZ - dStemZ) * ( dr - dMinRad) / dDeltaRad) ; if ( vtToolDir.z > 0) { Point3d ptInt( dX, dY, dMax) ; @@ -2293,7 +2203,6 @@ VolZmap::Conus_XYDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d // Verifica sull'interferenza utensile Zmap unsigned int nStartI, nStartJ, nEndI, nEndJ ; bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; - if ( ! bTest) return true ; @@ -2358,12 +2267,11 @@ VolZmap::Conus_XYDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d double dMax = ptI.z + dH ; Point3d ptIntMin( dX, dY, dMin) ; - Point3d ptIntMax( dX, dY, dMax) ; - Vector3d vtNmin = ( ptI - ptIntMin) - ( ptI - ptIntMin) * vtV1 * vtV1 ; - Vector3d vtNmax = ( ptI - ptIntMax) - ( ptI - ptIntMax) * vtV1 * vtV1 ; - vtNmin.Normalize() ; + + Point3d ptIntMax( dX, dY, dMax) ; + Vector3d vtNmax = ( ptI - ptIntMax) - ( ptI - ptIntMax) * vtV1 * vtV1 ; vtNmax.Normalize() ; SubtractIntervals( nGrid, i, j, ptI.z - dH, ptI.z + dH, vtNmin, vtNmax) ; @@ -2378,18 +2286,15 @@ VolZmap::Conus_XYDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d double dMax = ptI.z + dH ; Point3d ptIntMin( dX, dY, dMin) ; - Point3d ptIntMax( dX, dY, dMax) ; - Vector3d vtUmin = ( ptIntMin - ptV) - ( ptIntMin - ptV) * vtV * vtV ; - Vector3d vtUmax = ( ptIntMax - ptV) - ( ptIntMax - ptV) * vtV * vtV ; - vtUmin.Normalize() ; - vtUmax.Normalize() ; - Vector3d vtNmin = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtUmin ; - Vector3d vtNmax = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtUmax ; - vtNmin.Normalize() ; + + Point3d ptIntMax( dX, dY, dMax) ; + Vector3d vtUmax = ( ptIntMax - ptV) - ( ptIntMax - ptV) * vtV * vtV ; + vtUmax.Normalize() ; + Vector3d vtNmax = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtUmax ; vtNmax.Normalize() ; SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; @@ -2406,12 +2311,11 @@ VolZmap::Conus_XYDrilling( unsigned int nGrid, const Point3d& ptS, const Point3d double dMax = ptI.z + dH ; Point3d ptIntMin( dX, dY, dMin) ; - Point3d ptIntMax( dX, dY, dMax) ; - Vector3d vtNmin = ( ptI - ptIntMin) - ( ptI - ptIntMin) * vtV1 * vtV1 ; - Vector3d vtNmax = ( ptI - ptIntMax) - ( ptI - ptIntMax) * vtV1 * vtV1 ; - vtNmin.Normalize() ; + + Point3d ptIntMax( dX, dY, dMax) ; + Vector3d vtNmax = ( ptI - ptIntMax) - ( ptI - ptIntMax) * vtV1 * vtV1 ; vtNmax.Normalize() ; SubtractIntervals( nGrid, i, j, ptI.z - dH, ptI.z + dH, vtNmin, vtNmax) ; @@ -2429,7 +2333,6 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt // Verifica sull'interferenza utensile Zmap unsigned int nStartI, nStartJ, nEndI, nEndJ ; bool bTest = BoundingBox( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ) ; - if ( ! bTest) return true ; @@ -2495,12 +2398,11 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt double dMax = dZF + sqrt( dSqRad - dP2 * dP2) ; Point3d ptIntMin( dX, dY, dMin) ; - Point3d ptIntMax( dX, dY, dMax) ; - Vector3d vtNmin = - ( ptIntMin - ptI) + ( ptIntMin - ptI) * vtV1 * vtV1 ; - Vector3d vtNmax = - ( ptIntMax - ptF) + ( ptIntMax - ptF) * vtV1 * vtV1 ; - vtNmin.Normalize() ; + + Point3d ptIntMax( dX, dY, dMax) ; + Vector3d vtNmax = - ( ptIntMax - ptF) + ( ptIntMax - ptF) * vtV1 * vtV1 ; vtNmax.Normalize() ; SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; @@ -2517,18 +2419,15 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt double dMax = dZF + sqrt( dMr * dMr - dr * dr) ; Point3d ptIntMin( dX, dY, dMin) ; - Point3d ptIntMax( dX, dY, dMax) ; - Vector3d vtUmin = ( ptIntMin - ptVI) - ( ptIntMin - ptVI) * vtV * vtV ; - Vector3d vtUmax = ( ptIntMax - ptVF) - ( ptIntMax - ptVF) * vtV * vtV ; - vtUmin.Normalize() ; - vtUmax.Normalize() ; - Vector3d vtNmin = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtUmin ; - Vector3d vtNmax = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtUmax ; - vtNmin.Normalize() ; + + Point3d ptIntMax( dX, dY, dMax) ; + Vector3d vtUmax = ( ptIntMax - ptVF) - ( ptIntMax - ptVF) * vtV * vtV ; + vtUmax.Normalize() ; + Vector3d vtNmax = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtUmax ; vtNmax.Normalize() ; SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; @@ -2661,11 +2560,8 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt ptInt.Set( dX, dY, dMax) ; Vector3d vtU = ( ptInt - ptVI) - ( ptInt - ptVI) * vtV * vtV ; - vtU.Normalize() ; - vtNmax = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtU ; - vtNmax.Normalize() ; } @@ -2684,11 +2580,8 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt ptInt.Set( dX, dY, dMax) ; Vector3d vtU = ( ptInt - ptVF) - ( ptInt - ptVF) * vtV * vtV ; - vtU.Normalize() ; - vtNmax = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtU ; - vtNmax.Normalize() ; } @@ -2703,11 +2596,8 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt ptInt.Set( dX, dY, dMin) ; Vector3d vtU = ( ptInt - ptVI) - ( ptInt - ptVI) * vtV * vtV ; - vtU.Normalize() ; - vtNmin = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtU ; - vtNmin.Normalize() ; } @@ -2726,11 +2616,8 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt ptInt.Set( dX, dY, dMin) ; Vector3d vtU = ( ptInt - ptVF) - ( ptInt - ptVF) * vtV * vtV ; - vtU.Normalize() ; - vtNmin = dDeltaRad * vtV - m_Tool.GetTipHeigth() * vtU ; - vtNmin.Normalize() ; } @@ -2744,7 +2631,7 @@ VolZmap::Conus_XYPerp( unsigned int nGrid, const Point3d& ptS, const Point3d& pt //---------------------------------------------------------------------------- bool -VolZmap::Conus_XYMilling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir) +VolZmap::Conus_XYMilling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir) { double dStemHeigth = m_Tool.GetHeigth() - m_Tool.GetTipHeigth() ; @@ -3299,11 +3186,8 @@ VolZmap::CompConus_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Poi Point3d ptInt( dX, dY, dMin) ; Vector3d vtU = ( ptInt - ptV) - ( ptInt - ptV) * vtToolDir * vtToolDir ; - vtU.Normalize() ; - vtMin = dDeltaR * vtToolDir - dHei * vtU ; - vtMin.Normalize() ; SubtractIntervals( nGrid, i, j, dMin, dMax, vtMin, vtMax) ; @@ -3318,11 +3202,8 @@ VolZmap::CompConus_ZDrilling( unsigned int nGrid, const Point3d & ptS, const Poi Point3d ptInt( dX, dY, dMax) ; Vector3d vtU = ( ptInt - ptV) - ( ptInt - ptV) * vtToolDir * vtToolDir ; - vtU.Normalize() ; - vtMax = dDeltaR * vtToolDir - dHei * vtU ; - vtMax.Normalize() ; SubtractIntervals( nGrid, i, j, dMin, dMax, vtMin, vtMax) ; @@ -3471,7 +3352,6 @@ VolZmap::CompCyl_ZMilling( unsigned int nGrid, const Point3d & ptS, const Point3 double dX1_0 = sqrt( dSqRad - dX2 * dX2) ; // Massimo if ( ( dX1 - dLenXY) * ( dX1 - dLenXY) + dX2 * dX2 < dSqRad) { - dMax = dZMaxF ; vtMax = - Z_AX ; } @@ -3897,22 +3777,8 @@ VolZmap::CompCyl_Drilling( unsigned int nGrid, const Point3d& ptS, const Point3d Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; - if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dH, dRad, bTapB, bTapT, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dH, dRad, bTapB, bTapT, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } @@ -3960,42 +3826,14 @@ VolZmap::CompConus_Drilling( unsigned int nGrid, const Point3d& ptS, const Point // Cilindro if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dH, dMaxRad, true, bTapCylEn, - ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Cono if ( IntersLineConus( ptC, Z_AX, ConusFrame, dTan, dConeMinH, dConeMaxH, bTapT, true, - ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } @@ -4042,25 +3880,8 @@ VolZmap::CompPar_Drilling( unsigned int nGrid, double dLenX, double dLenY, doubl Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; - if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ + dLenMove, 0, ptInt1, ptInt2, vtN1, vtN2)) { - - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ + dLenMove, 0, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } @@ -4117,105 +3938,40 @@ VolZmap::CompCyl_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& Vector3d vtN1, vtN2 ; // Cilindro iniziale - if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dHei, dRad, bCylSt, bCylEn, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + CylFrame.ChangeOrig( ptITip) ; + if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dHei, dRad, bCylSt, bCylEn, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Cilindro finale:L'unica differenza rispetto a prima è l'origine // del sistema di riferimento, quindi usiamo lo stesso sistema sommando a ptC // il vettore che congiunge le due origini. - if ( IntersLineCylinder( ptC - vtMove, Z_AX, CylFrame, dHei, dRad, bCylSt, bCylEn, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + vtMove.z ; - dMax = ptInt2.z + vtMove.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + vtMove.z ; - dMax = ptInt1.z + vtMove.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + CylFrame.ChangeOrig( ptITip + vtMove) ; + if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dHei, dRad, bCylSt, bCylEn, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Poliedro interno - if ( IntersLineMyPolyhedron( ptC, Z_AX, CylFrame, dOrtLen, 2 * dRad, dHei, - dLongLen, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + CylFrame.ChangeOrig( ptITip) ; + if ( IntersLineMyPolyhedron( ptC, Z_AX, CylFrame, dOrtLen, 2 * dRad, dHei, + dLongLen, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Cilindro ellittico di punta - if ( IntersLineEllipticalCylinder( Z_AX, ptC, CylFrame, dRad, dLongLen, dOrtLen, - bElpsT, bElpsT, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + CylFrame.ChangeOrig( ptITip) ; + if ( IntersLineEllipticalCylinder( ptC, Z_AX, CylFrame, dRad, dLongLen, dOrtLen, + bElpsT, bElpsT, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Cilindro ellittico di base: L'unica differenza rispetto a prima è l'origine // del sistema di riferimento, quindi usiamo lo stesso sistema sommando a ptC // il vettore che congiunge le due origini. - if ( IntersLineEllipticalCylinder( Z_AX, ptC - dHei * vtV1, CylFrame, dRad, dLongLen, dOrtLen, - bElpsB, bElpsB, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + dHei * vtV1.z ; - dMax = ptInt2.z + dHei * vtV1.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + dHei * vtV1.z ; - dMax = ptInt1.z + dHei * vtV1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + CylFrame.ChangeOrig( ptITip + dHei * vtV1) ; + if ( IntersLineEllipticalCylinder( ptC, Z_AX, CylFrame, dRad, dLongLen, dOrtLen, + bElpsB, bElpsB, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } @@ -4224,13 +3980,12 @@ VolZmap::CompCyl_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& //---------------------------------------------------------------------------- bool -VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point3d & ptE, const Vector3d & vtToolDir, +VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d& ptS, const Point3d& ptE, const Vector3d& vtToolDir, double dHei, double dMaxRad, double dMinRad, bool bTapB, bool bTapT) { + // Verifico interferenza unsigned int nStartI, nStartJ, nEndI, nEndJ ; - bool bInterf = BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, - dMaxRad, dMinRad, dHei) ; - if ( ! bInterf) + if ( ! BBoxComponent( nGrid, ptS, ptE, vtToolDir, nStartI, nStartJ, nEndI, nEndJ, dMaxRad, dMinRad, dHei)) return true ; // Geometria del cono @@ -4243,7 +3998,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point Point3d ptIT = ptI - vtToolDir * dHei ; Point3d ptFT = ptF - vtToolDir * dHei ; - double dL = ( ( dMaxRad * dHei) / ( dDeltaR)) ; + double dL = ( dMaxRad * dHei) / dDeltaR ; double dl = dL - dHei ; Point3d ptV = ptI - vtToolDir * dL ; @@ -4252,7 +4007,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point Vector3d vtMove = ptF - ptI ; Vector3d vtMvLong = ( vtMove * vtToolDir) * vtToolDir ; Vector3d vtMvOrt = vtMove - vtMvLong ; - + // Terna destrorsa e unitaria Vector3d vtV1 = vtToolDir ; Vector3d vtV2 = vtMvOrt ; vtV2.Normalize() ; @@ -4272,7 +4027,6 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point // Per costruire piani laterali poliedro interno double dCos = dTan * dRatio ; double dSin = ( 1 - dCos * dCos > 0 ? sqrt( 1 - dCos * dCos) : 0) ; - double dDen = sqrt( 1 + dTan * dTan) ; // Dimensioni lineari descriventi il poliedro interno double dLenX = dLongLen ; @@ -4284,34 +4038,26 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point // Sistema di riferimento poliedro Point3d ptO = ptV + vtV1 * dl + vtV2 * ( dCos * dMinRad) ; + Frame3d PolyFrame ; + PolyFrame.Set( ptO, vtV1, vtV2, vtV3) ; - Frame3d PolyFrame ; PolyFrame.Set( ptO, vtV1, vtV2, vtV3) ; - - // Versori piani nel riferimento poliedro - // (Sx, Dx, Iniziale, Finale, Up, Down sono riferiti - // al sistema di riferimento): - + // Versori piani nel riferimento poliedro ( riferiti al sistema di riferimento) : // Sx, Dx - Vector3d vtNs( - ( dTan / dDen), ( dCos / dDen), ( dSin / dDen)) ; - Vector3d vtNd( - ( dTan / dDen), ( dCos / dDen), - ( dSin / dDen)) ; - + Vector3d vtNs( - dTan, dCos, dSin) ; + vtNs.Normalize() ; + Vector3d vtNd( - dTan, dCos, - dSin) ; + vtNd.Normalize() ; // Iniziale e finale Vector3d vtIF( - dDeltaY, dDeltaX, 0) ; - + vtIF.Normalize() ; // Up e Down Vector3d vtUD( - dLenY, dLenX, 0) ; - - vtNs.Normalize() ; - vtNd.Normalize() ; - vtIF.Normalize() ; vtUD.Normalize() ; // Punti dei piani (sempre espressi nel sistema PolyFrame) Point3d ptFacet135( 0, 0, dLenZ) ; Point3d ptFacet246( dLenX + dDeltaX, dLenY + dDeltaY, - dLenZ - dDeltaZ) ; - double dSqIndet = EPS_SMALL * EPS_SMALL ; - Vector3d vtUmv = vtMove ; vtUmv.Normalize() ; // Variabili booleane per i tappi @@ -4325,51 +4071,22 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { for ( unsigned int j = nStartJ ; j <= nEndJ ; ++ j) { - double dX = ( i + 0.5) * m_dStep ; - double dY = ( j + 0.5) * m_dStep ; - - Point3d ptC( dX, dY, 0) ; + Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; // Cono iniziale - if ( IntersLineConus( ptC, Z_AX, ConusFrame, dTan, dl, dL, bConeT, bConeB, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ConusFrame.ChangeOrig( ptV) ; + if ( IntersLineConus( ptC, Z_AX, ConusFrame, dTan, dl, dL, bConeT, bConeB, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Cono finale - if ( IntersLineConus( ptC - vtMove, Z_AX, ConusFrame, dTan, dl, dL, bConeT, bConeB, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + vtMove.z ; - dMax = ptInt2.z + vtMove.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + vtMove.z ; - dMax = ptInt1.z + vtMove.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; - } + ConusFrame.ChangeOrig( ptV + vtMove) ; + if ( IntersLineConus( ptC, Z_AX, ConusFrame, dTan, dl, dL, bConeT, bConeB, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; + } // Solido interno Point3d ptPoly = ptC ; @@ -4377,7 +4094,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point ptPoly.ToLoc( PolyFrame) ; vtPoly.ToLoc( PolyFrame) ; - + Point3d ptPoly1 = ptPoly + ( ( ( ptFacet135 - ptPoly) * vtNs) / ( vtPoly * vtNs)) * vtPoly ; Point3d ptPoly2 = ptPoly + ( ( ( ptFacet246 - ptPoly) * vtNd) / ( vtPoly * vtNd)) * vtPoly ; Point3d ptPoly3 = ptPoly + ( ( ( ptFacet135 - ptPoly) * vtIF) / ( vtPoly * vtIF)) * vtPoly ; @@ -4410,7 +4127,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point vtN1 = - vtNd ; ++ nIntNum ; } - else if ( ( ptInt1 - ptPoly2).SqLen() > dSqIndet) { + else if ( ( ptInt1 - ptPoly2).SqLen() > SQ_EPS_SMALL) { ptInt2 = ptPoly2 ; vtN2 = - vtNd ; ++ nIntNum ; @@ -4428,7 +4145,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point vtN1 = vtIF ; ++ nIntNum ; } - else if ( ( ptInt1 - ptPoly3).SqLen() > dSqIndet) { + else if ( ( ptInt1 - ptPoly3).SqLen() > SQ_EPS_SMALL) { ptInt2 = ptPoly3 ; vtN2 = vtIF ; ++ nIntNum ; @@ -4447,7 +4164,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point vtN1 = - vtIF ; ++ nIntNum ; } - else if ( ( ptInt1 - ptPoly4).SqLen() > dSqIndet) { + else if ( ( ptInt1 - ptPoly4).SqLen() > SQ_EPS_SMALL) { ptInt2 = ptPoly4 ; vtN2 = - vtIF ; ++ nIntNum ; @@ -4466,7 +4183,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point vtN1 = - vtUD ; ++ nIntNum ; } - else if ( ( ptInt1 - ptPoly5).SqLen() > dSqIndet) { + else if ( ( ptInt1 - ptPoly5).SqLen() > SQ_EPS_SMALL) { ptInt2 = ptPoly5 ; vtN2 = - vtUD ; ++ nIntNum ; @@ -4485,7 +4202,7 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point vtN1 = vtUD ; ++ nIntNum ; } - else if ( ( ptInt1 - ptPoly6).SqLen() > dSqIndet) { + else if ( ( ptInt1 - ptPoly6).SqLen() > SQ_EPS_SMALL) { ptInt2 = ptPoly6; vtN2 = vtUD ; ++ nIntNum ; @@ -4494,69 +4211,28 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point } // Se il poliedro è attraversato taglio if ( nIntNum == 2) { - + // Riporto le intersezioni nel sistema griglia ptInt1.ToGlob( PolyFrame) ; - ptInt2.ToGlob( PolyFrame) ; - vtN1.ToGlob( PolyFrame) ; + ptInt2.ToGlob( PolyFrame) ; vtN2.ToGlob( PolyFrame) ; - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Traslazione ellisse di punta - if ( IntersLineEllipticalCylinder( Z_AX, ptC - vtV1 * dl, ConusFrame, dMinRad, dLongLen, dOrtLen, - bElpsT, bElpsT, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + vtV1.z * dl ; - dMax = ptInt2.z + vtV1.z * dl ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + vtV1.z * dl ; - dMax = ptInt1.z + vtV1.z * dl ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ConusFrame.ChangeOrig( ptV + vtV1 * dl) ; + if ( IntersLineEllipticalCylinder( ptC, Z_AX, ConusFrame, dMinRad, dLongLen, dOrtLen, + bElpsT, bElpsT, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Traslazione ellisse di base - if ( IntersLineEllipticalCylinder( Z_AX, ptC - vtV1 * dL, ConusFrame, dMaxRad, dLongLen, dOrtLen, - bElpsB, bElpsB, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + vtV1.z * dL ; - dMax = ptInt2.z + vtV1.z * dL ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + vtV1.z * dL ; - dMax = ptInt1.z + vtV1.z * dL ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ConusFrame.ChangeOrig( ptV + vtV1 * dL) ; + if ( IntersLineEllipticalCylinder( ptC, Z_AX, ConusFrame, dMaxRad, dLongLen, dOrtLen, + bElpsB, bElpsB, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } @@ -4566,58 +4242,29 @@ VolZmap::CompConus_Milling( unsigned int nGrid, const Point3d & ptS, const Point else { for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { for ( unsigned int j = nStartJ ; j <= nEndJ ; ++ j) { - - double dX = ( i + 0.5) * m_dStep ; - double dY = ( j + 0.5) * m_dStep ; - Point3d ptC( dX, dY, 0) ; + Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; // Cono - if ( IntersLineConus( ptC, Z_AX, ConusFrame, dTan, dl, dL, bConeT, bConeB, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ConusFrame.ChangeOrig( ptV) ; + if ( IntersLineConus( ptC, Z_AX, ConusFrame, dTan, dl, dL, bConeT, bConeB, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } - // Traslazione ellisse - if ( IntersLineEllipticalCylinder( Z_AX, ptC - vtV1 * dL, ConusFrame, dMaxRad, dLongLen, dOrtLen, - bConeB, bConeB, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + vtV1.z * dL ; - dMax = ptInt2.z + vtV1.z * dL ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + vtV1.z * dL ; - dMax = ptInt1.z + vtV1.z * dL ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + // Traslazione ellisse + ConusFrame.ChangeOrig( ptV + vtV1 * dL) ; + if ( IntersLineEllipticalCylinder( ptC, Z_AX, ConusFrame, dMaxRad, dLongLen, dOrtLen, + bConeB, bConeB, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } return true ; } -} +} //---------------------------------------------------------------------------- bool @@ -4647,7 +4294,8 @@ VolZmap::CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double Vector3d vtV1 = vtAux ^ vtV3 ; Vector3d vtV2 = vtV3 ^ vtV1 ; ParaFrame.Set( ORIG, vtV1, vtV2, vtV3) ; - ParaFrame.ChangeOrig( ptMyS - dLenZ * ParaFrame.VersZ() - ( 0.5 * dLenX) * ParaFrame.VersX()) ; + Point3d ptV = ptMyS - dLenZ * ParaFrame.VersZ() - ( 0.5 * dLenX) * ParaFrame.VersX() ; + ParaFrame.ChangeOrig( ptV) ; // Studio del volume asportato durante il moto Frame3d MotionFrame ; @@ -4666,73 +4314,27 @@ VolZmap::CompPar_Milling( unsigned int nGrid, double dLenX, double dLenY, double for ( unsigned int i = nStartI ; i <= nEndI ; ++ i) { for ( unsigned int j = nStartJ ; j <= nEndJ ; ++ j) { - - double dX = ( i + 0.5) * m_dStep ; - double dY = ( j + 0.5) * m_dStep ; - Point3d ptC( dX, dY, 0) ; + Point3d ptC( ( i + 0.5) * m_dStep, ( j + 0.5) * m_dStep, 0) ; Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; // Solido nella posizione iniziale - if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ParaFrame.ChangeOrig( ptV) ; + if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Solido nella posizione finale - if ( IntersLineMyPolyhedron( ptC - vtMove, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z + vtMove.z ; - dMax = ptInt2.z + vtMove.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z + vtMove.z ; - dMax = ptInt1.z + vtMove.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + ParaFrame.ChangeOrig( ptV + vtMove) ; + if ( IntersLineMyPolyhedron( ptC, Z_AX, ParaFrame, dLenX, dLenY, dLenZ, 0, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } // Volume spazzato nel moto - if ( IntersLineMyPolyhedron( ptC, Z_AX, MotionFrame, dLenW1, dLenZ, dLenW3, dDeltaW3, ptInt1, ptInt2, vtN1, vtN2)) { - double dMin, dMax ; - Vector3d vtNmin, vtNmax ; - if ( ptInt1.z < ptInt2.z) { - dMin = ptInt1.z ; - dMax = ptInt2.z ; - vtNmin = vtN1 ; - vtNmax = vtN2 ; - } - else { - dMin = ptInt2.z ; - dMax = ptInt1.z ; - vtNmin = vtN2 ; - vtNmax = vtN1 ; - } - - SubtractIntervals( nGrid, i, j, dMin, dMax, vtNmin, vtNmax) ; + if ( IntersLineMyPolyhedron( ptC, Z_AX, MotionFrame, dLenW1, dLenZ, dLenW3, dDeltaW3, ptInt1, vtN1, ptInt2, vtN2)) { + SubtractIntervals( nGrid, i, j, ptInt1.z, ptInt2.z, vtN1, vtN2) ; } } } @@ -4801,7 +4403,7 @@ VolZmap::CompBall_Milling( unsigned int nGrid, const Point3d & ptLs, const Point // Cilindro inviluppo della sfera Point3d ptInt1, ptInt2 ; Vector3d vtN1, vtN2 ; - if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dLengthPath, dRad, false, false, ptInt1, ptInt2, vtN1, vtN2)) { + if ( IntersLineCylinder( ptC, Z_AX, CylFrame, dLengthPath, dRad, false, false, ptInt1, vtN1, ptInt2, vtN2)) { double dMin = ptInt1.z ; double dMax = ptInt2.z ; Vector3d vtNmin = vtN1 ; @@ -4873,8 +4475,8 @@ VolZmap::BoundingBox( unsigned int nGrid, const Point3d& ptP1, const Point3d& pt //---------------------------------------------------------------------------- inline bool -VolZmap::BBoxComponent( unsigned int nGrid, const Point3d & ptP1, const Point3d & ptP2, const Vector3d & vtV, - unsigned int & nStI, unsigned int & nStJ, unsigned int & nEnI, unsigned int & nEnJ, +VolZmap::BBoxComponent( unsigned int nGrid, const Point3d& ptP1, const Point3d& ptP2, const Vector3d& vtV, + unsigned int& nStI, unsigned int& nStJ, unsigned int& nEnI, unsigned int& nEnJ, double dRad, double dTipRad, double dHei) { // I punti e i vettori devono essere nel sistema di riferimento opportuno