From d7dedc80bb4e9b364214710d493692f0ba25aa9c Mon Sep 17 00:00:00 2001 From: abn Date: Fri, 21 Nov 2014 15:29:23 +0100 Subject: [PATCH] Bug fix in Intersect2DMeshWith1D: intersectEdges1 was incorrect when quadratic edges are given. --- src/MEDCoupling/MEDCouplingUMesh.cxx | 3 ++- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 24 +++++++++++++++++++ .../MEDCouplingDataForTest.py | 20 ++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index ce0257e6e..f9c16dcbf 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -10045,7 +10045,8 @@ void MEDCouplingUMesh::Intersect1DMeshes(const MEDCouplingUMesh *m1Desc, const M delete pol1; } else - intersectEdge1[i].insert(intersectEdge1[i].end(),c1+ci1[i]+1,c1+ci1[i+1]); + // Copy the edge (take only the two first points, ie discard quadratic point at this stage) + intersectEdge1[i].insert(intersectEdge1[i].end(),c1+ci1[i]+1,c1+ci1[i]+3); } } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 08f0fc859..96ae8c4b9 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -15858,6 +15858,30 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(d.isEqual(DataArrayInt([(-1,-1),(1,2),(1,2),(1,2),(-1,-1)]))) pass + def testSwig2Intersect2DMeshWith1DLine10(self): + """ Intersection between a circle and various lines """ + eps = 1.0e-8 + m_circ = MEDCouplingDataForTest.buildCircle2(0.0, 0.0, 2.0) + coords = [0.0,3.0,0.0,-3.0] + connec = [0,1] + m_line = MEDCouplingUMesh.New("seg", 1) + m_line.allocateCells(1) + meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + m_line.setCoords(meshCoords) + m_line.insertNextCell(NORM_SEG2, connec) + a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m_circ, m_line, eps) + self.assertEqual([32, 1, 7, 10, 11, 12, 13, 14, 15, 32, 5, 3, 11, 10, 16, 17, 18, 19], a.getNodalConnectivity().getValues()) + self.assertEqual([0, 9, 18], a.getNodalConnectivityIndex().getValues()) + self.assertEqual([1, 8, 11, 1, 11, 10, 1, 10, 9], b.getNodalConnectivity().getValues()) + self.assertEqual([0, 3, 6, 9], b.getNodalConnectivityIndex().getValues()) + self.assertTrue(a.getCoords()[:8].isEqual(m_circ.getCoords(),1e-12)) + self.assertTrue(a.getCoords()[8:10].isEqual(m_line.getCoords(),1e-12)) + coo_tgt = DataArrayDouble([2.0, 0.0, 1.4142135623730951, 1.414213562373095, 1.2246467991473532e-16, 2.0, -1.414213562373095, 1.4142135623730951, -2.0, 2.4492935982947064e-16, -1.4142135623730954, -1.414213562373095, -3.6739403974420594e-16, -2.0, 1.4142135623730947, -1.4142135623730954, 0.0, 3.0, 0.0, -3.0, 0.0, -2.0, 0.0, 2.0, 2.0, -2.220446049250313e-16, 0.7653668647301797, -1.8477590650225735, 0.0, 0.0, 0.7653668647301797, 1.8477590650225735, -1.9999999999999998, -3.2343398276365944e-16, -0.7653668647301795, 1.8477590650225735, 0.0, 0.0, -0.7653668647301795, -1.8477590650225735]) + self.assertTrue(a.getCoords().isEqualWithoutConsideringStr(coo_tgt, 1.0e-12)) + self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) + self.assertEqual([0, 0], c.getValues()) + self.assertEqual([-1, -1, 0, 1, -1, -1], d.getValues()) + def testOrderConsecutiveCells1D1(self): """A line in several unconnected pieces:""" m2 = MEDCouplingUMesh.New("bla", 1) diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py index 8012a6b83..ed5497fd8 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -701,6 +701,25 @@ class MEDCouplingDataForTest: baseMesh.finishInsertingCells() return baseMesh + def buildCircle2(self, center_X, center_Y, radius): + from cmath import rect + from math import pi + + c = [rect(radius, i*pi/4.0) for i in range(8)] + coords = [] + for i in range(8): + coords.extend([c[i].real,c[i].imag]) + connec = [7,5,3,1, 6,4,2,0] + baseMesh = MEDCouplingUMesh.New("circle", 2) + baseMesh.allocateCells(1) + meshCoords = DataArrayDouble.New(coords, len(coords)/2, 2) + meshCoords += (center_X, center_Y) + baseMesh.setCoords(meshCoords) + + baseMesh.insertNextCell(NORM_QPOLYG, connec) + baseMesh.finishInsertingCells() + return baseMesh + build2DTargetMesh_1=classmethod(build2DTargetMesh_1) build2DSourceMesh_1=classmethod(build2DSourceMesh_1) build3DTargetMesh_1=classmethod(build3DTargetMesh_1) @@ -730,6 +749,7 @@ class MEDCouplingDataForTest: buildFieldOnGauss_3=classmethod(buildFieldOnGauss_3) buildFieldOnGauss_4=classmethod(buildFieldOnGauss_4) buildCircle=classmethod(buildCircle) + buildCircle2=classmethod(buildCircle2) pass -- 2.30.2