diff --git a/PolyArc.cpp b/PolyArc.cpp index 603a162..7d0eeca 100644 --- a/PolyArc.cpp +++ b/PolyArc.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "DistPointLine.h" #include "GeoConst.h" +#include "CurveArc.h" #include "/EgtDev/Include/EGkPolyArc.h" #include "/EgtDev/Include/EGkFrame3d.h" #include @@ -344,6 +345,94 @@ PolyArc::IsClosed( void) const return ( AreSamePointApprox( m_lUPointBs.front().ptP, m_lUPointBs.back().ptP)) ; } +//---------------------------------------------------------------------------- +bool +PolyArc::IsRectangleXY( BBox3d& b3Rect) const +{ + b3Rect.Reset() ; + // Deve essere chiusa + if ( ! IsClosed()) + return false ; + // Verifico presenza di archi e linee oblique e calcolo il box + Point3d ptIni, ptFin ; double dBulge ; + bool bNext = GetFirstArc( ptIni, ptFin, dBulge) ; + while ( bNext) { + // non sono ammessi archi + double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; + if ( abs( dLeftDeflection) > 10 * EPS_SMALL) + return false ; + // non sono ammesse linee oblique + if ( abs( ptFin.y - ptIni.y) > 10 * EPS_SMALL && abs( ptFin.x - ptIni.x) > 10 * EPS_SMALL) + return false ; + // la Z deve essere costante + if ( abs( ptFin.z - ptIni.z) > 10 * EPS_SMALL) + return false ; + // aggiorno il box + b3Rect.Add( ptIni) ; + b3Rect.Add( ptFin) ; + // passo alla curva successiva + bNext = GetNextArc( ptIni, ptFin, dBulge) ; + } + // Verifico che tutte le linee stiano sulla frontiera del box + bNext = GetFirstArc( ptIni, ptFin, dBulge) ; + while ( bNext) { + // verifico che l'inizio stia sulla frontiera del rettangolo + if ( abs( ptIni.x - b3Rect.GetMin().x) > 10 * EPS_SMALL && abs( ptIni.x - b3Rect.GetMax().x) > 10 * EPS_SMALL && + abs( ptIni.y - b3Rect.GetMin().y) > 10 * EPS_SMALL && abs( ptIni.y - b3Rect.GetMax().y) > 10 * EPS_SMALL) + return false ; + // verifico che la fine stia sulla frontiera del rettangolo + if ( abs( ptFin.x - b3Rect.GetMin().x) > 10 * EPS_SMALL && abs( ptFin.x - b3Rect.GetMax().x) > 10 * EPS_SMALL && + abs( ptFin.y - b3Rect.GetMin().y) > 10 * EPS_SMALL && abs( ptFin.y - b3Rect.GetMax().y) > 10 * EPS_SMALL) + return false ; + // passo alla curva successiva + bNext = GetNextArc( ptIni, ptFin, dBulge) ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +PolyArc::IsCircle( double dLinTol, Point3d& ptCen, Vector3d& vtN, double& dRad, bool& bCCW) const +{ + // Deve essere chiusa + if ( ! IsClosed()) + return false ; + // Devono essere presenti solo archi con lo stesso centro, raggio e direzione + bool bFirst = true ; + Point3d ptIni, ptFin ; double dBulge ; + bool bNext = GetFirstArc( ptIni, ptFin, dBulge) ; + while ( bNext) { + // non ammessi segmenti di retta + double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; + if ( abs( dLeftDeflection) < 10 * EPS_SMALL) + return false ; + // calcolo l'arco + CurveArc cArc ; + if ( ! cArc.Set2PNB( ptIni, ptFin, m_vtExtr, dBulge)) + return false ; + if ( bFirst) { + bFirst = false ; + ptCen = cArc.GetCenter() ; + vtN = cArc.GetNormVersor() ; + dRad = cArc.GetRadius() ; + bCCW = ( cArc.GetAngCenter() > 0) ; + } + else { + if ( ! AreSamePointEpsilon( ptCen, cArc.GetCenter(), dLinTol)) + return false ; + if ( ! AreSameVectorApprox( vtN, cArc.GetNormVersor())) + return false ; + if ( abs( dRad - cArc.GetRadius()) > dLinTol) + return false ; + if ( bCCW != ( cArc.GetAngCenter() > 0)) + return false ; + } + // passo alla curva successiva + bNext = GetNextArc( ptIni, ptFin, dBulge) ; + } + return true ; +} + //---------------------------------------------------------------------------- bool PolyArc::GetFirstUPoint( double* pdPar, Point3d* pptP, double* pdBulge, bool bNotLast) const