diff --git a/BBox3d.cpp b/BBox3d.cpp index 2d67e7f..da639aa 100644 --- a/BBox3d.cpp +++ b/BBox3d.cpp @@ -53,7 +53,8 @@ BBox3d::Set( double dX1, double dY1, double dZ1, double dX2, double dY2, double bool BBox3d::IsValid( void) const { - return ( m_ptMin.x < ( m_ptMax.x + EPS_SMALL) && + return ( m_ptMin.IsValid() && m_ptMax.IsValid() && + m_ptMin.x < ( m_ptMax.x + EPS_SMALL) && m_ptMin.y < ( m_ptMax.y + EPS_SMALL) && m_ptMin.z < ( m_ptMax.z + EPS_SMALL)) ; } diff --git a/CurveArc.cpp b/CurveArc.cpp index f78f842..b9f8fb9 100644 --- a/CurveArc.cpp +++ b/CurveArc.cpp @@ -824,10 +824,10 @@ CurveArc::Validate( void) m_dAngCenDeg = - ANG_FULL ; } // eseguo il controllo - m_nStatus = ( ( m_VtN.IsNormalized() && m_VtS.IsNormalized() && - AreOrthoApprox( m_VtN, m_VtS) && - m_dRad > EPS_SMALL && m_dRad < MAX_ARC_RAD && - abs( m_dAngCenDeg) > EPS_ANG_ZERO) ? OK : ERR) ; + m_nStatus = ( ( m_PtCen.IsValid() && + m_VtN.IsNormalized() && m_VtS.IsNormalized() && AreOrthoApprox( m_VtN, m_VtS) && + m_dRad > EPS_SMALL && m_dRad < MAX_ARC_RAD && + abs( m_dAngCenDeg) > EPS_ANG_ZERO) ? OK : ERR) ; } return ( m_nStatus == OK) ; diff --git a/CurveBezier.cpp b/CurveBezier.cpp index ac0e967..3514473 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -424,6 +424,23 @@ CurveBezier::Load( NgeReader& ngeIn) bool CurveBezier::Validate( void) { + if ( m_nStatus == TO_VERIFY) { + for ( const auto& ptP : m_vPtCtrl) { + if ( ! ptP.IsValid()) { + m_nStatus = ERR ; + break ; + } + } + } + if ( m_nStatus == TO_VERIFY) { + for ( const auto& dWe : m_vWeCtrl) { + if ( ! isfinite( dWe)) { + m_nStatus = ERR ; + break ; + } + } + } + if ( m_nStatus == TO_VERIFY) m_nStatus = ( ( m_nDeg > 0 && m_vPtCtrl.size() > 0) ? OK : ERR) ; diff --git a/CurveLine.cpp b/CurveLine.cpp index 79ee00a..dbdc8c1 100644 --- a/CurveLine.cpp +++ b/CurveLine.cpp @@ -259,7 +259,7 @@ bool CurveLine::Validate( void) { if ( m_nStatus == TO_VERIFY) - m_nStatus = ( ! AreSamePointApprox( m_PtStart, m_PtEnd) ? OK : ERR) ; + m_nStatus = ( m_PtStart.IsValid() && m_PtEnd.IsValid() && ! AreSamePointApprox( m_PtStart, m_PtEnd) ? OK : ERR) ; return ( m_nStatus == OK) ; } diff --git a/Frame3d.cpp b/Frame3d.cpp index 0338468..0216924 100644 --- a/Frame3d.cpp +++ b/Frame3d.cpp @@ -456,6 +456,9 @@ Frame3d::LocToLoc( const Frame3d& frOri, const Frame3d& frDest) bool Frame3d::Verify( void) { + // verifica origine + if ( ! m_ptOrig.IsValid()) + return false ; // verifica della ortogonalità dei versori e del senso destrorso double dOrtXY = m_vtVersX * m_vtVersY ; double dOrtYZ = m_vtVersY * m_vtVersZ ; diff --git a/VolZmapCalculus.cpp b/VolZmapCalculus.cpp index c24fd29..8876c95 100644 --- a/VolZmapCalculus.cpp +++ b/VolZmapCalculus.cpp @@ -1815,6 +1815,7 @@ VolZmap::AvoidRectPrismoid( const Frame3d& frPrismoid, double dLenghtBaseX, doub dLenghtTopX + 2 * dOffsTopX, dLenghtTopY + 2 * dOffsTopY, dHeight + 2 * dSafeDist, bPrecise)) return true ; + // Offset fine // Sfere centrate nei vertici double dHalfBaseX = dLenghtBaseX / 2 ; double dHalfBaseY = dLenghtBaseY / 2 ; @@ -2307,10 +2308,10 @@ bool VolZmap::IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, const Frame3d& CylFrame, double dH, double dRad, bool bTapLow, bool bTapUp, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const -{ +{ // Porto la linea nel riferimento del cilindro - Point3d ptP = ptLineSt ; ptP.ToLoc( CylFrame) ; - Vector3d vtV = vtLineDir ; vtV.ToLoc( CylFrame) ; + Point3d ptP = GetToLoc( ptLineSt, CylFrame) ; + Vector3d vtV = GetToLoc( vtLineDir, CylFrame) ; // Determino le eventuali intersezioni con le due basi a quota minima e massima (solo se linea non parallela ad esse) int nBasInt = 0 ; @@ -2341,13 +2342,11 @@ VolZmap::IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, } // Determino le intersezioni con la superficie laterale del cilindro - DBLVECTOR vdCoef(3) ; - 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 ; + DBLVECTOR vdCoeff{ ptP.x * ptP.x + ptP.y * ptP.y - dRad * dRad, + 2 * ( ptP.x * vtV.x + ptP.y * vtV.y), + vtV.x * vtV.x + vtV.y * vtV.y} ; DBLVECTOR vdRoots ; - int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; + int nRoot = PolynomialRoots( 2, vdCoeff, vdRoots) ; // Epsilon per piani di tappo double dEpsLow = ( bTapLow ? - EPS_SMALL : EPS_SMALL) ; @@ -2357,7 +2356,7 @@ VolZmap::IntersLineCylinder( const Point3d& ptLineSt, const Vector3d& vtLineDir, if ( nRoot == 2) { double dIntZ2 = ptP.z + vdRoots[1] * vtV.z ; if ( dIntZ2 < 0 + dEpsLow || dIntZ2 > dH + dEpsUp) - nRoot = 1 ; + -- nRoot ; } if ( nRoot >= 1) { double dIntZ1 = ptP.z + vdRoots[0] * vtV.z ; @@ -2432,8 +2431,8 @@ VolZmap::IntersLineConus( const Point3d& ptLineSt, const Vector3d& vtLineDir, Point3d& ptInt1, Vector3d& vtN1, Point3d& ptInt2, Vector3d& vtN2) const { // Porto la linea nel riferimento del cono - Point3d ptP = ptLineSt ; ptP.ToLoc( ConusFrame) ; - Vector3d vtV = vtLineDir ; vtV.ToLoc( ConusFrame) ; + Point3d ptP = GetToLoc( ptLineSt, ConusFrame) ; + Vector3d vtV = GetToLoc( vtLineDir, ConusFrame) ; // Raggi delle due basi double dMinRad = dTan * dMinH ; @@ -2470,19 +2469,18 @@ VolZmap::IntersLineConus( const Point3d& ptLineSt, const Vector3d& vtLineDir, } // Determino le intersezioni con la superficie laterale del cono - DBLVECTOR vdCoef( 3) ; double dSqTan = dTan * dTan ; - 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 ; + DBLVECTOR vdCoeff{ dSqTan * ptP.z * ptP.z - ptP.x * ptP.x - ptP.y * ptP.y, + 2 * ( dSqTan * ptP.z * vtV.z - ptP.x * vtV.x - ptP.y * vtV.y), + dSqTan * vtV.z * vtV.z - vtV.x * vtV.x - vtV.y * vtV.y} ; DBLVECTOR vdRoots ; - int nRoot = PolynomialRoots( 2, vdCoef, vdRoots) ; + int nRoot = PolynomialRoots( 2, vdCoeff, vdRoots) ; // 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 ; + -- nRoot ; } if ( nRoot >= 1) { double dIntZ1 = ptP.z + vdRoots[0] * vtV.z ; @@ -2570,8 +2568,8 @@ VolZmap::IntersLineEllipticalCylinder( const Point3d& ptLineSt, const Vector3d& return false ; // Porto la linea nel riferimento del cilindro - Point3d ptP = ptLineSt ; ptP.ToLoc( CircFrame) ; - Vector3d vtV = vtLineDir ; vtV.ToLoc( CircFrame) ; + Point3d ptP = GetToLoc( ptLineSt, CircFrame) ; + Vector3d vtV = GetToLoc( vtLineDir, CircFrame) ; // Quadrato del raggio double dSqRad = dRad * dRad ; @@ -2713,8 +2711,8 @@ VolZmap::IntersLineMyPolyhedron( const Point3d& ptLineSt, const Vector3d& vtLine return false ; // Porto la linea nel riferimento del poliedro - Point3d ptP = ptLineSt ; ptP.ToLoc( PolyFrame) ; - Vector3d vtV = vtLineDir ; vtV.ToLoc( PolyFrame) ; + Point3d ptP = GetToLoc( ptLineSt, PolyFrame) ; + Vector3d vtV = GetToLoc( vtLineDir, PolyFrame) ; // Facce 1 e 2 parallele a XY // Facce 3 e 4 parallele a XZ @@ -2862,10 +2860,8 @@ VolZmap::IntersLineTruncatedPyramid( const Point3d& ptLineSt, const Vector3d& vt return false ; // Porto la linea nel riferimento del solido - Point3d ptP = ptLineSt ; - Vector3d vtV = vtLineDir ; - ptP.ToLoc( frTruncPyramFrame) ; - vtV.ToLoc( frTruncPyramFrame) ; + Point3d ptP = GetToLoc( ptLineSt, frTruncPyramFrame) ; + Vector3d vtV = GetToLoc( vtLineDir, frTruncPyramFrame) ; // Se la retta sta sopra o sotto il solido non vi può essere intersezione if ( abs( vtV.z) < EPS_ZERO && ( ptP.z < EPS_SMALL || ptP.z > dHeight + EPS_SMALL))