Salome HOME
Implementation of MEDCoupling1SGTUMesh.computeTriangleHeight and DataArrayDouble...
[tools/medcoupling.git] / src / INTERP_KERNEL / PointLocator2DIntersector.txx
index 2491ea75655f5bcaf86373700ce3e354ee6395b6..67a07e5e319d1b323b550fb8bc7c066c9fa00435 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2022  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.
+// 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
@@ -53,13 +53,22 @@ namespace INTERP_KERNEL
     std::vector<double> CoordsS;
     PlanarIntersector<MyMeshType,MyMatrix>::getRealCoordinates(icellT,icellS,nbNodesT,nbNodesS,CoordsT,CoordsS,orientation);
     NormalizedCellType tT=PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getTypeOfElement(icellT);
+    NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(icellS);
     QuadraticPolygon *pT=buildPolygonFrom(CoordsT,tT);
     double baryT[SPACEDIM];
     pT->getBarycenterGeneral(baryT);
     delete pT;
-    if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(baryT,&CoordsS[0],nbNodesS,InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >::_precision))
-      return 1.;
-    return 0.;
+    bool ret;
+    double eps = InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >::_precision;
+    if (tS != INTERP_KERNEL::NORM_POLYGON && !CellModel::GetCellModel(tS).isQuadratic())
+      ret = PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2DSimple(baryT,&CoordsS[0],nbNodesS,eps);
+    else
+      {
+        std::vector<ConnType> conn_elem(nbNodesS);
+        std::iota(conn_elem.begin(), conn_elem.end(), 0);
+        ret = PointLocatorAlgos<MyMeshType>::isElementContainsPointAlgo2DPolygon(baryT, tS, &CoordsS[0], &conn_elem[0], nbNodesS, eps);
+      }
+    return (ret ? 1. : 0.);
   }
 
   INTERSECTOR_TEMPLATE
@@ -118,16 +127,16 @@ namespace INTERP_KERNEL
                                                const double *             sourceTria,
                                                std::vector<double>&       res)
   {
-    throw INTERP_KERNEL::Exception("intersectGeoBary incompatible with PointLocator. Desactivate P1P0Bary to avoid the problem");
+    throw INTERP_KERNEL::Exception("intersectGeoBary incompatible with PointLocator. Deactivate P1P0Bary to avoid the problem");
     return 0.;
   }
 
   INTERSECTOR_TEMPLATE
   QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonFrom(const std::vector<double>& coords, NormalizedCellType type)
   {
-    int nbNodes=coords.size()/SPACEDIM;
+    std::size_t nbNodes=coords.size()/SPACEDIM;
     std::vector<Node *> nodes(nbNodes);
-    for(int i=0;i<nbNodes;i++)
+    for(std::size_t i=0;i<nbNodes;i++)
       nodes[i]=new Node(coords[i*SPACEDIM],coords[i*SPACEDIM+1]);
     if(!CellModel::GetCellModel(type).isQuadratic())
       return QuadraticPolygon::BuildLinearPolygon(nodes);