Salome HOME
23653: [CEA] SMESH compilation failure: Ubuntu 16 : isnan
[modules/smesh.git] / src / SMESH_I / SMESH_Measurements_i.cxx
index ca0103c016e6cb9994a8eb21f1d0ef7c35dcb8cf..e6e5493fa14de37ac35ec6d9a981ff395eee220d 100644 (file)
@@ -38,6 +38,7 @@
 #include "SMESH_MeshAlgos.hxx"
 #include "SMESH_PythonDump.hxx"
 
+#include <cmath>
 
 using namespace SMESH;
 
@@ -255,16 +256,13 @@ static void enlargeBoundingBox(const SMESH::SMESH_IDSource_ptr theObject,
       enlargeBoundingBox( aMesh->FindNode( aElementsId[i] ), theMeasure);
     else
     {
-      const SMDS_MeshElement* elem = aMesh->FindElement( aElementsId[i] );
-      if (!elem)
-        continue;
-      SMDS_ElemIteratorPtr aNodeIter = elem->nodesIterator();
-      while( aNodeIter->more() )
-        enlargeBoundingBox( dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() ), theMeasure);
+      if ( const SMDS_MeshElement* elem = aMesh->FindElement( aElementsId[i] ))
+        for (SMDS_NodeIteratorPtr aNodeIter = elem->nodeIterator(); aNodeIter->more(); )
+          enlargeBoundingBox( aNodeIter->next(), theMeasure);
     }
   }
 }
-                               
+
 //=======================================================================
 // name    : BoundingBox
 // Purpose : compute common bounding box of entities
@@ -349,3 +347,30 @@ SMESH::PointStruct Measurements_i::GravityCenter(SMESH::SMESH_IDSource_ptr theSo
 
   return grCenter;
 }
+
+//=======================================================================
+//function : Angle
+//purpose  : Return angle in radians defined by 3 points <(p1,p2,p3)
+//=======================================================================
+
+CORBA::Double Measurements_i::Angle(const SMESH::PointStruct& p1,
+                                    const SMESH::PointStruct& p2,
+                                    const SMESH::PointStruct& p3 )
+{
+  gp_Vec v1( p1.x - p2.x, p1.y - p2.y, p1.z - p2.z );
+  gp_Vec v2( p3.x - p2.x, p3.y - p2.y, p3.z - p2.z );
+
+  double angle = -1;
+
+  try
+  {
+    angle = v1.Angle( v2 );
+  }
+  catch(...)
+  {
+  }
+  if ( std::isnan( angle ))
+    angle = -1;
+
+  return angle;
+}