]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Minor bug in Intersect2DMeshWith1DLine()
authorabn <adrien.bruneton@cea.fr>
Thu, 29 Jun 2017 10:43:20 +0000 (12:43 +0200)
committerabn <adrien.bruneton@cea.fr>
Thu, 29 Jun 2017 10:44:10 +0000 (12:44 +0200)
src/MEDCoupling/MEDCouplingUMesh_intersection.cxx
src/MEDCoupling_Swig/MEDCouplingIntersectTest.py

index ba18effcd6d5d474b4391d1046f0b1459f8bf936..75b2b1683c14f368a2996cac8a6a6257fc42a003 100644 (file)
@@ -1704,7 +1704,9 @@ void MEDCouplingUMesh::Intersect2DMeshWith1DLine(const MEDCouplingUMesh *mesh2D,
   MCAuto<DataArrayDouble> baryRet1(ret1NonCol->computeCellCenterOfMass());
   MCAuto<DataArrayInt> elts,eltsIndex;
   mesh2D->getCellsContainingPoints(baryRet1->begin(),baryRet1->getNumberOfTuples(),eps,elts,eltsIndex);
-  MCAuto<DataArrayInt> eltsIndex2(eltsIndex->deltaShiftIndex());
+  MCAuto<DataArrayInt> eltsIndex2(DataArrayInt::New()); eltsIndex2->alloc(0,1);
+  if (eltsIndex->getNumberOfTuples() > 1)
+    eltsIndex2 = eltsIndex->deltaShiftIndex();
   MCAuto<DataArrayInt> eltsIndex3(eltsIndex2->findIdsEqual(1));
   if(eltsIndex2->count(0)+eltsIndex3->getNumberOfTuples()!=ret1NonCol->getNumberOfCells())
     throw INTERP_KERNEL::Exception("Intersect2DMeshWith1DLine : internal error 1 !");
index 6bc159d0b7d4a1c556ba6d9d55800ef98850a37e..3175de29b1a73f73cc9f21bb8dd3316dad292059 100644 (file)
@@ -895,6 +895,29 @@ class MEDCouplingIntersectTest(unittest.TestCase):
         self.assertTrue(d.isEqual(DataArrayInt([(-1,-1),(1,2),(3,0),(3,4),(-1,-1)])))
         pass
 
+    def testSwig2Intersect2DMeshWith1DLine17(self):
+        """ Single colinear intersection - a deltaShiftIndex() was improperly tested. """
+        eps = 1.0e-12
+        mesh = MEDCouplingUMesh('dummy_layer', 2)
+        coo = DataArrayDouble([(-0.5,-0.5),(-0.5,0.5),(0.5,0.5),(0.5,-0.5),(-0.25,-0.25),(-0.25,0.25),(0.25,0.25),(0.25,-0.25)])
+        mesh.setCoords(coo)
+        c = DataArrayInt([5, 4, 5, 6, 7, 5, 0, 1, 5, 4, 5, 1, 2, 3, 0, 4, 7, 6, 5])
+        cI = DataArrayInt([0, 5, 10, 19])
+        mesh.setConnectivity(c, cI)
+        m_line = MEDCouplingUMesh('segment', 1)
+        coo = DataArrayDouble([(-0.5,0.5),(-0.25,0.25)])
+        m_line.setCoords(coo)
+        c = DataArrayInt([1, 0, 1])
+        cI = DataArrayInt([0, 3])
+        m_line.setConnectivity(c, cI)
+        a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(mesh, m_line, eps)
+        self.assertEqual(mesh.getNodalConnectivity().getValues(),a.getNodalConnectivity().getValues())
+        self.assertEqual(mesh.getNodalConnectivityIndex().getValues(),a.getNodalConnectivityIndex().getValues())
+        self.assertEqual([1,1,5],b.getNodalConnectivity().getValues())
+        self.assertEqual(m_line.getNodalConnectivityIndex().getValues(),b.getNodalConnectivityIndex().getValues())
+        self.assertTrue([0,1,2], c.getValues())
+        self.assertEqual([2,1], d.getValues())
+
     def testSwig2Conformize2D1(self):
         eps = 1.0e-8
         coo = [0.,-0.5,0.,0.,0.5,0.,0.5,-0.5,0.25,