Salome HOME
merge conflict
[tools/medcoupling.git] / src / MEDCoupling / Test / MEDCouplingBasicsTest5.cxx
index 85da2eccefe8ac0278c880b22b007193bd1f65c5..0dc0e8c017f43709f43abaae07261c60247457d9 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  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
@@ -1403,7 +1403,7 @@ void MEDCouplingBasicsTest5::testUMeshSetPartOfMySelf2()
   // resize with explicit ids list
   MEDCouplingUMesh *m=build2DTargetMesh_1();
   std::set<INTERP_KERNEL::NormalizedCellType> s; s.insert(INTERP_KERNEL::NORM_TRI3); s.insert(INTERP_KERNEL::NORM_QUAD4);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   const int ids1[3]={0,3,4};
   MEDCouplingUMesh *part=static_cast<MEDCouplingUMesh *>(m->buildPartOfMySelf(ids1,ids1+3,true));
   part->simplexize(0)->decrRef();
@@ -1417,7 +1417,7 @@ void MEDCouplingBasicsTest5::testUMeshSetPartOfMySelf2()
   CPPUNIT_ASSERT(std::equal(expected2,expected2+6,m->getNodalConnectivityIndex()->getConstPointer()));
   CPPUNIT_ASSERT_EQUAL((std::size_t)6,m->getNodalConnectivityIndex()->getNbOfElems());
   s.clear(); s.insert(INTERP_KERNEL::NORM_TRI3);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   m->decrRef(); part->decrRef(); part2->decrRef();
   // no resize with explicit ids list
   m=build2DTargetMesh_1();
@@ -1431,7 +1431,7 @@ void MEDCouplingBasicsTest5::testUMeshSetPartOfMySelf2()
   CPPUNIT_ASSERT(std::equal(expected4,expected4+6,m->getNodalConnectivityIndex()->getConstPointer()));
   CPPUNIT_ASSERT_EQUAL((std::size_t)6,m->getNodalConnectivityIndex()->getNbOfElems());
   s.clear(); s.insert(INTERP_KERNEL::NORM_TRI3); s.insert(INTERP_KERNEL::NORM_QUAD4); s.insert(INTERP_KERNEL::NORM_POLYGON);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   m->decrRef(); part->decrRef();
   // resize with range ids
   m=build2DTargetMesh_1();
@@ -1444,7 +1444,7 @@ void MEDCouplingBasicsTest5::testUMeshSetPartOfMySelf2()
   CPPUNIT_ASSERT(std::equal(expected6,expected6+6,m->getNodalConnectivityIndex()->getConstPointer()));
   CPPUNIT_ASSERT_EQUAL((std::size_t)6,m->getNodalConnectivityIndex()->getNbOfElems());
   s.clear(); s.insert(INTERP_KERNEL::NORM_QUAD4);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   m->decrRef(); part->decrRef();
   // no resize with range ids
   m=build2DTargetMesh_1();
@@ -1458,7 +1458,7 @@ void MEDCouplingBasicsTest5::testUMeshSetPartOfMySelf2()
   CPPUNIT_ASSERT(std::equal(expected8,expected8+6,m->getNodalConnectivityIndex()->getConstPointer()));
   CPPUNIT_ASSERT_EQUAL((std::size_t)6,m->getNodalConnectivityIndex()->getNbOfElems());
 s.clear(); s.insert(INTERP_KERNEL::NORM_TRI3); s.insert(INTERP_KERNEL::NORM_QUAD4); s.insert(INTERP_KERNEL::NORM_POLYGON);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   m->decrRef(); part->decrRef();
   // no resize with range ids negative direction
   m=build2DTargetMesh_1();
@@ -1472,7 +1472,7 @@ s.clear(); s.insert(INTERP_KERNEL::NORM_TRI3); s.insert(INTERP_KERNEL::NORM_QUAD
   CPPUNIT_ASSERT(std::equal(expected10,expected10+6,m->getNodalConnectivityIndex()->getConstPointer()));
   CPPUNIT_ASSERT_EQUAL((std::size_t)6,m->getNodalConnectivityIndex()->getNbOfElems());
   s.clear(); s.insert(INTERP_KERNEL::NORM_TRI3); s.insert(INTERP_KERNEL::NORM_QUAD4); s.insert(INTERP_KERNEL::NORM_POLYGON);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   part->decrRef();
   m->decrRef();
 }
@@ -1500,7 +1500,7 @@ void MEDCouplingBasicsTest5::testUnPolyze3()
   m->unPolyze();
   CPPUNIT_ASSERT_EQUAL(1,m->getNumberOfCells());
   std::set<INTERP_KERNEL::NormalizedCellType> s; s.insert(INTERP_KERNEL::NORM_PENTA6);
-  CPPUNIT_ASSERT(s==m->getAllTypes());
+  CPPUNIT_ASSERT(s==m->getAllGeoTypes());
   //
   const int expected1[2]={0,7};
   const int expected2[7]={16,0,2,1,3,5,4};
