From e12ff086a9d3d6c1eb2b69d55e9a86a31c646764 Mon Sep 17 00:00:00 2001 From: abn Date: Thu, 29 Jun 2017 12:43:20 +0200 Subject: [PATCH] Minor bug in Intersect2DMeshWith1DLine() --- .../MEDCouplingUMesh_intersection.cxx | 4 +++- .../MEDCouplingIntersectTest.py | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx b/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx index ba18effcd..75b2b1683 100644 --- a/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx @@ -1704,7 +1704,9 @@ void MEDCouplingUMesh::Intersect2DMeshWith1DLine(const MEDCouplingUMesh *mesh2D, MCAuto baryRet1(ret1NonCol->computeCellCenterOfMass()); MCAuto elts,eltsIndex; mesh2D->getCellsContainingPoints(baryRet1->begin(),baryRet1->getNumberOfTuples(),eps,elts,eltsIndex); - MCAuto eltsIndex2(eltsIndex->deltaShiftIndex()); + MCAuto eltsIndex2(DataArrayInt::New()); eltsIndex2->alloc(0,1); + if (eltsIndex->getNumberOfTuples() > 1) + eltsIndex2 = eltsIndex->deltaShiftIndex(); MCAuto eltsIndex3(eltsIndex2->findIdsEqual(1)); if(eltsIndex2->count(0)+eltsIndex3->getNumberOfTuples()!=ret1NonCol->getNumberOfCells()) throw INTERP_KERNEL::Exception("Intersect2DMeshWith1DLine : internal error 1 !"); diff --git a/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py b/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py index 6bc159d0b..3175de29b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py @@ -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, -- 2.39.2