diff --git a/EXE_GeoSnap.cpp b/EXE_GeoSnap.cpp index 35cf660..66e4451 100644 --- a/EXE_GeoSnap.cpp +++ b/EXE_GeoSnap.cpp @@ -1154,6 +1154,40 @@ ExeSurfTmFacetNormVersor( int nId, int nFacet, int nRefId, Vector3d& vtNorm) return TransformVector( pGeomDB, nId, nRefId, vtNorm) ; } +//---------------------------------------------------------------------------- +bool +ExeSurfTmFacetMinAreaRectangle( int nId, int nFacet, int nRefId, Frame3d& frRect, double& dDimX, double& dDimY) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, false) + // recupero la superficie trimesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return false ; + // recupero il centro e la normale della faccia + Point3d ptCen ; Vector3d vtN ; + if ( ! pStm->GetFacetCenter( nFacet, ptCen, vtN)) + return false ; + // calcolo il riferimento OCS della faccia + Frame3d frFac ; + if ( ! frFac.Set( ptCen, vtN)) + return false ; + // recupero il contorno esterno della faccia e lo porto nel suo riferimento + POLYLINEVECTOR vPL ; + pStm->GetFacetLoops( nFacet, vPL) ; + if ( vPL.empty()) + return false ; + vPL[0].ToLoc( frFac) ; + // derivo il rettangolo in XY di area minima di questa + Point3d ptOri ; + Vector3d vtAx ; + if ( ! vPL[0].GetMinAreaRectangleXY( ptOri, vtAx, dDimX, dDimY) && frRect.Set( ptOri, Z_AX, vtAx)) + return false ; + // esprimo il riferimento rispetto a quello richiesto + frRect.ToGlob( frFac) ; + return TransformFrame( pGeomDB, nId, nRefId, frRect) ; +} + //---------------------------------------------------------------------------- bool ExeSurfTmFacetOppositeSide( int nId, int nFacet, const Vector3d& vtDir, int nRefId, diff --git a/LUA_GeoSnap.cpp b/LUA_GeoSnap.cpp index 0a59f17..9dfcc13 100644 --- a/LUA_GeoSnap.cpp +++ b/LUA_GeoSnap.cpp @@ -842,6 +842,33 @@ LuaSurfTmFacetNormVersor( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmFacetMinAreaRectangle( lua_State* L) +{ + // 2 o 3 parametri : Id, nFacet [, nRefId] + int nId ; + LuaCheckParam( L, 1, nId) + int nFacet ; + LuaCheckParam( L, 2, nFacet) + int nRefId = nId ; + LuaGetParam( L, 3, nRefId) ; + LuaClearStack( L) ; + // recupero il rettangolo di minima area della faccia della superficie trimesh + Frame3d frRect ; + double dDimX, dDimY ; + if ( ExeSurfTmFacetMinAreaRectangle( nId, nFacet, nRefId, frRect, dDimX, dDimY)) { + LuaSetParam( L, frRect) ; + LuaSetParam( L, dDimX) ; + LuaSetParam( L, dDimY) ; + return 3 ; + } + else { + LuaSetParam( L) ; + return 1 ; + } +} + //---------------------------------------------------------------------------- static int LuaSurfTmFacetOppositeSide( lua_State* L) @@ -1067,6 +1094,7 @@ LuaInstallGeoSnap( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestMidPoint", LuaSurfTmFacetNearestMidPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCenter", LuaSurfTmFacetCenter) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNormVersor", LuaSurfTmFacetNormVersor) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetMinAreaRectangle", LuaSurfTmFacetMinAreaRectangle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetOppositeSide", LuaSurfTmFacetOppositeSide) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetsContact", LuaSurfTmFacetsContact) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapVolume", LuaVolZmapVolume) ;