@@ -1798,6 +1798,64 @@ void MEDCouplingBasicsTest5::testIntersect2DMeshesTmp6()
   d2->decrRef();
 }
 
+void MEDCouplingBasicsTest5::testIntersect2DMeshesTmp7()
+{
+  double eps = 1.0e-8;
+  // coordinates circle - SEE getCircle() on the Python side
+  DataArrayDouble *coords1=DataArrayDouble::New();
+  const double coordsData1[16]={0.5328427124746189, -0.08284271247461905, -0.03284271247461901, 0.4828427124746191, -0.03284271247461906, -0.082842712474619, 0.5328427124746191, 0.482842712474619};
+  coords1->useArray(coordsData1,false,CPP_DEALLOC,8,2);
+  // connectivity
+  DataArrayInt *conn1=DataArrayInt::New();
+  const int connData1[5]={INTERP_KERNEL::NORM_QPOLYG,0,1,2,3};
+  conn1->useArray(connData1,false,CPP_DEALLOC,5,1);
+  DataArrayInt *connI1=DataArrayInt::New();
+  const int connIData1[2]={0,5};
+  connI1->useArray(connIData1,false,CPP_DEALLOC,2,1);
+  MEDCouplingUMesh *m1=MEDCouplingUMesh::New("circle",2);
+  m1->setCoords(coords1);
+  m1->setConnectivity(conn1,connI1,true);
+  coords1->decrRef(); conn1->decrRef(); connI1->decrRef();
+
+  // square
+  DataArrayDouble *coords2=DataArrayDouble::New();
+  const double coordsData2[8]={-0.5,-0.5,   -0.5, 0.5, 0.5, 0.5,    0.5,-0.5};
+  coords2->useArray(coordsData2,false,CPP_DEALLOC,4,2);
+  // connectivity
+  DataArrayInt *conn2=DataArrayInt::New();
+  const int connData2[5]={INTERP_KERNEL::NORM_POLYGON, 0,1,2,3};
+  conn2->useArray(connData2,false,CPP_DEALLOC,5,1);
+  DataArrayInt *connI2=DataArrayInt::New();
+  const int connIData2[2]={0,5};
+  connI2->useArray(connIData2,false,CPP_DEALLOC,2,1);
+  MEDCouplingUMesh *m2=MEDCouplingUMesh::New("square",2);
+  m2->setCoords(coords2);
+  m2->setConnectivity(conn2,connI2,true);
+  coords2->decrRef(); conn2->decrRef(); connI2->decrRef();
+
+  DataArrayInt * resToM1 = 0, * resToM2 = 0;
+  MEDCouplingUMesh *m_intersec=MEDCouplingUMesh::Intersect2DMeshes(m2, m1, eps, resToM1, resToM2);
+  m_intersec->zipCoords();
+
+  const double coo_tgt[34]={-0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.03284271247461901, 0.4828427124746191, \
+    -0.014575131106459124, 0.5000000000000001, 0.5, -0.11224989991991996, 0.24271243444677046, 0.5, 0.5, 0.19387505004004, \
+    -0.04799910280454185, -0.06682678787499614, -0.023843325638122054, 0.4915644577163915, 0.5, -0.30612494995996, 0.0, -0.5,\
+    -0.5, 0.0, -0.25728756555322957, 0.5, -0.023843325638122026, 0.49156445771639157, -0.04799910280454181, -0.06682678787499613};
+  const int conn_tgt[22]={32, 5, 2, 6, 4, 7, 8, 9, 10, 32, 6, 3, 0, 1, 5, 4, 11, 12, 13, 14, 15, 16};
+  const int connI_tgt[3]={0, 9, 22};
+  const int res1_tgt[2] = {0, 0};
+  const int res2_tgt[2] = {0, -1};
+
+  CPPUNIT_ASSERT(std::equal(conn_tgt,conn_tgt+22,m_intersec->getNodalConnectivity()->getConstPointer()));
+  CPPUNIT_ASSERT(std::equal(connI_tgt,connI_tgt+3,m_intersec->getNodalConnectivityIndex()->getConstPointer()));
+  CPPUNIT_ASSERT(std::equal(res1_tgt,res1_tgt+2,resToM1->getConstPointer()));
+  CPPUNIT_ASSERT(std::equal(res2_tgt,res2_tgt+2,resToM2->getConstPointer()));
+  for(int i=0;i<34;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(coo_tgt[i],m_intersec->getCoords()->getIJ(0,i),1e-12);
+  m1->decrRef(); m2->decrRef(); m_intersec->decrRef();
+  resToM1->decrRef(); resToM2->decrRef();
+}
+
 void MEDCouplingBasicsTest5::testDAIBuildSubstractionOptimized1()
 {
   const int tab1[7]={1,3,5,6,7,9,13};