]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNELTest/QuadraticPlanarInterpTest2.cxx
Salome HOME
50e2c4cc398313837d6eef516e0f9efcd248057a
[tools/medcoupling.git] / src / INTERP_KERNELTest / QuadraticPlanarInterpTest2.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 // Author : Anthony Geay (CEA/DEN)
20
21 #include "QuadraticPlanarInterpTest.hxx"
22 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
23 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
24 #include "InterpKernelGeo2DEdgeLin.hxx"
25
26 #include <cmath>
27 #include <sstream>
28 #include <iostream>
29
30 using namespace INTERP_KERNEL;
31
32 namespace INTERP_TEST
33 {
34
35 static const double ADMISSIBLE_ERROR = 1.e-14;
36
37 void QuadraticPlanarInterpTest::IntersectArcCircleBase()
38 {
39   double center[2]={0.5,0.5};
40   double radius=0.3;
41   EdgeArcCircle *e1=buildArcOfCircle(center,radius,M_PI/4.,M_PI/3.);
42   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI/3),ADMISSIBLE_ERROR);
43   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(M_PI/4),ADMISSIBLE_ERROR);
44   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(M_PI/4),ADMISSIBLE_ERROR);
45   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/3),ADMISSIBLE_ERROR);
46   e1->decrRef();
47   //
48   e1=buildArcOfCircle(center,radius,M_PI/3.,M_PI/2.);
49   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI/2),ADMISSIBLE_ERROR);
50   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(M_PI/3),ADMISSIBLE_ERROR);
51   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(M_PI/3),ADMISSIBLE_ERROR);
52   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/2),ADMISSIBLE_ERROR);
53   e1->decrRef();
54   //
55   e1=buildArcOfCircle(center,radius,M_PI/3.,3.*M_PI/4.);
56   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(3*M_PI/4),ADMISSIBLE_ERROR);
57   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(M_PI/3),ADMISSIBLE_ERROR);
58   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(3*M_PI/4),ADMISSIBLE_ERROR);
59   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/2),ADMISSIBLE_ERROR);//<<
60   e1->decrRef();
61   //
62   e1=buildArcOfCircle(center,radius,3*M_PI/4,7*M_PI/8);
63   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(7*M_PI/8),ADMISSIBLE_ERROR);
64   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(3*M_PI/4),ADMISSIBLE_ERROR);
65   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(7*M_PI/8),ADMISSIBLE_ERROR);
66   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(3*M_PI/4),ADMISSIBLE_ERROR);
67   e1->decrRef();
68   //
69   e1=buildArcOfCircle(center,radius,7.*M_PI/8.,9.*M_PI/8.);
70   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI),ADMISSIBLE_ERROR);//<<
71   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(7*M_PI/8),ADMISSIBLE_ERROR);
72   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(9*M_PI/8),ADMISSIBLE_ERROR);
73   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(7*M_PI/8),ADMISSIBLE_ERROR);
74   e1->decrRef();
75   //
76   e1=buildArcOfCircle(center,radius,9.*M_PI/8.,11.*M_PI/8.);
77   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(9*M_PI/8),ADMISSIBLE_ERROR);
78   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(11*M_PI/8),ADMISSIBLE_ERROR);
79   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(11*M_PI/8),ADMISSIBLE_ERROR);
80   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(9*M_PI/8),ADMISSIBLE_ERROR);
81   e1->decrRef();
82   //
83   e1=buildArcOfCircle(center,radius,11.*M_PI/8.,7.*M_PI/4.);
84   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(11*M_PI/8),ADMISSIBLE_ERROR);
85   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(7*M_PI/4),ADMISSIBLE_ERROR);
86   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(3*M_PI/2),ADMISSIBLE_ERROR);//<<
87   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(7*M_PI/4),ADMISSIBLE_ERROR);
88   e1->decrRef();
89   //
90   e1=buildArcOfCircle(center,radius,7.*M_PI/4.,15.*M_PI/8.);
91   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(7*M_PI/4),ADMISSIBLE_ERROR);
92   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(15*M_PI/8),ADMISSIBLE_ERROR);
93   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(7*M_PI/4),ADMISSIBLE_ERROR);
94   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(15*M_PI/8),ADMISSIBLE_ERROR);
95   e1->decrRef();
96   //
97   e1=buildArcOfCircle(center,radius,-M_PI/8.,M_PI/4.);
98   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI/4),ADMISSIBLE_ERROR);
99   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(0.),ADMISSIBLE_ERROR);      //<<
100   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(15*M_PI/8),ADMISSIBLE_ERROR);
101   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/4),ADMISSIBLE_ERROR);
102   e1->decrRef();
103   //
104   // ArcCArcCIntersector
105   //
106   TypeOfLocInEdge where1,where2;
107   std::vector<Node *> v4;
108   MergePoints v3;
109   EdgeArcCircle *e2;
110   ArcCArcCIntersector *intersector=0;
111   for(unsigned k=0;k<8;k++)
112     {
113       e1=buildArcOfCircle(center,radius,M_PI/4.+k*M_PI/4.,M_PI/3.+k*M_PI/4.);
114       e2=buildArcOfCircle(center,radius,M_PI/4.+k*M_PI/4.,M_PI/3.+k*M_PI/4.);
115       intersector=new ArcCArcCIntersector(*e1,*e2);
116       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
117       CPPUNIT_ASSERT(where1==START && where2==END);
118       delete intersector; v3.clear(); e2->decrRef();
119       //
120       e2=buildArcOfCircle(center,radius,7*M_PI/24.+k*M_PI/4.,M_PI/3.+k*M_PI/4.);
121       intersector=new ArcCArcCIntersector(*e1,*e2);
122       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
123       CPPUNIT_ASSERT(where1==INSIDE && where2==END);
124       delete intersector; v3.clear(); e2->decrRef();
125       //
126       e2=buildArcOfCircle(center,radius,M_PI/4.+k*M_PI/4.,7*M_PI/24.+k*M_PI/4.);
127       intersector=new ArcCArcCIntersector(*e1,*e2);
128       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
129       CPPUNIT_ASSERT(where1==START && where2==INSIDE);
130       delete intersector; v3.clear(); e2->decrRef();
131       //
132       e2=buildArcOfCircle(center,radius,13.*M_PI/48.+k*M_PI/4.,15*M_PI/48.+k*M_PI/4.);
133       intersector=new ArcCArcCIntersector(*e1,*e2);
134       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
135       CPPUNIT_ASSERT(where1==INSIDE && where2==INSIDE);
136       delete intersector; v3.clear(); e2->decrRef();
137       //
138       e2=buildArcOfCircle(center,radius,-M_PI/4.+k*M_PI/4.,M_PI/6.+k*M_PI/4.);
139       intersector=new ArcCArcCIntersector(*e1,*e2);
140       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
141       CPPUNIT_ASSERT(where1==OUT_BEFORE && where2==OUT_BEFORE);
142       delete intersector; v3.clear(); e2->decrRef();
143       //
144       e2=buildArcOfCircle(center,radius,0+k*M_PI/4.,5*M_PI/6.+k*M_PI/4.);
145       intersector=new ArcCArcCIntersector(*e1,*e2);
146       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
147       CPPUNIT_ASSERT(where1==OUT_BEFORE && where2==OUT_AFTER);
148       delete intersector; v3.clear(); e2->decrRef();
149       e1->decrRef();
150     }
151   // Ok now let's see intersection only. 2 intersections R1 > R2 ; dist(circle1,circle2)>R1; Opposite order.
152   for(unsigned k=0;k<8;k++)
153     {
154       center[0]=0.; center[1]=0.;
155       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
156       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
157       e2=buildArcOfCircle(center2,1.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
158       intersector=new ArcCArcCIntersector(*e1,*e2);
159       bool order;
160       bool obvious,areOverlapped;
161       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
162       CPPUNIT_ASSERT(!obvious && !areOverlapped);
163       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
164       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
165       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
166       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
167       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
168       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
169       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
170       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.35587863972199624,1e-10);
171       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
172         (*iter)->decrRef();
173       v4.clear(); v3.clear();
174       delete intersector; e2->decrRef(); e1->decrRef();
175     }
176   // Ok now let's see intersection only. 2 intersections R1 > R2 ; dist(circle1,circle2)>R1; Same order.
177   for(unsigned k=0;k<7;k++)
178     {
179       center[0]=0.; center[1]=0.;
180       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
181       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
182       e2=buildArcOfCircle(center2,1.,M_PI+(k+1)*M_PI/4.,M_PI+(k-1)*M_PI/4.);
183       intersector=new ArcCArcCIntersector(*e1,*e2);
184       bool order;
185       bool obvious,areOverlapped;
186       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
187       CPPUNIT_ASSERT(!obvious && !areOverlapped);
188       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
189       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
190       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
191       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
192       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
193       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
194       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
195       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.35587863972199624,1e-10);
196       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
197         (*iter)->decrRef();
198       v4.clear(); v3.clear();
199       delete intersector; e2->decrRef(); e1->decrRef();
200     }
201   // 2 intersections R1>R2 ; dist(circle1,circle2)<R1; Same order.
202   for(unsigned k=0;k<8;k++)
203     {
204       center[0]=0.; center[1]=0.;
205       double center2[2]; center2[0]=2.8*cos(k*M_PI/4.); center2[1]=2.8*sin(k*M_PI/4.);
206       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
207       e2=buildArcOfCircle(center2,1.,(k)*M_PI/4.-M_PI/2.,(k)*M_PI/4.+M_PI/2.);
208       intersector=new ArcCArcCIntersector(*e1,*e2);
209       bool order;
210       bool obvious,areOverlapped;
211       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
212       CPPUNIT_ASSERT(!obvious && !areOverlapped);
213       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
214       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
215       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
216       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
217       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
218       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
219       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
220       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.6793851523346941,1e-10);
221       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
222         (*iter)->decrRef();
223       v4.clear(); v3.clear();
224       delete intersector; e2->decrRef(); e1->decrRef();
225     }
226   // 2 intersections R1>R2 ; dist(circle1,circle2)<R1; Opp order.
227   for(unsigned k=0;k<8;k++)
228     {
229       center[0]=0.; center[1]=0.;
230       double center2[2]; center2[0]=2.8*cos(k*M_PI/4.); center2[1]=2.8*sin(k*M_PI/4.);
231       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
232       e2=buildArcOfCircle(center2,1.,(k)*M_PI/4.+M_PI/2.,(k)*M_PI/4.-M_PI/2.);
233       intersector=new ArcCArcCIntersector(*e1,*e2);
234       bool order;
235       bool obvious,areOverlapped;
236       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
237       CPPUNIT_ASSERT(!obvious && !areOverlapped);
238       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
239       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
240       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
241       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
242       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
243       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
244       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
245       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.6793851523346941,1e-10);
246       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
247         (*iter)->decrRef();
248       v4.clear(); v3.clear();
249       delete intersector; e2->decrRef(); e1->decrRef();
250     }
251   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)>R2; Opposite order.
252   for(unsigned k=0;k<1;k++)
253     {
254       double center2[2]; center[0]=0.; center[1]=0.;
255       center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
256       e1=buildArcOfCircle(center,1.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
257       e2=buildArcOfCircle(center2,3.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
258       intersector=new ArcCArcCIntersector(*e1,*e2);
259       bool order;
260       bool obvious,areOverlapped;
261       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
262       CPPUNIT_ASSERT(!obvious && !areOverlapped);
263       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
264       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
265       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
266       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
267       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
268       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
269       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
270       CPPUNIT_ASSERT_DOUBLES_EQUAL(1.1195732971845034,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
271       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
272         (*iter)->decrRef();
273       v4.clear(); v3.clear();
274       delete intersector; e2->decrRef(); e1->decrRef();
275     }
276   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)>R2; same order.
277   for(unsigned k=0;k<8;k++)
278     {
279       double center2[2]; center[0]=0.; center[1]=0.;
280       center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
281       e1=buildArcOfCircle(center,1.,(k+1)*M_PI/4.,(k-1)*M_PI/4.);
282       e2=buildArcOfCircle(center2,3.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
283       intersector=new ArcCArcCIntersector(*e1,*e2);
284       bool order;
285       bool obvious,areOverlapped;
286       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
287       CPPUNIT_ASSERT(!obvious && !areOverlapped);
288       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
289       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
290       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
291       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
292       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
293       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
294       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
295       CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.1195732971845034,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
296       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
297         (*iter)->decrRef();
298       v4.clear(); v3.clear();
299       delete intersector; e2->decrRef(); e1->decrRef();
300     }
301   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)<R2; same order.
302   for(unsigned k=0;k<8;k++)
303     {
304       double center2[2]; center[0]=0.; center[1]=0.;
305       center2[0]=-2.8*cos(k*M_PI/4.); center2[1]=-2.8*sin(k*M_PI/4.);
306       e1=buildArcOfCircle(center,1.,(k)*M_PI/4.+M_PI/2.,(k)*M_PI/4.-M_PI/2.);
307       e2=buildArcOfCircle(center2,3.,(k+1)*M_PI/4.,(k-1)*M_PI/4.);
308       intersector=new ArcCArcCIntersector(*e1,*e2);
309       bool order;
310       bool obvious,areOverlapped;
311       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
312       CPPUNIT_ASSERT(!obvious && !areOverlapped);
313       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
314       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
315       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
316       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
317       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
318       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
319       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
320       CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0844420190512074,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
321       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
322         (*iter)->decrRef();
323       v4.clear(); v3.clear();
324       delete intersector; e2->decrRef(); e1->decrRef();
325     }
326   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)<R2; opp. order.
327   for(unsigned k=0;k<8;k++)
328     {
329       double center2[2]; center[0]=0.; center[1]=0.;
330       center2[0]=-2.8*cos(k*M_PI/4.); center2[1]=-2.8*sin(k*M_PI/4.);
331       e1=buildArcOfCircle(center,1.,(k)*M_PI/4.+M_PI/2.,(k)*M_PI/4.-M_PI/2.);
332       e2=buildArcOfCircle(center2,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
333       intersector=new ArcCArcCIntersector(*e1,*e2);
334       bool order;
335       bool obvious,areOverlapped;
336       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
337       CPPUNIT_ASSERT(!obvious && !areOverlapped);
338       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
339       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
340       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
341       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
342       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
343       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
344       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
345       CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0844420190512074,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
346       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
347         (*iter)->decrRef();
348       v4.clear(); v3.clear();
349       delete intersector; e2->decrRef(); e1->decrRef();
350     }
351   // Tangent intersection
352   QUADRATIC_PLANAR::setPrecision(1e-5);
353   for(unsigned k=0;k<8;k++)
354     {
355       double center2[2]; center[0]=0.; center[1]=0.;
356       center2[0]=4.*cos(k*M_PI/4.); center2[1]=4.*sin(k*M_PI/4.);
357       e1=buildArcOfCircle(center,1.,(k+1)*M_PI/4.,(k-1)*M_PI/4.);
358       e2=buildArcOfCircle(center2,3.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
359       intersector=new ArcCArcCIntersector(*e1,*e2);
360       bool order;
361       bool obvious,areOverlapped;
362       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
363       CPPUNIT_ASSERT(!obvious && !areOverlapped);
364       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order); // order has no sence here because v4.size() expected to 1 but for valgrind serenity test.
365       CPPUNIT_ASSERT_EQUAL(1,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
366       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
367       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
368       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
369         (*iter)->decrRef();
370       v4.clear(); v4.clear();
371       delete intersector; e2->decrRef(); e1->decrRef();
372     }
373   QUADRATIC_PLANAR::setPrecision(1e-14);
374   // Extremities # 1
375   for(unsigned k=0;k<8;k++)
376     {
377       center[0]=0.; center[1]=0.;
378       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
379       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
380       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.-0.55978664859225125,M_PI+k*M_PI/4.+0.55978664859225125);
381       intersector=new ArcCArcCIntersector(*e1,*e2);
382       bool order;
383       bool obvious,areOverlapped;
384       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
385       CPPUNIT_ASSERT(!obvious && !areOverlapped);
386       CPPUNIT_ASSERT(!intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT_EQUAL(0,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(2,(int)v3.getNumberOfAssociations());
387       CPPUNIT_ASSERT(e1->getStartNode()==e2->getEndNode()); CPPUNIT_ASSERT(e2->getStartNode()==e1->getEndNode());
388       v4.clear(); v3.clear();
389       delete intersector; e2->decrRef(); e1->decrRef();
390     }
391   for(unsigned k=0;k<8;k++)
392     {
393       center[0]=0.; center[1]=0.;
394       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
395       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
396       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.55978664859225125,M_PI+k*M_PI/4.-0.55978664859225125);
397       intersector=new ArcCArcCIntersector(*e1,*e2);
398       bool order;
399       bool obvious,areOverlapped;
400       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
401       CPPUNIT_ASSERT(!obvious && !areOverlapped);
402       CPPUNIT_ASSERT(!intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT_EQUAL(0,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(2,(int)v3.getNumberOfAssociations());
403       CPPUNIT_ASSERT(e1->getStartNode()==e2->getStartNode()); CPPUNIT_ASSERT(e2->getEndNode()==e1->getEndNode());
404       v4.clear(); v3.clear();
405       delete intersector; e2->decrRef(); e1->decrRef();
406     }
407   // Extremities # 2
408   for(unsigned k=0;k<8;k++)
409     {
410       center[0]=0.; center[1]=0.;
411       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
412       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
413       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.55978664859225125,M_PI+k*M_PI/4.-0.7);
414       intersector=new ArcCArcCIntersector(*e1,*e2);
415       bool order;
416       bool obvious,areOverlapped;
417       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
418       CPPUNIT_ASSERT(!obvious && !areOverlapped);
419       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3));
420       CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(1,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(1,(int)v3.getNumberOfAssociations());
421       CPPUNIT_ASSERT(e1->getStartNode()==e2->getStartNode()); CPPUNIT_ASSERT(e1->getEndNode()==v4[0]);
422       v4[0]->decrRef();
423       v4.clear(); v3.clear();
424       delete intersector; e2->decrRef(); e1->decrRef();
425     }
426   // Extremities # 3
427   for(unsigned k=0;k<8;k++)
428     {
429       center[0]=0.; center[1]=0.;
430       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
431       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
432       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.7,M_PI+k*M_PI/4.-0.7);
433       intersector=new ArcCArcCIntersector(*e1,*e2);
434       bool order;
435       bool obvious,areOverlapped;
436       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
437       CPPUNIT_ASSERT(!obvious && !areOverlapped);
438       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
439       CPPUNIT_ASSERT(e1->getStartNode()==v4[0]); CPPUNIT_ASSERT(e1->getEndNode()==v4[1]);
440       v4[0]->decrRef(); v4[1]->decrRef();
441       v4.clear(); v3.clear();
442       delete intersector; e2->decrRef(); e1->decrRef();
443     }
444   // Extremities # 4
445   for(unsigned k=0;k<8;k++)
446     {
447       center[0]=0.; center[1]=0.;
448       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
449       Node *nodeS=new Node(center[0]+3.*cos(k*M_PI/4.-0.17793931986099812),center[1]+3.*sin(k*M_PI/4.-0.17793931986099812));
450       Node *nodeE=new Node(center[0]+3.*cos(k*M_PI/4.),center[1]+3.*sin(k*M_PI/4.));
451       double angle=k*M_PI/4.-0.17793931986099812;
452       angle=angle>M_PI?angle-2.*M_PI:angle;
453       e1=new EdgeArcCircle(nodeS,nodeE,//Problem of precision 1e-14 to easily reached.
454                            center,3.,angle,0.17793931986099812);
455       nodeS->decrRef(); nodeE->decrRef();
456       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.7,M_PI+k*M_PI/4.-0.7);
457       intersector=new ArcCArcCIntersector(*e1,*e2);
458       bool order;
459       bool obvious,areOverlapped;
460       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
461       CPPUNIT_ASSERT(!obvious && !areOverlapped);
462       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(1,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
463       CPPUNIT_ASSERT(e1->getStartNode()==v4[0]);
464       v4[0]->decrRef();
465       v4.clear(); v3.clear();
466       delete intersector; e2->decrRef(); e1->decrRef();
467     }
468   //Extremities # 5
469   for(unsigned k=0;k<8;k++)
470     {
471       center[0]=0.; center[1]=0.;
472       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
473       Node *nodeS=new Node(center[0]+3.*cos(k*M_PI/4.-0.17793931986099812),center[1]+3.*sin(k*M_PI/4.-0.17793931986099812));
474       Node *nodeE=new Node(center[0]+3.*cos(k*M_PI/4.)+0.5,center[1]+3.*sin(k*M_PI/4.));
475       double angle=k*M_PI/4.-0.17793931986099812;
476       angle=angle>M_PI?angle-2.*M_PI:angle;
477       e1=new EdgeArcCircle(nodeS,nodeE,//Problem of precision 1e-14 to easily reached.
478                            center,3.,angle,0.67793931986099812);
479       nodeS->decrRef(); nodeE->decrRef();
480       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.7,M_PI+k*M_PI/4.-0.7);
481       intersector=new ArcCArcCIntersector(*e1,*e2);
482       bool order;
483       bool obvious,areOverlapped;
484       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
485       CPPUNIT_ASSERT(!obvious && !areOverlapped);
486       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
487       CPPUNIT_ASSERT(e1->getStartNode()==v4[0]);
488       v4[0]->decrRef(); v4[1]->decrRef();
489       v4.clear(); v3.clear();
490       delete intersector; e2->decrRef(); e1->decrRef();
491     }
492 }
493
494 void QuadraticPlanarInterpTest::IntersectArcCircleFull()
495 {
496   double center1[2]; center1[0]=0.;   center1[1]=0.;   double radius1=3.;
497   double center2[2]; center2[0]=0.75; center2[1]=-2.6; double radius2=1.;
498   EdgeArcCircle *e1=buildArcOfCircle(center1,radius1,-M_PI/3.,4.*M_PI/3.);
499   EdgeArcCircle *e2=buildArcOfCircle(center2,radius2,0.,M_PI/2.);
500   MergePoints commonNode;
501   QuadraticPolygon pol1; QuadraticPolygon pol2;
502   QuadraticPolygon pol3; QuadraticPolygon pol4;
503   pol3.pushBack(e1); pol4.pushBack(e2);
504   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol3.getPerimeter(),1e-6);
505   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol4.getPerimeter(),1e-6);
506   CPPUNIT_ASSERT_DOUBLES_EQUAL(19.6648305849,pol3.getArea(),1e-6);
507   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol4.getArea(),1e-6);
508   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol1,pol2));
509   CPPUNIT_ASSERT_EQUAL(2,pol1.size());
510   CPPUNIT_ASSERT_EQUAL(2,pol2.size());
511   CPPUNIT_ASSERT_DOUBLES_EQUAL(19.6648305849,pol1.getArea(),1e-6);
512   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol2.getArea(),1e-6);
513   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol1.getPerimeter(),1e-6);
514   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol2.getPerimeter(),1e-6);
515   //
516   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
517   e2=buildArcOfCircle(center2,radius2,0.,M_PI/2.);
518   commonNode.clear();
519   QuadraticPolygon pol5; QuadraticPolygon pol6;
520   QuadraticPolygon pol7; QuadraticPolygon pol8;
521   pol7.pushBack(e1); pol8.pushBack(e2);
522   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol7.getPerimeter(),1e-6);
523   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol8.getPerimeter(),1e-6);
524   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol7.getArea(),1e-6);
525   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol8.getArea(),1e-6);
526   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol5,pol6));
527   CPPUNIT_ASSERT_EQUAL(2,pol5.size());
528   CPPUNIT_ASSERT_EQUAL(2,pol6.size());
529   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol5.getArea(),1e-6);
530   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol6.getArea(),1e-6);
531   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol5.getPerimeter(),1e-6);
532   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol6.getPerimeter(),1e-6);
533   //
534   center2[0]=3.5; center2[1]=0.;
535   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
536   e2=buildArcOfCircle(center2,radius2,M_PI/2.,3*M_PI/2.);
537   commonNode.clear();
538   QuadraticPolygon pol9; QuadraticPolygon pol10;
539   QuadraticPolygon pol11; QuadraticPolygon pol12;
540   pol11.pushBack(e1); pol12.pushBack(e2);
541   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol11.getPerimeter(),1e-6);
542   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol12.getPerimeter(),1e-6);
543   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol11.getArea(),1e-6);
544   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol12.getArea(),1e-6);
545   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol9,pol10));
546   CPPUNIT_ASSERT_EQUAL(3,pol9.size());
547   CPPUNIT_ASSERT_EQUAL(3,pol10.size());
548   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol9.getPerimeter(),1e-6);
549   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol10.getPerimeter(),1e-6);
550   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol9.getArea(),1e-6);
551   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol10.getArea(),1e-6);
552   //
553   center2[0]=0.; center2[1]=0.; radius2=radius1;
554   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
555   e2=buildArcOfCircle(center2,radius2,M_PI/3.,2*M_PI/3.);
556   commonNode.clear();
557   QuadraticPolygon pol13; QuadraticPolygon pol14;
558   QuadraticPolygon pol15; QuadraticPolygon pol16;
559   pol15.pushBack(e1); pol16.pushBack(e2);
560   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol15.getPerimeter(),1e-6);
561   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol16.getPerimeter(),1e-6);
562   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol15.getArea(),1e-6);
563   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.6095032974147,pol16.getArea(),1e-6);
564   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol13,pol14));
565   CPPUNIT_ASSERT_EQUAL(3,pol13.size());
566   CPPUNIT_ASSERT_EQUAL(1,pol14.size());
567   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol13.getPerimeter(),1e-6);
568   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol13.getArea(),1e-6);
569   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol14.getPerimeter(),1e-6);
570   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.6095032974147,pol14.getArea(),1e-6);
571   //
572   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
573   e2=buildArcOfCircle(center2,radius2,2*M_PI/3.,M_PI/3.);
574   commonNode.clear();
575   QuadraticPolygon pol17; QuadraticPolygon pol18;
576   QuadraticPolygon pol19; QuadraticPolygon pol20;
577   pol19.pushBack(e1); pol20.pushBack(e2);
578   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol19.getPerimeter(),1e-6);
579   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol20.getPerimeter(),1e-6);
580   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol19.getArea(),1e-6);
581   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.6095032974147,pol20.getArea(),1e-6);
582   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol17,pol18));
583   CPPUNIT_ASSERT_EQUAL(3,pol17.size());
584   CPPUNIT_ASSERT_EQUAL(1,pol18.size());
585   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol17.getPerimeter(),1e-6);
586   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol17.getArea(),1e-6);
587   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol18.getPerimeter(),1e-6);
588   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.6095032974147,pol18.getArea(),1e-6);
589   //no intersection #1
590   center2[0]=4.277; center2[1]=-4.277;
591   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
592   e2=buildArcOfCircle(center2,radius2,M_PI/4.,5*M_PI/4.);
593   QuadraticPolygon polTemp1; QuadraticPolygon polTemp2;
594   CPPUNIT_ASSERT(!e1->intersectWith(e2,commonNode,polTemp1,polTemp2));
595   e1->decrRef(); e2->decrRef();
596   //no intersection #2
597   center2[0]=1.; center2[1]=-1.; radius2=0.2;
598   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
599   e2=buildArcOfCircle(center2,radius2,M_PI/4.,5*M_PI/4.);
600   CPPUNIT_ASSERT(!e1->intersectWith(e2,commonNode,polTemp1,polTemp2));
601   e1->decrRef(); e2->decrRef();
602 }
603
604 void QuadraticPlanarInterpTest::IntersectArcCircleSegumentBase()
605 {
606   double center[2]={2.,2.};
607   EdgeArcCircle *e1=buildArcOfCircle(center,2.3,M_PI/4.,5.*M_PI/4.);
608   EdgeLin *e2=new EdgeLin(-1.3,1.,3.,5.3);
609   EdgeIntersector *intersector=new ArcCSegIntersector(*e1,*e2);
610   bool order;
611   bool obvious,areOverlapped;
612   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
613   CPPUNIT_ASSERT(!obvious && !areOverlapped);
614   std::vector<Node *> v4;
615   MergePoints v3;
616   CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order); CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
617   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[0])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3,(*v4[0])[1],1e-10);
618   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.3,(*v4[1])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[1])[1],1e-10);
619   v4[0]->decrRef(); v4[1]->decrRef(); e2->decrRef(); v3.clear(); v4.clear(); delete intersector;
620   //
621   e2=new EdgeLin(3.,5.3,-1.3,1.);
622   intersector=new ArcCSegIntersector(*e1,*e2);
623   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped); CPPUNIT_ASSERT(!obvious && !areOverlapped);
624   CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
625   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[0])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3,(*v4[0])[1],1e-10);
626   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.3,(*v4[1])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[1])[1],1e-10);
627   v4[0]->decrRef(); v4[1]->decrRef(); e2->decrRef(); v3.clear(); v4.clear(); delete intersector;
628   // tangent intersection
629   e2=new EdgeLin(-1.,4.3,3.,4.3);
630   intersector=new ArcCSegIntersector(*e1,*e2);
631   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped); CPPUNIT_ASSERT(!obvious && !areOverlapped);
632   CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(1,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
633   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[0])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3,(*v4[0])[1],1e-10);
634   v4[0]->decrRef(); e2->decrRef(); v3.clear(); delete intersector;
635   // no intersection
636   e2=new EdgeLin(-2.,-2.,-1.,-3.);
637   intersector=new ArcCSegIntersector(*e1,*e2);
638   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped); CPPUNIT_ASSERT(obvious && !areOverlapped);
639   e2->decrRef(); v3.clear(); delete intersector;
640   //
641   e1->decrRef();
642 }
643
644 QuadraticPolygon *QuadraticPlanarInterpTest::buildQuadraticPolygonCoarseInfo(const double *coords, const int *conn, int lgth)
645 {
646   std::vector<INTERP_KERNEL::Node *> nodes;
647   for(int i=0;i<lgth;i++)
648     nodes.push_back(new INTERP_KERNEL::Node(coords[2*conn[i]],coords[2*conn[i]+1]));
649   return INTERP_KERNEL::QuadraticPolygon::BuildArcCirclePolygon(nodes);
650 }
651
652 EdgeArcCircle *QuadraticPlanarInterpTest::buildArcOfCircle(const double *center, double radius, double alphaStart, double alphaEnd)
653 {
654   double alphaM=(alphaStart+alphaEnd)/2;
655   return new EdgeArcCircle(center[0]+cos(alphaStart)*radius,center[1]+sin(alphaStart)*radius,
656                            center[0]+cos(alphaM)*radius,center[1]+sin(alphaM)*radius,
657                            center[0]+cos(alphaEnd)*radius,center[1]+sin(alphaEnd)*radius);
658 }
659
660 double QuadraticPlanarInterpTest::btw2NodesAndACenter(const Node& n1, const Node& n2, const double *center)
661 {
662   const double *n1Pt=n1;
663   const double *n2Pt=n2;
664   double tmp1[2],tmp2[2];
665   tmp1[0]=n1Pt[0]-center[0]; tmp1[1]=n1Pt[1]-center[1];
666   tmp2[0]=n2Pt[0]-center[0]; tmp2[1]=n2Pt[1]-center[1];
667   double distTmp1=sqrt(tmp1[0]*tmp1[0]+tmp1[1]*tmp1[1]);
668   double distTmp2=sqrt(tmp2[0]*tmp2[0]+tmp2[1]*tmp2[1]);
669   double ret=acos((tmp1[0]*tmp2[0]+tmp1[1]*tmp2[1])/(distTmp1*distTmp2));
670   if(tmp1[0]*tmp2[1]-tmp1[1]*tmp2[0]<0)
671     ret=-ret;
672   return ret;
673 }
674
675 }