]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNELTest/QuadraticPlanarInterpTest3.cxx
Salome HOME
55d6d13d07764c0ad48d044802fbde01b7f173ca
[tools/medcoupling.git] / src / INTERP_KERNELTest / QuadraticPlanarInterpTest3.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "QuadraticPlanarInterpTest.hxx"
20 #include "QuadraticPolygon.hxx"
21 #include "ElementaryEdge.hxx"
22 #include "EdgeArcCircle.hxx"
23 #include "EdgeLin.hxx"
24
25 #include <cmath>
26 #include <sstream>
27 #include <iostream>
28
29 using namespace std;
30 using namespace INTERP_KERNEL;
31
32
33 void QuadraticPlanarInterpTest::checkInOutDetection()
34 {
35   Node *n1=new Node(0.,0.);
36   Node *n2=new Node(1.,0.);
37   Node *n3=new Node(0.5,1.);
38   EdgeLin *e1=new EdgeLin(n1,n2);
39   EdgeLin *e2=new EdgeLin(n2,n3);
40   EdgeLin *e3=new EdgeLin(n3,n1);
41   ComposedEdge *tri=new ComposedEdge;
42   tri->pushBack(e1); tri->pushBack(e2); tri->pushBack(e3);
43   //
44   Node *where=new Node(0.4,0.1);
45   CPPUNIT_ASSERT(tri->isInOrOut(where)); where->decrRef();
46   where=new Node(-0.1,1.);
47   CPPUNIT_ASSERT(!tri->isInOrOut(where)); where->decrRef();
48   where=new Node(0.6,-0.1);
49   CPPUNIT_ASSERT(!tri->isInOrOut(where)); where->decrRef();
50   //Clean-up
51   n1->decrRef(); n2->decrRef(); n3->decrRef();
52   ComposedEdge::Delete(tri);
53 }
54
55 /*!
56  * Check Iterators mechanism.
57  */
58 void QuadraticPlanarInterpTest::checkAssemblingBases1()
59 {
60   Node *n1=new Node(0.,0.);
61   Node *n2=new Node(0.1,0.); EdgeLin *e1_2=new EdgeLin(n1,n2);
62   Node *n3=new Node(0.2,0.); EdgeLin *e2_3=new EdgeLin(n2,n3);
63   Node *n4=new Node(0.3,0.); EdgeLin *e3_4=new EdgeLin(n3,n4);
64   Node *n5=new Node(0.4,0.); EdgeLin *e4_5=new EdgeLin(n4,n5);
65   Node *n6=new Node(0.5,0.); EdgeLin *e5_6=new EdgeLin(n5,n6);
66   Node *n7=new Node(0.6,0.); EdgeLin *e6_7=new EdgeLin(n6,n7);
67   Node *n8=new Node(0.7,0.); EdgeLin *e7_8=new EdgeLin(n7,n8);
68   Node *n9=new Node(0.8,0.); EdgeLin *e8_9=new EdgeLin(n8,n9);
69   Node *n10=new Node(0.9,0.); EdgeLin *e9_10=new EdgeLin(n9,n10);
70   Node *n11=new Node(1.,0.); EdgeLin *e10_11=new EdgeLin(n10,n11);
71   Node *n12=new Node(0.5,1.); EdgeLin *e11_12=new EdgeLin(n11,n12);
72   EdgeLin *e12_1=new EdgeLin(n12,n1);
73   //Only one level
74   e1_2->incrRef(); e2_3->incrRef(); e3_4->incrRef(); e4_5->incrRef(); e5_6->incrRef(); e6_7->incrRef(); 
75   e7_8->incrRef(); e8_9->incrRef(); e9_10->incrRef(); e10_11->incrRef(); e11_12->incrRef(); e12_1->incrRef();
76   ComposedEdge *c=new ComposedEdge;
77   c->pushBack(e1_2); c->pushBack(e2_3); c->pushBack(e3_4); c->pushBack(e4_5); c->pushBack(e5_6); c->pushBack(e6_7);
78   c->pushBack(e7_8); c->pushBack(e8_9); c->pushBack(e9_10); c->pushBack(e10_11); c->pushBack(e11_12); c->pushBack(e12_1);
79   CPPUNIT_ASSERT_EQUAL(12,c->recursiveSize());
80   IteratorOnComposedEdge it(c);
81   CPPUNIT_ASSERT(it.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it.finished());
82   it.next(); CPPUNIT_ASSERT(it.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it.finished());
83   it.next(); it.next(); CPPUNIT_ASSERT(it.current()->getPtr()==e4_5); CPPUNIT_ASSERT(!it.finished());
84   it.previousLoop(); CPPUNIT_ASSERT(it.current()->getPtr()==e3_4); CPPUNIT_ASSERT(!it.finished());
85   it.previousLoop(); CPPUNIT_ASSERT(it.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it.finished());
86   it.previousLoop(); CPPUNIT_ASSERT(it.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it.finished());
87   it.previousLoop(); CPPUNIT_ASSERT(it.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it.finished());
88   it.next(); CPPUNIT_ASSERT(it.finished());
89   it.first(); CPPUNIT_ASSERT(it.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it.finished());
90   it.previousLoop(); CPPUNIT_ASSERT(it.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it.finished());
91   it.nextLoop(); CPPUNIT_ASSERT(it.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it.finished());
92   it.last(); CPPUNIT_ASSERT(it.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it.finished());
93   //Multi-Level
94   ComposedEdge::Delete(c);
95   //(e1_2, (e2_3,(e3_4, e4_5, e5_6, e6_7, (e7_8, e8_9 ), ( e9_10 , e10_11 ), e11_12 ),e12_1 ) )
96   e1_2->incrRef(); e2_3->incrRef(); e3_4->incrRef(); e4_5->incrRef(); e5_6->incrRef(); e6_7->incrRef(); 
97   e7_8->incrRef(); e8_9->incrRef(); e9_10->incrRef(); e10_11->incrRef(); e11_12->incrRef(); e12_1->incrRef();
98   ComposedEdge *c2_2_4=new ComposedEdge; c2_2_4->pushBack(e7_8); c2_2_4->pushBack(e8_9);
99   ComposedEdge *c2_2_5=new ComposedEdge; c2_2_5->pushBack(e9_10); c2_2_5->pushBack(e10_11);
100   ComposedEdge *c2_2=new ComposedEdge; c2_2->pushBack(e3_4); c2_2->pushBack(e4_5); c2_2->pushBack(e5_6);  c2_2->pushBack(e6_7); c2_2->pushBack(c2_2_4); c2_2->pushBack(c2_2_5); c2_2->pushBack(e11_12);
101   ComposedEdge *c2=new ComposedEdge; c2->pushBack(e2_3); c2->pushBack(c2_2); c2->pushBack(e12_1);
102   c=new ComposedEdge; c->pushBack(e1_2); c->pushBack(c2); CPPUNIT_ASSERT_EQUAL(12,c->recursiveSize());
103   IteratorOnComposedEdge it2(c);
104   CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2);
105   it2.next(); CPPUNIT_ASSERT(it2.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it2.finished());
106   it2.next(); CPPUNIT_ASSERT(it2.current()->getPtr()==e3_4); CPPUNIT_ASSERT(!it2.finished());
107   it2.next(); CPPUNIT_ASSERT(it2.current()->getPtr()==e4_5); CPPUNIT_ASSERT(!it2.finished());
108   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e3_4); CPPUNIT_ASSERT(!it2.finished());
109   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it2.finished());
110   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it2.finished());
111   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it2.finished());
112   it2.next(); CPPUNIT_ASSERT(it2.finished());
113   it2.first(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it2.finished());
114   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it2.finished());
115   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it2.finished());
116   it2.last(); CPPUNIT_ASSERT(it2.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it2.finished());
117   it2.first(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it2.finished());
118   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it2.finished());
119   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e3_4); CPPUNIT_ASSERT(!it2.finished());
120   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e4_5); CPPUNIT_ASSERT(!it2.finished());
121   //  substitutions.
122   /*it2.first(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it2.finished());
123   ElementaryEdge *&tmp=it2.current(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_2); CPPUNIT_ASSERT(!it2.finished());
124   ComposedEdge *c1=new ComposedEdge;  Node *n1_bis=new Node(0.,0.05); EdgeLin *e1_1bis=new EdgeLin(n1,n1_bis); EdgeLin *e1bis_2=new EdgeLin(n1_bis,n2); e1_1bis->incrRef(); e1bis_2->incrRef();
125   c1->pushBack(e1_1bis); c1->pushBack(e1bis_2); delete tmp; tmp=(ElementaryEdge *)c1; CPPUNIT_ASSERT_EQUAL(13,c->recursiveSize());
126   CPPUNIT_ASSERT(it2.current()->getPtr()==e1_1bis); CPPUNIT_ASSERT(!it2.finished());// here testing capability of Iterator.'current' method to deal with change of hierarchy.
127   it2.next(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1bis_2); CPPUNIT_ASSERT(!it2.finished());
128   it2.next(); CPPUNIT_ASSERT(it2.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it2.finished());
129   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1bis_2); CPPUNIT_ASSERT(!it2.finished());
130   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_1bis); CPPUNIT_ASSERT(!it2.finished());
131   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it2.finished());
132   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e11_12); CPPUNIT_ASSERT(!it2.finished());
133   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e10_11); CPPUNIT_ASSERT(!it2.finished());
134   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e9_10); CPPUNIT_ASSERT(!it2.finished());
135   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e8_9); CPPUNIT_ASSERT(!it2.finished());
136   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e7_8); CPPUNIT_ASSERT(!it2.finished());
137   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e6_7); CPPUNIT_ASSERT(!it2.finished());
138   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e5_6); CPPUNIT_ASSERT(!it2.finished());
139   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e4_5); CPPUNIT_ASSERT(!it2.finished());
140   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e3_4); CPPUNIT_ASSERT(!it2.finished());
141   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it2.finished());
142   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1bis_2); CPPUNIT_ASSERT(!it2.finished());
143   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_1bis); CPPUNIT_ASSERT(!it2.finished());
144   it2.previousLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it2.finished());
145   //go forward
146   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_1bis); CPPUNIT_ASSERT(!it2.finished());
147   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1bis_2); CPPUNIT_ASSERT(!it2.finished());
148   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e2_3); CPPUNIT_ASSERT(!it2.finished());
149   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e3_4); CPPUNIT_ASSERT(!it2.finished());
150   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e4_5); CPPUNIT_ASSERT(!it2.finished());
151   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e5_6); CPPUNIT_ASSERT(!it2.finished());
152   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e6_7); CPPUNIT_ASSERT(!it2.finished());
153   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e7_8); CPPUNIT_ASSERT(!it2.finished());
154   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e8_9); CPPUNIT_ASSERT(!it2.finished());
155   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e9_10); CPPUNIT_ASSERT(!it2.finished());
156   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e10_11); CPPUNIT_ASSERT(!it2.finished());
157   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e11_12); CPPUNIT_ASSERT(!it2.finished());
158   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e12_1); CPPUNIT_ASSERT(!it2.finished());
159   it2.nextLoop(); CPPUNIT_ASSERT(it2.current()->getPtr()==e1_1bis); CPPUNIT_ASSERT(!it2.finished());*/
160   ComposedEdge::SoftDelete(c2_2_4);
161   ComposedEdge::SoftDelete(c2_2_5);
162   ComposedEdge::SoftDelete(c2_2);
163   ComposedEdge::SoftDelete(c2);
164   ComposedEdge::Delete(c);
165   //clean-up
166   //e1_1bis->decrRef(); e1bis_2->decrRef();
167   e1_2->decrRef(); e2_3->decrRef(); e3_4->decrRef(); e4_5->decrRef(); e5_6->decrRef(); e6_7->decrRef(); 
168   e7_8->decrRef(); e8_9->decrRef(); e9_10->decrRef(); e10_11->decrRef(); e11_12->decrRef(); e12_1->decrRef(); 
169   //n1_bis->decrRef();
170   n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef();
171   n7->decrRef(); n8->decrRef(); n9->decrRef(); n10->decrRef(); n11->decrRef(); n12->decrRef();
172 }
173
174 /*!
175  * Check splitting of 2 polygons. After this operation, all ElementaryEdge are either in/out/on.
176  */
177 void QuadraticPlanarInterpTest::checkAssemblingBases2()
178 {
179   //The "most" basic test1
180   Node *n1=new Node(0.,0.);                Node *n4=new Node(0.,-0.3);   
181   Node *n2=new Node(1.,0.);                Node *n5=new Node(1.,-0.3);
182   Node *n3=new Node(0.5,1.);               Node *n6=new Node(0.5,0.7);
183   EdgeLin *e1_2=new EdgeLin(n1,n2);        EdgeLin *e4_5=new EdgeLin(n4,n5);
184   EdgeLin *e2_3=new EdgeLin(n2,n3);        EdgeLin *e5_6=new EdgeLin(n5,n6);
185   EdgeLin *e3_1=new EdgeLin(n3,n1);        EdgeLin *e6_4=new EdgeLin(n6,n4);
186   //
187   e1_2->incrRef(); e2_3->incrRef(); e3_1->incrRef(); e4_5->incrRef(); e5_6->incrRef(); e6_4->incrRef(); 
188   QuadraticPolygon pol1; pol1.pushBack(e1_2); pol1.pushBack(e2_3); pol1.pushBack(e3_1);
189   QuadraticPolygon pol2; pol2.pushBack(e4_5); pol2.pushBack(e5_6); pol2.pushBack(e6_4);
190   QuadraticPolygon cpyPol1(pol1); int nbOfSplits=0;
191   cpyPol1.splitPolygonsEachOther(pol1,pol2,nbOfSplits);
192   CPPUNIT_ASSERT_EQUAL(5,pol1.recursiveSize());
193   CPPUNIT_ASSERT_EQUAL(5,pol2.recursiveSize());CPPUNIT_ASSERT_EQUAL(15,nbOfSplits);
194   checkBasicsOfPolygons(pol1,pol2,true);
195   CPPUNIT_ASSERT(pol2[1]->getEndNode()==pol1[1]->getEndNode());
196   CPPUNIT_ASSERT(pol2[1]->getEndNode()->getLoc()==ON_1);
197   CPPUNIT_ASSERT(pol2[3]->getEndNode()==pol1[0]->getEndNode());
198   CPPUNIT_ASSERT(pol2[3]->getEndNode()->getLoc()==ON_1);
199   cpyPol1.performLocatingOperation(pol2);
200   ElementaryEdge *tmp=dynamic_cast<ElementaryEdge *>(pol2[0]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e4_5);
201   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
202   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
203   tmp=dynamic_cast<ElementaryEdge *>(pol2[1]); CPPUNIT_ASSERT(tmp);
204   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
205   tmp=dynamic_cast<ElementaryEdge *>(pol2[2]); CPPUNIT_ASSERT(tmp);
206   CPPUNIT_ASSERT(tmp->getLoc()==FULL_IN_1);
207   tmp=dynamic_cast<ElementaryEdge *>(pol2[3]); CPPUNIT_ASSERT(tmp);
208   CPPUNIT_ASSERT(tmp->getLoc()==FULL_IN_1);
209   tmp=dynamic_cast<ElementaryEdge *>(pol2[4]); CPPUNIT_ASSERT(tmp);
210   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
211   //clean-up for test1
212   e1_2->decrRef(); e2_3->decrRef(); e3_1->decrRef(); e4_5->decrRef(); e5_6->decrRef(); e6_4->decrRef();
213   n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef();
214
215   //Deeper test some extremities of pol2 are on edges of pol1.
216
217   n1=new Node(0.,0.);                n4=new Node(1.5,-0.5);   
218   n2=new Node(1.,0.);                n5=new Node(0.5,0.);
219   n3=new Node(0.5,1.);               n6=new Node(0.75,0.5); Node *n7=new Node(2.,0.5);
220   e1_2=new EdgeLin(n1,n2); e2_3=new EdgeLin(n2,n3); e3_1=new EdgeLin(n3,n1);
221   EdgeLin *e5_4=new EdgeLin(n5,n4); EdgeLin *e4_7=new EdgeLin(n4,n7); EdgeLin *e7_6=new EdgeLin(n7,n6); EdgeLin *e6_5=new EdgeLin(n6,n5);
222   //
223   e1_2->incrRef(); e2_3->incrRef(); e3_1->incrRef(); e5_4->incrRef(); e4_7->incrRef(); e7_6->incrRef(); e6_5->incrRef();
224   QuadraticPolygon pol3; pol3.pushBack(e1_2); pol3.pushBack(e2_3); pol3.pushBack(e3_1);
225   QuadraticPolygon pol4; pol4.pushBack(e5_4); pol4.pushBack(e4_7); pol4.pushBack(e7_6); pol4.pushBack(e6_5);
226   QuadraticPolygon cpyPol3(pol3); nbOfSplits=0;
227   cpyPol3.splitPolygonsEachOther(pol3,pol4,nbOfSplits);
228   CPPUNIT_ASSERT_EQUAL(5,pol3.recursiveSize());
229   CPPUNIT_ASSERT_EQUAL(4,pol4.recursiveSize());CPPUNIT_ASSERT_EQUAL(16,nbOfSplits);
230   checkBasicsOfPolygons(pol3,pol4,true);
231   CPPUNIT_ASSERT(pol4[0]->getStartNode()==pol3[0]->getEndNode()); CPPUNIT_ASSERT(pol4[0]->getStartNode()==n5);
232   CPPUNIT_ASSERT(n5->getLoc()==ON_LIM_1);
233   CPPUNIT_ASSERT(pol4[2]->getEndNode()==pol3[2]->getEndNode()); CPPUNIT_ASSERT(pol4[2]->getEndNode()==n6);
234   CPPUNIT_ASSERT(n6->getLoc()==ON_LIM_1);
235   cpyPol3.performLocatingOperation(pol4);
236   tmp=dynamic_cast<ElementaryEdge *>(pol4[1]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e4_7);
237   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
238   tmp=dynamic_cast<ElementaryEdge *>(pol4[3]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e6_5);
239   tmp=dynamic_cast<ElementaryEdge *>(pol4[0]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e5_4);
240   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
241   tmp=dynamic_cast<ElementaryEdge *>(pol4[2]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e7_6);
242   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
243   tmp=dynamic_cast<ElementaryEdge *>(pol4[3]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e6_5);
244   CPPUNIT_ASSERT(tmp->getLoc()==FULL_IN_1);
245   //clean-up for test2
246   e1_2->decrRef(); e2_3->decrRef(); e3_1->decrRef(); e5_4->decrRef(); e4_7->decrRef(); e7_6->decrRef(); e6_5->decrRef();
247   n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef(); n7->decrRef();
248
249   //Test with one edge of pol2 is included in pol1.
250
251   n1=new Node(0.,0.);                n4=new Node(-0.5,0.);   
252   n2=new Node(1.,0.);                n5=new Node(0.,-1.);
253   n3=new Node(0.5,1.);               n6=new Node(0.5,0.);
254   e1_2=new EdgeLin(n1,n2); e2_3=new EdgeLin(n2,n3); e3_1=new EdgeLin(n3,n1);
255   e4_5=new EdgeLin(n4,n5); e5_6=new EdgeLin(n5,n6); e6_4=new EdgeLin(n6,n4);
256   e1_2->incrRef(); e2_3->incrRef(); e3_1->incrRef(); e4_5->incrRef(); e5_6->incrRef(); e6_4->incrRef();
257   QuadraticPolygon pol5; pol5.pushBack(e1_2); pol5.pushBack(e2_3); pol5.pushBack(e3_1);
258   QuadraticPolygon pol6; pol6.pushBack(e4_5); pol6.pushBack(e5_6); pol6.pushBack(e6_4);
259   QuadraticPolygon cpyPol5(pol5); nbOfSplits=0;
260   cpyPol5.splitPolygonsEachOther(pol5,pol6,nbOfSplits);
261   CPPUNIT_ASSERT_EQUAL(4,pol5.recursiveSize());
262   CPPUNIT_ASSERT_EQUAL(4,pol6.recursiveSize()); CPPUNIT_ASSERT_EQUAL(13,nbOfSplits);
263   checkBasicsOfPolygons(pol5,pol6,false);
264   CPPUNIT_ASSERT(pol6[2]->getStartNode()==pol5[0]->getEndNode()); CPPUNIT_ASSERT(pol6[2]->getStartNode()==n6);
265   CPPUNIT_ASSERT(n6->getLoc()==ON_LIM_1);
266   CPPUNIT_ASSERT(pol6[2]->getEndNode()==pol5[0]->getStartNode()); CPPUNIT_ASSERT(pol5[0]->getStartNode()==n1);
267   CPPUNIT_ASSERT(n1->getLoc()==ON_LIM_1);
268   cpyPol5.performLocatingOperation(pol6);
269   tmp=dynamic_cast<ElementaryEdge *>(pol6[0]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e4_5);
270   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
271   tmp=dynamic_cast<ElementaryEdge *>(pol6[1]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e5_6);
272   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
273   tmp=dynamic_cast<ElementaryEdge *>(pol6[2]); CPPUNIT_ASSERT(tmp);
274   CPPUNIT_ASSERT(tmp->getLoc()==FULL_ON_1);
275   tmp=dynamic_cast<ElementaryEdge *>(pol6[3]); CPPUNIT_ASSERT(tmp);
276   CPPUNIT_ASSERT(tmp->getLoc()==FULL_OUT_1);
277   //clean-up test3
278   e1_2->decrRef(); e2_3->decrRef(); e3_1->decrRef(); e4_5->decrRef(); e5_6->decrRef(); e6_4->decrRef();
279   n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef();
280
281   //Test of full overlapped polygons.
282
283   n1=new Node(0.,0.);                n4=new Node(0.,0.);   
284   n2=new Node(1.,0.);                n5=new Node(1.,0.);
285   n3=new Node(0.5,1.);               n6=new Node(0.5,1.);
286   e1_2=new EdgeLin(n1,n2); e2_3=new EdgeLin(n2,n3); e3_1=new EdgeLin(n3,n1);
287   e4_5=new EdgeLin(n4,n5); e5_6=new EdgeLin(n5,n6); e6_4=new EdgeLin(n6,n4);
288   e1_2->incrRef(); e2_3->incrRef(); e3_1->incrRef(); e4_5->incrRef(); e5_6->incrRef(); e6_4->incrRef();
289   QuadraticPolygon pol7; pol7.pushBack(e1_2); pol7.pushBack(e2_3); pol7.pushBack(e3_1);
290   QuadraticPolygon pol8; pol8.pushBack(e4_5); pol8.pushBack(e5_6); pol8.pushBack(e6_4);
291   QuadraticPolygon cpyPol7(pol7); nbOfSplits=0;
292   cpyPol7.splitPolygonsEachOther(pol7,pol8,nbOfSplits);
293   tmp=dynamic_cast<ElementaryEdge *>(pol8[0]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e1_2);
294   CPPUNIT_ASSERT(tmp->getLoc()==FULL_ON_1);
295   tmp=dynamic_cast<ElementaryEdge *>(pol8[1]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e2_3);
296   CPPUNIT_ASSERT(tmp->getLoc()==FULL_ON_1);
297   tmp=dynamic_cast<ElementaryEdge *>(pol8[2]); CPPUNIT_ASSERT(tmp); CPPUNIT_ASSERT(tmp->getPtr()==e3_1);
298   CPPUNIT_ASSERT(tmp->getLoc()==FULL_ON_1);
299   //clean-up test4
300   e1_2->decrRef(); e2_3->decrRef(); e3_1->decrRef(); e4_5->decrRef(); e5_6->decrRef(); e6_4->decrRef();
301   n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef(); n5->decrRef(); n6->decrRef();
302 }
303
304 void QuadraticPlanarInterpTest::checkBasicsOfPolygons(QuadraticPolygon& pol1, QuadraticPolygon& pol2, bool checkDirection)
305 {
306   IteratorOnComposedEdge it1(&pol1),it2(&pol2); it1.previousLoop(); it2.previousLoop();
307   Node *nIter1=it1.current()->getEndNode(); Node *nIter2=it2.current()->getEndNode();
308   for(it2.first();!it2.finished();it2.next())
309     {
310       CPPUNIT_ASSERT(nIter2==it2.current()->getStartNode());
311       if(checkDirection)
312         CPPUNIT_ASSERT(it2.current()->getDirection());
313       nIter2=it2.current()->getEndNode();
314     }
315   for(it1.first();!it1.finished();it1.next())
316     {
317       CPPUNIT_ASSERT(nIter1==it1.current()->getStartNode());
318       if(checkDirection)
319         CPPUNIT_ASSERT(it1.current()->getDirection());
320       nIter1=it1.current()->getEndNode();
321     }
322 }