diff --git a/CurveArc.cpp b/CurveArc.cpp index 027528f..93d3af7 100644 --- a/CurveArc.cpp +++ b/CurveArc.cpp @@ -895,7 +895,7 @@ CurveArc::GetParamAtLength( double dLen, double& dU) const return false ; // fine - if ( dLen < dTotLen - EPS_SMALL) { + if ( dLen > dTotLen - EPS_SMALL) { dU = 1 ; return true ; } diff --git a/CurveBezier.cpp b/CurveBezier.cpp index 049e111..4bd4a64 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -597,11 +597,29 @@ CurveBezier::GetMidPoint( Point3d& ptMid) const // verifico lo stato if ( m_nStatus != OK) return false ; - + // determino il valore del parametro a metà lunghezza + double dLen, dMid ; + if ( ! GetLength( dLen) || ! GetParamAtLength( 0.5 * dLen, dMid)) + return false ; // calcolo il punto - return GetPointD1D2( 0.5, ptMid) ; + return GetPointD1D2( dMid, ptMid) ; } +//---------------------------------------------------------------------------- +bool +CurveBezier::GetMidDir( Vector3d& vtDir) const +{ + // verifico lo stato + if ( m_nStatus != OK) + return false ; + // determino il valore del parametro a metà lunghezza + double dLen, dMid ; + if ( ! GetLength( dLen) || ! GetParamAtLength( 0.5 * dLen, dMid)) + return false ; + // calcolo la direzione + return ::GetTang( *this, dMid, FROM_MINUS, vtDir) ; +} + //---------------------------------------------------------------------------- bool CurveBezier::GetPointD1D2( double dU, Side nS, Point3d& ptPos, Vector3d* pvtDer1, Vector3d* pvtDer2) const @@ -1177,8 +1195,10 @@ CurveBezier::GetParamAtLength( double dLen, double& dU) const double dCurrLen = 0 ; double dUIni = 0 ; double dUFin = 1 ; - while ( ( bOk = GetSegmentParam( dLen, dCurrLen, dSegLen, dUIni, dUFin)) && dSegLen > MIN_SEG_LEN) - ; + while ( ( bOk = GetSegmentParam( dLen, dCurrLen, dSegLen, dUIni, dUFin)) && dSegLen > MIN_SEG_LEN) { + // allungo di un poco l'intervallo di ricerca per compensare l'approssimazione della lunghezza + dUFin = min( dUFin + ( dUFin - dUIni) * 0.05, 1) ; + } // aggiustamento finale parametro if ( bOk) dU = dUIni + ( dLen - dCurrLen) / dSegLen * ( dUFin - dUIni) ; diff --git a/CurveBezier.h b/CurveBezier.h index a5d0b27..648e3ec 100644 --- a/CurveBezier.h +++ b/CurveBezier.h @@ -66,8 +66,7 @@ class CurveBezier : public ICurveBezier, public IGeoObjRW { return ::GetTang( *this, 0, FROM_PLUS, vtDir) ; } virtual bool GetEndDir( Vector3d& vtDir) const { return ::GetTang( *this, 1, FROM_MINUS, vtDir) ; } - virtual bool GetMidDir( Vector3d& vtDir) const - { return ::GetTang( *this, 0.5, FROM_MINUS, vtDir) ; } + virtual bool GetMidDir( Vector3d& vtDir) const ; virtual bool GetExtrusion( Vector3d& vtExtr) const { vtExtr = m_VtExtr ; return ( m_nStatus == OK) ; } virtual bool GetThickness( double& dThick) const diff --git a/CurveComposite.cpp b/CurveComposite.cpp index 4c35f4c..271f52c 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -869,16 +869,29 @@ CurveComposite::GetMidPoint( Point3d& ptMid) const // verifico lo stato if ( m_nStatus != OK) return false ; - - // determino il valore medio del parametro della curva - double dStart, dEnd, dMid ; - GetDomain( dStart, dEnd) ; - dMid = 0.5 * ( dStart + dEnd) ; - + // determino il valore del parametro a metà lunghezza + double dLen, dMid ; + if ( ! GetLength( dLen) || ! GetParamAtLength( 0.5 * dLen, dMid)) + return false ; // calcolo il punto return GetPointD1D2( dMid, FROM_MINUS, ptMid) ; } +//---------------------------------------------------------------------------- +bool +CurveComposite::GetMidDir( Vector3d& vtDir) const +{ + // verifico lo stato + if ( m_nStatus != OK) + return false ; + // determino il valore del parametro a metà lunghezza + double dLen, dMid ; + if ( ! GetLength( dLen) || ! GetParamAtLength( 0.5 * dLen, dMid)) + return false ; + // calcolo la direzione + return ::GetTang( *this, 0.5 * m_nCounter, FROM_MINUS, vtDir) ; +} + //---------------------------------------------------------------------------- bool CurveComposite::GetDomain( double& dStart, double& dEnd) const @@ -1064,7 +1077,7 @@ CurveComposite::GetParamAtLength( double dLen, double& dU) const } } - return false ; + return true ; } //---------------------------------------------------------------------------- diff --git a/CurveComposite.h b/CurveComposite.h index 201243d..b460148 100644 --- a/CurveComposite.h +++ b/CurveComposite.h @@ -66,8 +66,7 @@ class CurveComposite : public ICurveComposite, public IGeoObjRW { return ::GetTang( *this, 0, FROM_PLUS, vtDir) ; } virtual bool GetEndDir( Vector3d& vtDir) const { return ::GetTang( *this, m_nCounter, FROM_MINUS, vtDir) ; } - virtual bool GetMidDir( Vector3d& vtDir) const - { return ::GetTang( *this, 0.5 * m_nCounter, FROM_MINUS, vtDir) ; } + virtual bool GetMidDir( Vector3d& vtDir) const ; virtual bool GetExtrusion( Vector3d& vtExtr) const { vtExtr = m_VtExtr ; return ( m_nStatus == OK) ; } virtual bool GetThickness( double& dThick) const diff --git a/CurveLine.cpp b/CurveLine.cpp index 4e85af0..72831e5 100644 --- a/CurveLine.cpp +++ b/CurveLine.cpp @@ -424,7 +424,7 @@ CurveLine::GetParamAtLength( double dLen, double& dU) const return false ; // fine - if ( dLen < dTotLen - EPS_SMALL) { + if ( dLen > dTotLen - EPS_SMALL) { dU = 1 ; return true ; } diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 3340ff6..d411907 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