+//=======================================================================
+/*!
+ * \brief Check and fix node UV on a face
+ * \retval bool - false if UV is bad and could not be fixed
+ */
+//=======================================================================
+
+bool SMESH_MesherHelper::CheckNodeUV(const TopoDS_Face& F,
+ const SMDS_MeshNode* n,
+ gp_XY& uv,
+ const double tol) const
+{
+ if ( !myOkNodePosShapes.count( n->GetPosition()->GetShapeId() ))
+ {
+ // check that uv is correct
+ TopLoc_Location loc;
+ Handle(Geom_Surface) surface = BRep_Tool::Surface( F,loc );
+ gp_Pnt nodePnt = XYZ( n );
+ if ( !loc.IsIdentity() ) nodePnt.Transform( loc.Transformation().Inverted() );
+ if ( nodePnt.Distance( surface->Value( uv.X(), uv.Y() )) > tol )
+ {
+ // uv incorrect, project the node to surface
+ GeomAPI_ProjectPointOnSurf projector( nodePnt, surface, tol );
+ if ( !projector.IsDone() || projector.NbPoints() < 1 )
+ {
+ MESSAGE( "SMESH_MesherHelper::CheckNodeUV() failed to project" );
+ return false;
+ }
+ Quantity_Parameter U,V;
+ projector.LowerDistanceParameters(U,V);
+ if ( nodePnt.Distance( surface->Value( U, V )) > tol )
+ {
+ MESSAGE( "SMESH_MesherHelper::CheckNodeUV(), invalid projection" );
+ return false;
+ }
+ uv.SetCoord( U,V );
+ }
+ else if ( uv.Modulus() > numeric_limits<double>::min() )
+ {
+ ((SMESH_MesherHelper*) this)->myOkNodePosShapes.insert( n->GetPosition()->GetShapeId() );
+ }
+ }
+ return true;
+}
+