+ def testIntersect2DMeshes7(self):
+ """ Quadratic precision values were improperly reset before testing colinearities """
+ eps = 1.0e-08
+ mesh1 = MEDCouplingUMesh('assemblyGrid_Pij', 2)
+ coo = DataArrayDouble([(10.80630000000000,10.80630000000000),(9.48750000000000,10.80630000000000),(10.75250000000000,10.80630000000000),(9.48750000000000,9.48750000000000),(10.75250000000000,9.48750000000000),(10.80630000000000,9.48750000000000),(9.48750000000000,10.75250000000000),(10.75250000000000,10.75250000000000),(10.80630000000000,10.75250000000000)])
+ mesh1.setCoords(coo)
+ c = DataArrayInt([5, 4, 3, 6, 7, 5, 5, 4, 7, 8, 5, 1, 2, 7, 6, 5, 2, 0, 8, 7])
+ cI = DataArrayInt([0, 5, 10, 15, 20])
+ mesh1.setConnectivity(c, cI)
+ mesh2 = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(9.48750000000001,9.48750000000001),(10.75249999999975,9.48749999999955),(10.12000000000001,9.48750000000001),(10.80629999999976,9.48749999999955),(8.22250000000029,10.75250000000028),(9.48749999999961,10.75249999999971),(8.85500000000029,10.75250000000028),(9.48750000000001,10.12000000000001),(10.75249999999338,10.75249999999338),(10.41000000000001,10.12000000000001),(10.32506096654411,10.32506096654411),(10.12000000000001,10.41000000000001),(9.91493903345591,10.32506096654411),(9.83000000000001,10.12000000000001),(9.91493903345591,9.91493903345591),(10.12000000000001,9.83000000000001),(10.32506096654411,9.91493903345591),(10.11999999999961,10.75249999999971),(10.75249999999975,10.11999999999958),(10.49000000000001,10.12000000000001),(10.38162950903903,10.38162950903903),(10.12000000000001,10.49000000000001),(9.85837049096099,10.38162950903903),(9.75000000000001,10.12000000000001),(9.85837049096099,9.85837049096099),(10.12000000000001,9.75000000000001),(10.38162950903903,9.85837049096099),(9.88665476220845,10.35334523779157),(9.88665476220845,9.88665476220845),(9.67293524548050,9.67293524548050),(9.67293524548050,10.56706475451952),(10.80629999999339,10.75249999999338),(8.22250000000029,10.80630000000028),(9.48749999999961,10.80629999999971),(10.75249999999338,10.80629999999339),(10.80629999999339,10.80629999999339),(10.77939999999976,9.48749999999955),(10.77939999999339,10.75249999999338),(10.80629999999976,10.11999999999958),(8.22250000000029,10.77940000000028),(8.85500000000029,10.80630000000028),(9.48749999999961,10.77939999999971),(10.11999999999961,10.80629999999971),(10.75249999999338,10.77939999999339),(10.77939999999339,10.80629999999339),(10.80629999999339,10.77939999999339)])
+ mesh2.setCoords(coo)
+ c = DataArrayInt([32, 4, 32, 33, 5, 39, 40, 41, 6, 32, 5, 33, 34, 8, 41, 42, 43, 17, 32, 8, 34, 35, 31, 43, 44, 45, 37, 32, 14, 12, 10, 16, 13, 11, 9, 15, 32, 22, 12, 14, 24, 27, 13, 28, 23, 32, 24, 0, 5, 22, 29, 7, 30, 23, 32, 24, 14, 16, 10, 12, 22, 20, 26, 28, 15, 9, 11, 27, 21, 19, 25, 32, 22, 5, 8, 1, 0, 24, 26, 20, 30, 17, 18, 2, 29, 25, 19, 21, 32, 1, 8, 31, 3, 18, 37, 38, 36])
+ cI = DataArrayInt([0, 9, 18, 27, 36, 45, 54, 71, 88, 97])
+ mesh2.setConnectivity(c, cI)
+ result, mapResToInit, mapResToRef = MEDCouplingUMesh.Intersect2DMeshes(mesh1, mesh2, eps)
+ result.zipCoords()
+ exp_coo = [9.48750000000001, 9.48750000000001, 10.75249999999975, 9.48749999999955, 10.80629999999976, 9.48749999999955, 9.48749999999961, 10.75249999999971, 10.75249999999338, 10.75249999999338, 10.32506096654411, 10.32506096654411, 9.91493903345591, 10.32506096654411, 9.91493903345591, 9.91493903345591, 10.32506096654411, 9.91493903345591, 10.38162950903903, 10.38162950903903, 9.85837049096099, 10.38162950903903, 9.85837049096099, 9.85837049096099, 10.38162950903903, 9.85837049096099, 10.80629999999339, 10.75249999999338, 9.48749999999961, 10.80629999999971, 10.75249999999338, 10.80629999999339, 10.80629999999339, 10.80629999999339, 9.830000000000023, 10.120000000000008, 10.120000000000008, 10.410000000000004, 10.41000000000001, 10.120000000000008, 10.120000000000008, 9.830000000000013, 9.886654762208451, 10.353345237791569, 9.830000000000023, 10.120000000000008, 9.886654762208451, 9.886654762208451, 9.750000000000005, 10.12000000000001, 9.487499999999809, 10.11999999999986, 9.6729352454803, 10.56706475451937, 9.750000000000005, 10.12000000000001, 9.672935245480499, 9.672935245480499, 9.886654762208451, 9.886654762208451, 10.120000000000008, 9.830000000000013, 10.41000000000001, 10.120000000000008, 10.120000000000008, 10.410000000000004, 9.886654762208451, 10.353345237791569, 10.120000000000013, 10.490000000000004, 10.489999999999988, 10.120000000000013, 10.120000000000017, 9.750000000000021, 10.119999999996494, 10.752499999996544, 10.752499999996566, 10.119999999996466, 10.11999999999988, 9.48749999999978, 9.672935245480499, 9.672935245480499, 10.120000000000017, 9.750000000000021, 10.489999999999988, 10.120000000000013, 10.120000000000013, 10.490000000000004, 9.6729352454803, 10.56706475451937]
+ e1 = [0, 0, 0, 0, 0, 1, 2, 3]
+ e2 = [3, 4, 5, 6, 7, 8, 1, 2]
+ valuesExpected=DataArrayDouble(exp_coo, len(exp_coo)//2, 2)
+ self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-12))
+ self.assertEqual(e1, mapResToInit.getValues())
+ self.assertEqual(e2, mapResToRef.getValues())
+ pass
+
+ def testIntersect2DMeshes8(self):
+ """ Quadratic precision values were improperly reset before testing colinearities
+ This was also impacting the mapping computation. """
+ eps = 1.0e-8
+ mesh1 = MEDCouplingUMesh('assemblyGrid_Pij', 2)
+ coo = DataArrayDouble([(10.80630000000000,-10.80630000000000),(9.48750000000000,-10.80630000000000),(10.75250000000000,-10.80630000000000),(9.48750000000000,-10.75250000000000),(10.75250000000000,-10.75250000000000),(10.80630000000000,-10.75250000000000),(9.48750000000000,-9.48750000000000),(10.75250000000000,-9.48750000000000),(10.80630000000000,-9.48750000000000)])
+ mesh1.setCoords(coo)
+ c = DataArrayInt([5, 2, 1, 3, 4, 5, 0, 2, 4, 5, 5, 4, 3, 6, 7, 5, 5, 4, 7, 8])
+ cI = DataArrayInt([0, 5, 10, 15, 20])
+ mesh1.setConnectivity(c, cI)
+ mesh2 = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(9.48749999999998,-10.75249999999999),(9.48750000000018,-10.80629999999998),(10.75250000000047,-10.75250000000063),(10.75249999999318,-10.80629999999318),(10.80630000000048,-10.75250000000063),(10.80629999999318,-10.80629999999318),(9.48750000000001,-9.48750000000001),(9.48749999999998,-10.11999999999999),(10.75249999999975,-9.48750000000004),(10.40999999999999,-10.11999999999999),(10.32506096654408,-9.91493903345589),(10.11999999999999,-9.82999999999999),(9.91493903345589,-9.91493903345589),(9.82999999999998,-10.11999999999999),(9.91493903345589,-10.32506096654409),(10.11999999999999,-10.40999999999999),(10.32506096654408,-10.32506096654409),(10.12000000000001,-9.48750000000001),(10.75250000000047,-10.12000000000058),(10.12000000000018,-10.75249999999998),(9.70121951672794,-10.53878048327204),(9.70121951672794,-9.70121951672794),(10.80629999999976,-9.48750000000004),(9.48750000000018,-10.77939999999998),(10.75249999999318,-10.77939999999318),(10.12000000000018,-10.80629999999998),(10.77940000000048,-10.75250000000063),(10.80629999999318,-10.77939999999318),(10.77939999999318,-10.80629999999318),(10.77939999999976,-9.48750000000004),(10.80630000000048,-10.12000000000058)])
+ mesh2.setCoords(coo)
+ c = DataArrayInt([32, 1, 0, 2, 3, 23, 19, 24, 25, 32, 3, 2, 4, 5, 24, 26, 27, 28, 32, 16, 14, 12, 10, 15, 13, 11, 9, 32, 0, 6, 12, 14, 7, 21, 13, 20, 32, 6, 8, 2, 0, 14, 16, 10, 12, 17, 18, 19, 20, 15, 9, 11, 21, 32, 2, 8, 22, 4, 18, 29, 30, 26])
+ cI = DataArrayInt([0, 9, 18, 27, 36, 53, 62])
+ mesh2.setConnectivity(c, cI)
+ result, mapResToInit, mapResToRef = MEDCouplingUMesh.Intersect2DMeshes(mesh1, mesh2, eps)
+ result.zipCoords()
+ exp_coo = [9.48749999999998, -10.75249999999999, 9.48750000000018, -10.80629999999998, 10.75250000000047, -10.75250000000063, 10.75249999999318, -10.80629999999318, 10.80630000000048, -10.75250000000063, 10.80629999999318, -10.80629999999318, 9.48750000000001, -9.48750000000001, 10.75249999999975, -9.48750000000004, 10.32506096654408, -9.91493903345589, 9.91493903345589, -9.91493903345589, 9.91493903345589, -10.32506096654409, 10.32506096654408, -10.32506096654409, 10.80629999999976, -9.48750000000004, 10.119999999999989, -10.409999999999961, 9.829999999999997, -10.11999999999999, 10.119999999999983, -9.830000000000005, 10.409999999999968, -10.119999999999987, 9.487499999999994, -10.120000000000001, 9.70121951672795, -9.70121951672795, 9.829999999999997, -10.11999999999999, 9.701219516727935, -10.53878048327204, 10.11999999999988, -9.487500000000026, 10.752500000000111, -10.120000000000335, 10.120000000000225, -10.75250000000031, 9.701219516727935, -10.53878048327204, 10.119999999999989, -10.409999999999961, 10.409999999999968, -10.119999999999987, 10.119999999999983, -9.830000000000005, 9.70121951672795, -9.70121951672795]
+ e1 = [0, 1, 2, 2, 2, 3]
+ e2 = [0, 1, 2, 3, 4, 5]
+ valuesExpected=DataArrayDouble(exp_coo, len(exp_coo)//2, 2)
+ self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-10))
+ self.assertEqual(e1, mapResToInit.getValues())
+ self.assertEqual(e2, mapResToRef.getValues())
+ pass
+
+ def testIntersect2DMeshes9(self):
+ """ Last part of the intersection algorithm was not properly dealing with residual cells when
+ it was a quad polygon just made of 2 edges. Was throwing an exception. """
+ eps = 1e-6
+ back = MEDCouplingUMesh('crh7_rse1', 2)
+ coo = DataArrayDouble([(71.6187499999999915,-10.6521000000000008),(71.0937370510802538,-12.6114750000000022),(71.4852218317702608,-11.6663471329955062),(72.0541666666666600,-10.6521000000000008),(71.8364583333333258,-10.6521000000000008),(71.4708189456447371,-12.8291833333333365),(71.2822779983625026,-12.7203291666666694),(71.9058020353005816,-11.7790412588839590)])
+ back.setCoords(coo)
+ c = DataArrayInt([32, 1, 0, 3, 5, 2, 4, 7, 6])
+ cI = DataArrayInt([0, 9])
+ back.setConnectivity(c, cI)
+ tool = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(71.5737767246627783,-14.0122818133993299),(72.5920244490449136,-7.0390015370978469),(47.7780086628800404,-4.6328708831306278)])
+ tool.setCoords(coo)
+ c = DataArrayInt([5, 1, 0, 2])
+ cI = DataArrayInt([0, 4])
+ tool.setConnectivity(c, cI)
+
+ result, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+ exp_coo = [71.61874999999999, -10.6521, 71.09373705108025, -12.611475000000002, 71.48522183177026, -11.666347132995506, 72.05416666666666, -10.6521, 71.83645833333333, -10.6521, 71.47081894564474, -12.829183333333336, 71.2822779983625, -12.72032916666667, 71.90580203530058, -11.779041258883959, 71.57377672466278, -14.01228181339933, 72.59202444904491, -7.039001537097847, 47.77800866288004, -4.632870883130628, 72.05352566581652, -10.726810361986129, 71.8931109163297, -11.825380957175156, 71.71347100577636, -12.340536509586565, 71.2822779983625, -12.72032916666667, 71.48522183177026, -11.666347132995508, 71.83645833333333, -10.6521, 72.0540064135051, -10.689456555884437, 71.97331829107311, -11.276095659580642, 72.0084757809432, -11.281229403333473, 71.97331829107311, -11.276095659580642]
+ c = [32, 12, 5, 1, 0, 3, 11, 13, 14, 15, 16, 17, 18, 32, 11, 12, 19, 20]
+ cI = [0, 13, 18]
+ e1 = [0, 0]
+ e2 = [0, -1]
+ valuesExpected = DataArrayDouble(exp_coo, len(exp_coo)//2, 2)
+ self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-10))
+ self.assertEqual(c, result.getNodalConnectivity().getValues())
+ self.assertEqual(cI, result.getNodalConnectivityIndex().getValues())
+ self.assertEqual(e1, res2Back.getValues())
+ self.assertEqual(e2, res2Tool.getValues())
+ pass
+
+ def testIntersect2DMeshes10(self):
+ """ Edge::sortIdAbs() was merging points too agressively. This is not the job of the intersector,
+ user should call mergeNodes afterwards. Was throwing an exception later in the algorithm because
+ it had to deal with a degenerated cell.
+ """
+ eps = 1e-6
+ back = MEDCouplingUMesh('crh7_rse1', 2)
+ coo = DataArrayDouble([(-31.31375453845049250,-32.51281383633234157),(-31.69083643301495812,-32.73052216966566874),(-31.50229548573272353,-32.62166800299900871),(-31.53146287178381968,-32.88989573089681073),(-31.62164061609212951,-32.82069991397399633),(-31.42260870511715609,-32.70135478361457615)])
+ back.setCoords(coo)
+ c = DataArrayInt([32, 0, 3, 1, 5, 4, 2])
+ cI = DataArrayInt([0, 7])
+ back.setConnectivity(c, cI)
+ tool = MEDCouplingUMesh('merge', 2)
+ coo = DataArrayDouble([(-29.70769086373595513,-38.08598700945959337),(-27.13627518201525746,-36.53626696210140778),(-35.49132481798474714,-28.48933303789858940)])
+ tool.setCoords(coo)
+ c = DataArrayInt([5, 0, 2, 1])
+ cI = DataArrayInt([0, 4])
+ tool.setConnectivity(c, cI)
+
+ result, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+# print result.getCoords().getValues()
+# print result.getNodalConnectivity().getValues()
+# print result.getNodalConnectivityIndex().getValues()
+# print res2Back.getValues()
+# print res2Tool.getValues()
+ exp_coo = [-31.313754538450493, -32.51281383633234, -31.690836433014958, -32.73052216966567, -31.502295485732724, -32.62166800299901, -31.53146287178382, -32.88989573089681, -31.62164061609213, -32.820699913973996, -31.422608705117156, -32.701354783614576, -29.707690863735955, -38.08598700945959, -27.136275182015257, -36.53626696210141, -35.49132481798475, -28.48933303789859, -31.31376565042576, -32.51283308283808, -31.313773979690932, -32.51282506073775, -31.42261426110479, -32.70136440686744, -31.62164061609211, -32.82069991397398, -31.502305206352943, -32.62167361520171, -31.313769815058347, -32.51282907178791]
+ c = [32, 9, 3, 1, 10, 11, 12, 13, 14, 5, 10, 0, 9]
+ cI = [0, 9, 13]
+ e1 = [0, 0]
+ e2 = [0, -1]
+ valuesExpected = DataArrayDouble(exp_coo, len(exp_coo)//2, 2)
+ self.assertTrue(result.getCoords().isEqual(valuesExpected,1e-10))
+ self.assertEqual(c, result.getNodalConnectivity().getValues())
+ self.assertEqual(cI, result.getNodalConnectivityIndex().getValues())
+ self.assertEqual(e1, res2Back.getValues())
+ self.assertEqual(e2, res2Tool.getValues())
+ pass
+
+ def testIntersect2DMeshes11(self):
+ """ Dealing properly with respective polygon orientation in QuadraticPolygon::haveIAChanceToBeCompletedBy()
+ The two polygons below have same orientation, but one edge of pol1 is colinear to pol2 in opposite directions.
+ """
+ eps = 1.0e-8
+ back = MEDCouplingUMesh('lback', 2)
+ coo = DataArrayDouble([(-2.5,-2.5),(-2.5,2.5),(2.5,2.5),(2.5,-2.5),(0,0),(0,1.66667),(1.66667,1.66667),(1.66667,0)])
+ back.setCoords(coo)
+ c = DataArrayInt([5, 6, 7, 4, 5, 2, 3, 7, 6, 5, 3, 0, 1, 2, 6, 4, 7])
+ cI = DataArrayInt([0, 4, 9, 17])
+ back.setConnectivity(c, cI)
+
+ tool = MEDCouplingUMesh('ltool', 2)
+ coo = DataArrayDouble([(0,0),(0,2.5),(2.5,2.5),(2.5,0)])
+ tool.setCoords(coo)
+ c = DataArrayInt([5, 0, 1, 2, 3])
+ cI = DataArrayInt([0, 5])
+ tool.setConnectivity(c, cI)
+
+ result, res2Back, res2Tool = MEDCouplingUMesh.Intersect2DMeshes(back, tool, eps)
+ self.assertEqual(result.getNodalConnectivity().getValues(), [5, 7, 8, 6, 5, 7, 6, 10, 11, 5, 11, 3, 7, 5, 9, 10, 6, 8, 5, 8, 7, 3, 0, 1, 9])
+ self.assertEqual(result.getNodalConnectivityIndex().getValues(), [0, 4, 9, 13, 18, 25])
+ self.assertEqual(res2Back.getValues(), [0, 1, 1, 2, 2])
+ self.assertEqual(res2Tool.getValues(), [0, 0, -1, 0, -1])
+ pass