Salome HOME
Some useful helpers into medcoupling python module
[tools/medcoupling.git] / src / INTERP_KERNEL / PolygonAlgorithms.txx
index 74fe484ae05969307fbae47c802a64fef17c3338..bf606e92670e28092bc585af69afa95157e82212 100644 (file)
@@ -1,20 +1,20 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #ifndef __POLYGONALGORITHMS_TXX__
 #define __POLYGONALGORITHMS_TXX__
@@ -37,7 +37,7 @@ namespace INTERP_KERNEL
   /*************************************************************/
   /* Computes the 3D intersection between two COPLANAR         */
   /* Segments [A,B] and [C,D], stores the result in V.         */
-  /* If A belongs to [CD] then the vertex E (preceeding A)     */
+  /* If A belongs to [CD] then the vertex E (preceding A)      */
   /* is used to decide if the crossing is real. If A coincides */
   /* with C or D, a special treatment is performed             */
   /*************************************************************/
@@ -71,30 +71,30 @@ namespace INTERP_KERNEL
             {
               if(distance2<DIM>(A,D)<_epsilon)
                 crossprod<DIM>(A,C,E,_vdouble);//store the crossprod between vectors AC and AE (E=vertex preceding A)                     
-              return false;//case of paralell segments
+              return false;//case of parallel segments
             }
           case 3://beware AB and CD may belong to a vertical plane
             det = determinant(&AB[1],&DC[1]);//determinant of the last two coefficients
             if(fabs(det) > _epsilon) 
               {
                 inv_det = 1/det;
-                t1=(AC[1]*DC[2]-AC[2]*DC[1])*inv_det;
-                t2=(AB[1]*AC[2]-AB[2]*AC[1])*inv_det;
+                t1=(AC[1]*DC[DIM-1]-AC[DIM-1]*DC[1])*inv_det;
+                t2=(AB[1]*AC[DIM-1]-AB[DIM-1]*AC[1])*inv_det;
               }
             else //beware AB and CD may belong to a plane y = constant
               {
-                det = AB[0]*DC[2]-AB[2]*DC[0];
+                det = AB[0]*DC[DIM-1]-AB[DIM-1]*DC[0];
                 if(fabs(det) > _epsilon) 
                   {
                     inv_det = 1/det;
-                    t1=(AC[0]*DC[2]-AC[2]*DC[0])*inv_det;
-                    t2=(AB[0]*AC[2]-AB[2]*AC[0])*inv_det;
+                    t1=(AC[0]*DC[DIM-1]-AC[DIM-1]*DC[0])*inv_det;
+                    t2=(AB[0]*AC[DIM-1]-AB[DIM-1]*AC[0])*inv_det;
                   }
                 else
                   {
                     if(distance2<DIM>(A,D)<_epsilon)
                       crossprod<DIM>(A,C,E,_vdouble);//store the crossprod between vectors AC and AE (E=vertex preceding A)                     
-                    return false;//case of paralell segments
+                    return false;//case of parallel segments
                   }
               }
           }
@@ -269,7 +269,7 @@ namespace INTERP_KERNEL
   /*******************************************************/
   /* adds the possible crossings between segments [A,B] (with end-point global indices i and i_next) */
   /*and segments [C,D] and [E,F] to the list inter and updates _End_segments */
-  /* In cases of ambiguity, the vertex G is used to decide wether the crossing should be accepted */
+  /* In cases of ambiguity, the vertex G is used to decide whether the crossing should be accepted */
   /*******************************************************/
   template<int DIM>
   inline void PolygonAlgorithms<DIM>::addCrossings( const double * A, const double * B, int i , int i_next,
@@ -490,8 +490,10 @@ namespace INTERP_KERNEL
                 break;
               case 2 :
                 if(!_Inter.empty())
-                  if(i_glob < N1)  for(idim=0;idim<DIM;idim++) _Inter.push_back(P_1[DIM*i_glob+idim]);
-                  else for(idim=0;idim<DIM;idim++) _Inter.push_back(P_2[DIM*(i_glob-N1)+idim]);
+                  {
+                    if(i_glob < N1)  for(idim=0;idim<DIM;idim++) _Inter.push_back(P_1[DIM*i_glob+idim]);
+                    else for(idim=0;idim<DIM;idim++) _Inter.push_back(P_2[DIM*(i_glob-N1)+idim]);
+                  }
                 return _Inter;
               case 0 ://To do if possible : remove this case from here
                 if(_Inter.empty() && (i_glob < N1) != which_start){
@@ -510,7 +512,8 @@ namespace INTERP_KERNEL
                       //std::cout<<"coucou1" << std::endl;
                       if( _is_in_intersection)
                         {
-                          for(int idim=0;idim<DIM;idim++) _Inter.push_back(Poly1[DIM*i_loc+idim]);
+                          for(int iidim=0;iidim<DIM;iidim++)
+                            _Inter.push_back(Poly1[DIM*i_loc+iidim]);
                           _End_segments.push_back(std::make_pair(i_glob,i_next_glob));
                           _End_segments.push_back(std::make_pair(i_glob,i_prev_glob));
                         }