Back to index

salome-med  6.5.0
QuadraticPlanarInterpTest2.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "QuadraticPlanarInterpTest.hxx"
00021 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
00022 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
00023 #include "InterpKernelGeo2DEdgeLin.hxx"
00024 
00025 #include <cmath>
00026 #include <sstream>
00027 #include <iostream>
00028 
00029 using namespace INTERP_KERNEL;
00030 
00031 namespace INTERP_TEST
00032 {
00033 
00034 static const double ADMISSIBLE_ERROR = 1.e-14;
00035 
00036 void QuadraticPlanarInterpTest::IntersectArcCircleBase()
00037 {
00038   double center[2]={0.5,0.5};
00039   double radius=0.3;
00040   EdgeArcCircle *e1=buildArcOfCircle(center,radius,M_PI/4.,M_PI/3.);
00041   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI/3),ADMISSIBLE_ERROR);
00042   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(M_PI/4),ADMISSIBLE_ERROR);
00043   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(M_PI/4),ADMISSIBLE_ERROR);
00044   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/3),ADMISSIBLE_ERROR);
00045   e1->decrRef();
00046   //
00047   e1=buildArcOfCircle(center,radius,M_PI/3.,M_PI/2.);
00048   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI/2),ADMISSIBLE_ERROR);
00049   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(M_PI/3),ADMISSIBLE_ERROR);
00050   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(M_PI/3),ADMISSIBLE_ERROR);
00051   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/2),ADMISSIBLE_ERROR);
00052   e1->decrRef();
00053   //
00054   e1=buildArcOfCircle(center,radius,M_PI/3.,3.*M_PI/4.);
00055   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(3*M_PI/4),ADMISSIBLE_ERROR);
00056   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(M_PI/3),ADMISSIBLE_ERROR);
00057   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(3*M_PI/4),ADMISSIBLE_ERROR);
00058   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/2),ADMISSIBLE_ERROR);//<<
00059   e1->decrRef();
00060   //
00061   e1=buildArcOfCircle(center,radius,3*M_PI/4,7*M_PI/8);
00062   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(7*M_PI/8),ADMISSIBLE_ERROR);
00063   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(3*M_PI/4),ADMISSIBLE_ERROR);
00064   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(7*M_PI/8),ADMISSIBLE_ERROR);
00065   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(3*M_PI/4),ADMISSIBLE_ERROR);
00066   e1->decrRef();
00067   //
00068   e1=buildArcOfCircle(center,radius,7.*M_PI/8.,9.*M_PI/8.);
00069   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI),ADMISSIBLE_ERROR);//<<
00070   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(7*M_PI/8),ADMISSIBLE_ERROR);
00071   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(9*M_PI/8),ADMISSIBLE_ERROR);
00072   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(7*M_PI/8),ADMISSIBLE_ERROR);
00073   e1->decrRef();
00074   //
00075   e1=buildArcOfCircle(center,radius,9.*M_PI/8.,11.*M_PI/8.);
00076   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(9*M_PI/8),ADMISSIBLE_ERROR);
00077   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(11*M_PI/8),ADMISSIBLE_ERROR);
00078   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(11*M_PI/8),ADMISSIBLE_ERROR);
00079   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(9*M_PI/8),ADMISSIBLE_ERROR);
00080   e1->decrRef();
00081   //
00082   e1=buildArcOfCircle(center,radius,11.*M_PI/8.,7.*M_PI/4.);
00083   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(11*M_PI/8),ADMISSIBLE_ERROR);
00084   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(7*M_PI/4),ADMISSIBLE_ERROR);
00085   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(3*M_PI/2),ADMISSIBLE_ERROR);//<<
00086   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(7*M_PI/4),ADMISSIBLE_ERROR);
00087   e1->decrRef();
00088   //
00089   e1=buildArcOfCircle(center,radius,7.*M_PI/4.,15.*M_PI/8.);
00090   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(7*M_PI/4),ADMISSIBLE_ERROR);
00091   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(15*M_PI/8),ADMISSIBLE_ERROR);
00092   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(7*M_PI/4),ADMISSIBLE_ERROR);
00093   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(15*M_PI/8),ADMISSIBLE_ERROR);
00094   e1->decrRef();
00095   //
00096   e1=buildArcOfCircle(center,radius,-M_PI/8.,M_PI/4.);
00097   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[0],center[0]+radius*cos(M_PI/4),ADMISSIBLE_ERROR);
00098   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[1],center[0]+radius*cos(0.),ADMISSIBLE_ERROR);      //<<
00099   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[2],center[1]+radius*sin(15*M_PI/8),ADMISSIBLE_ERROR);
00100   CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getBounds()[3],center[1]+radius*sin(M_PI/4),ADMISSIBLE_ERROR);
00101   e1->decrRef();
00102   //
00103   // ArcCArcCIntersector
00104   //
00105   TypeOfLocInEdge where1,where2;
00106   std::vector<Node *> v4;
00107   MergePoints v3;
00108   EdgeArcCircle *e2;
00109   ArcCArcCIntersector *intersector=0;
00110   for(unsigned k=0;k<8;k++)
00111     {
00112       e1=buildArcOfCircle(center,radius,M_PI/4.+k*M_PI/4.,M_PI/3.+k*M_PI/4.);
00113       e2=buildArcOfCircle(center,radius,M_PI/4.+k*M_PI/4.,M_PI/3.+k*M_PI/4.);
00114       intersector=new ArcCArcCIntersector(*e1,*e2);
00115       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
00116       CPPUNIT_ASSERT(where1==START && where2==END);
00117       delete intersector; v3.clear(); e2->decrRef();
00118       //
00119       e2=buildArcOfCircle(center,radius,7*M_PI/24.+k*M_PI/4.,M_PI/3.+k*M_PI/4.);
00120       intersector=new ArcCArcCIntersector(*e1,*e2);
00121       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
00122       CPPUNIT_ASSERT(where1==INSIDE && where2==END);
00123       delete intersector; v3.clear(); e2->decrRef();
00124       //
00125       e2=buildArcOfCircle(center,radius,M_PI/4.+k*M_PI/4.,7*M_PI/24.+k*M_PI/4.);
00126       intersector=new ArcCArcCIntersector(*e1,*e2);
00127       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
00128       CPPUNIT_ASSERT(where1==START && where2==INSIDE);
00129       delete intersector; v3.clear(); e2->decrRef();
00130       //
00131       e2=buildArcOfCircle(center,radius,13.*M_PI/48.+k*M_PI/4.,15*M_PI/48.+k*M_PI/4.);
00132       intersector=new ArcCArcCIntersector(*e1,*e2);
00133       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
00134       CPPUNIT_ASSERT(where1==INSIDE && where2==INSIDE);
00135       delete intersector; v3.clear(); e2->decrRef();
00136       //
00137       e2=buildArcOfCircle(center,radius,-M_PI/4.+k*M_PI/4.,M_PI/6.+k*M_PI/4.);
00138       intersector=new ArcCArcCIntersector(*e1,*e2);
00139       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
00140       CPPUNIT_ASSERT(where1==OUT_BEFORE && where2==OUT_BEFORE);
00141       delete intersector; v3.clear(); e2->decrRef();
00142       //
00143       e2=buildArcOfCircle(center,radius,0+k*M_PI/4.,5*M_PI/6.+k*M_PI/4.);
00144       intersector=new ArcCArcCIntersector(*e1,*e2);
00145       intersector->getPlacements(e2->getStartNode(),e2->getEndNode(),where1,where2,v3);
00146       CPPUNIT_ASSERT(where1==OUT_BEFORE && where2==OUT_AFTER);
00147       delete intersector; v3.clear(); e2->decrRef();
00148       e1->decrRef();
00149     }
00150   // Ok now let's see intersection only. 2 intersections R1 > R2 ; dist(circle1,circle2)>R1; Opposite order.
00151   for(unsigned k=0;k<8;k++)
00152     {
00153       center[0]=0.; center[1]=0.;
00154       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00155       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
00156       e2=buildArcOfCircle(center2,1.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
00157       intersector=new ArcCArcCIntersector(*e1,*e2);
00158       bool order;
00159       bool obvious,areOverlapped;
00160       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00161       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00162       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
00163       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00164       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00165       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00166       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00167       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00168       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00169       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.35587863972199624,1e-10);
00170       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00171         (*iter)->decrRef();
00172       v4.clear(); v3.clear();
00173       delete intersector; e2->decrRef(); e1->decrRef();
00174     }
00175   // Ok now let's see intersection only. 2 intersections R1 > R2 ; dist(circle1,circle2)>R1; Same order.
00176   for(unsigned k=0;k<7;k++)
00177     {
00178       center[0]=0.; center[1]=0.;
00179       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00180       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
00181       e2=buildArcOfCircle(center2,1.,M_PI+(k+1)*M_PI/4.,M_PI+(k-1)*M_PI/4.);
00182       intersector=new ArcCArcCIntersector(*e1,*e2);
00183       bool order;
00184       bool obvious,areOverlapped;
00185       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00186       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00187       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
00188       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00189       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00190       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00191       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00192       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00193       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00194       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.35587863972199624,1e-10);
00195       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00196         (*iter)->decrRef();
00197       v4.clear(); v3.clear();
00198       delete intersector; e2->decrRef(); e1->decrRef();
00199     }
00200   // 2 intersections R1>R2 ; dist(circle1,circle2)<R1; Same order.
00201   for(unsigned k=0;k<8;k++)
00202     {
00203       center[0]=0.; center[1]=0.;
00204       double center2[2]; center2[0]=2.8*cos(k*M_PI/4.); center2[1]=2.8*sin(k*M_PI/4.);
00205       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
00206       e2=buildArcOfCircle(center2,1.,(k)*M_PI/4.-M_PI/2.,(k)*M_PI/4.+M_PI/2.);
00207       intersector=new ArcCArcCIntersector(*e1,*e2);
00208       bool order;
00209       bool obvious,areOverlapped;
00210       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00211       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00212       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
00213       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00214       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00215       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00216       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00217       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00218       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00219       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.6793851523346941,1e-10);
00220       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00221         (*iter)->decrRef();
00222       v4.clear(); v3.clear();
00223       delete intersector; e2->decrRef(); e1->decrRef();
00224     }
00225   // 2 intersections R1>R2 ; dist(circle1,circle2)<R1; Opp order.
00226   for(unsigned k=0;k<8;k++)
00227     {
00228       center[0]=0.; center[1]=0.;
00229       double center2[2]; center2[0]=2.8*cos(k*M_PI/4.); center2[1]=2.8*sin(k*M_PI/4.);
00230       e1=buildArcOfCircle(center,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
00231       e2=buildArcOfCircle(center2,1.,(k)*M_PI/4.+M_PI/2.,(k)*M_PI/4.-M_PI/2.);
00232       intersector=new ArcCArcCIntersector(*e1,*e2);
00233       bool order;
00234       bool obvious,areOverlapped;
00235       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00236       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00237       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
00238       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00239       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00240       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00241       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00242       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00243       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00244       CPPUNIT_ASSERT_DOUBLES_EQUAL(btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),0.6793851523346941,1e-10);
00245       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00246         (*iter)->decrRef();
00247       v4.clear(); v3.clear();
00248       delete intersector; e2->decrRef(); e1->decrRef();
00249     }
00250   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)>R2; Opposite order.
00251   for(unsigned k=0;k<1;k++)
00252     {
00253       double center2[2]; center[0]=0.; center[1]=0.;
00254       center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00255       e1=buildArcOfCircle(center,1.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
00256       e2=buildArcOfCircle(center2,3.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
00257       intersector=new ArcCArcCIntersector(*e1,*e2);
00258       bool order;
00259       bool obvious,areOverlapped;
00260       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00261       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00262       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
00263       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00264       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00265       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00266       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00267       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00268       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00269       CPPUNIT_ASSERT_DOUBLES_EQUAL(1.1195732971845034,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
00270       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00271         (*iter)->decrRef();
00272       v4.clear(); v3.clear();
00273       delete intersector; e2->decrRef(); e1->decrRef();
00274     }
00275   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)>R2; same order.
00276   for(unsigned k=0;k<8;k++)
00277     {
00278       double center2[2]; center[0]=0.; center[1]=0.;
00279       center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00280       e1=buildArcOfCircle(center,1.,(k+1)*M_PI/4.,(k-1)*M_PI/4.);
00281       e2=buildArcOfCircle(center2,3.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
00282       intersector=new ArcCArcCIntersector(*e1,*e2);
00283       bool order;
00284       bool obvious,areOverlapped;
00285       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00286       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00287       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
00288       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00289       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00290       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00291       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00292       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00293       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00294       CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.1195732971845034,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
00295       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00296         (*iter)->decrRef();
00297       v4.clear(); v3.clear();
00298       delete intersector; e2->decrRef(); e1->decrRef();
00299     }
00300   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)<R2; same order.
00301   for(unsigned k=0;k<8;k++)
00302     {
00303       double center2[2]; center[0]=0.; center[1]=0.;
00304       center2[0]=-2.8*cos(k*M_PI/4.); center2[1]=-2.8*sin(k*M_PI/4.);
00305       e1=buildArcOfCircle(center,1.,(k)*M_PI/4.+M_PI/2.,(k)*M_PI/4.-M_PI/2.);
00306       e2=buildArcOfCircle(center2,3.,(k+1)*M_PI/4.,(k-1)*M_PI/4.);
00307       intersector=new ArcCArcCIntersector(*e1,*e2);
00308       bool order;
00309       bool obvious,areOverlapped;
00310       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00311       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00312       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(order);
00313       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00314       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00315       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00316       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00317       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00318       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00319       CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0844420190512074,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
00320       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00321         (*iter)->decrRef();
00322       v4.clear(); v3.clear();
00323       delete intersector; e2->decrRef(); e1->decrRef();
00324     }
00325   // Ok now let's see intersection only. 2 intersections R1 < R2 ; dist(circle1,circle2)<R2; opp. order.
00326   for(unsigned k=0;k<8;k++)
00327     {
00328       double center2[2]; center[0]=0.; center[1]=0.;
00329       center2[0]=-2.8*cos(k*M_PI/4.); center2[1]=-2.8*sin(k*M_PI/4.);
00330       e1=buildArcOfCircle(center,1.,(k)*M_PI/4.+M_PI/2.,(k)*M_PI/4.-M_PI/2.);
00331       e2=buildArcOfCircle(center2,3.,(k-1)*M_PI/4.,(k+1)*M_PI/4.);
00332       intersector=new ArcCArcCIntersector(*e1,*e2);
00333       bool order;
00334       bool obvious,areOverlapped;
00335       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00336       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00337       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT(!order);
00338       CPPUNIT_ASSERT_EQUAL(2,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00339       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00340       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00341       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00342       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[1]))),ADMISSIBLE_ERROR);
00343       CPPUNIT_ASSERT(!v4[0]->isEqual(*v4[1]));
00344       CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0844420190512074,btw2NodesAndACenter(*v4[0],*v4[1],e1->getCenter()),1e-10);
00345       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00346         (*iter)->decrRef();
00347       v4.clear(); v3.clear();
00348       delete intersector; e2->decrRef(); e1->decrRef();
00349     }
00350   // Tangent intersection
00351   QUADRATIC_PLANAR::setPrecision(1e-5);
00352   for(unsigned k=0;k<8;k++)
00353     {
00354       double center2[2]; center[0]=0.; center[1]=0.;
00355       center2[0]=4.*cos(k*M_PI/4.); center2[1]=4.*sin(k*M_PI/4.);
00356       e1=buildArcOfCircle(center,1.,(k+1)*M_PI/4.,(k-1)*M_PI/4.);
00357       e2=buildArcOfCircle(center2,3.,M_PI+(k-1)*M_PI/4.,M_PI+(k+1)*M_PI/4.);
00358       intersector=new ArcCArcCIntersector(*e1,*e2);
00359       bool order;
00360       bool obvious,areOverlapped;
00361       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00362       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00363       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.
00364       CPPUNIT_ASSERT_EQUAL(1,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(0,(int)v3.getNumberOfAssociations());
00365       CPPUNIT_ASSERT_DOUBLES_EQUAL(e1->getRadius(),Node::distanceBtw2Pt(e1->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00366       CPPUNIT_ASSERT_DOUBLES_EQUAL(e2->getRadius(),Node::distanceBtw2Pt(e2->getCenter(),(*(v4[0]))),ADMISSIBLE_ERROR);
00367       for(std::vector<Node *>::iterator iter=v4.begin();iter!=v4.end();iter++)
00368         (*iter)->decrRef();
00369       v4.clear(); v4.clear();
00370       delete intersector; e2->decrRef(); e1->decrRef();
00371     }
00372   QUADRATIC_PLANAR::setPrecision(1e-14);
00373   // Extremities # 1
00374   for(unsigned k=0;k<8;k++)
00375     {
00376       center[0]=0.; center[1]=0.;
00377       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00378       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
00379       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.-0.55978664859225125,M_PI+k*M_PI/4.+0.55978664859225125);
00380       intersector=new ArcCArcCIntersector(*e1,*e2);
00381       bool order;
00382       bool obvious,areOverlapped;
00383       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00384       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00385       CPPUNIT_ASSERT(!intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT_EQUAL(0,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(2,(int)v3.getNumberOfAssociations());
00386       CPPUNIT_ASSERT(e1->getStartNode()==e2->getEndNode()); CPPUNIT_ASSERT(e2->getStartNode()==e1->getEndNode());
00387       v4.clear(); v3.clear();
00388       delete intersector; e2->decrRef(); e1->decrRef();
00389     }
00390   for(unsigned k=0;k<8;k++)
00391     {
00392       center[0]=0.; center[1]=0.;
00393       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00394       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
00395       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.55978664859225125,M_PI+k*M_PI/4.-0.55978664859225125);
00396       intersector=new ArcCArcCIntersector(*e1,*e2);
00397       bool order;
00398       bool obvious,areOverlapped;
00399       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00400       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00401       CPPUNIT_ASSERT(!intersector->intersect(0,v4,order,v3)); CPPUNIT_ASSERT_EQUAL(0,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(2,(int)v3.getNumberOfAssociations());
00402       CPPUNIT_ASSERT(e1->getStartNode()==e2->getStartNode()); CPPUNIT_ASSERT(e2->getEndNode()==e1->getEndNode());
00403       v4.clear(); v3.clear();
00404       delete intersector; e2->decrRef(); e1->decrRef();
00405     }
00406   // Extremities # 2
00407   for(unsigned k=0;k<8;k++)
00408     {
00409       center[0]=0.; center[1]=0.;
00410       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00411       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
00412       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.55978664859225125,M_PI+k*M_PI/4.-0.7);
00413       intersector=new ArcCArcCIntersector(*e1,*e2);
00414       bool order;
00415       bool obvious,areOverlapped;
00416       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00417       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00418       CPPUNIT_ASSERT(intersector->intersect(0,v4,order,v3));
00419       CPPUNIT_ASSERT(order); CPPUNIT_ASSERT_EQUAL(1,(int)v4.size()); CPPUNIT_ASSERT_EQUAL(1,(int)v3.getNumberOfAssociations());
00420       CPPUNIT_ASSERT(e1->getStartNode()==e2->getStartNode()); CPPUNIT_ASSERT(e1->getEndNode()==v4[0]);
00421       v4[0]->decrRef();
00422       v4.clear(); v3.clear();
00423       delete intersector; e2->decrRef(); e1->decrRef();
00424     }
00425   // Extremities # 3
00426   for(unsigned k=0;k<8;k++)
00427     {
00428       center[0]=0.; center[1]=0.;
00429       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00430       e1=buildArcOfCircle(center,3.,k*M_PI/4.-0.17793931986099812,k*M_PI/4.+0.17793931986099812);
00431       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.7,M_PI+k*M_PI/4.-0.7);
00432       intersector=new ArcCArcCIntersector(*e1,*e2);
00433       bool order;
00434       bool obvious,areOverlapped;
00435       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00436       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00437       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());
00438       CPPUNIT_ASSERT(e1->getStartNode()==v4[0]); CPPUNIT_ASSERT(e1->getEndNode()==v4[1]);
00439       v4[0]->decrRef(); v4[1]->decrRef();
00440       v4.clear(); v3.clear();
00441       delete intersector; e2->decrRef(); e1->decrRef();
00442     }
00443   // Extremities # 4
00444   for(unsigned k=0;k<8;k++)
00445     {
00446       center[0]=0.; center[1]=0.;
00447       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00448       Node *nodeS=new Node(center[0]+3.*cos(k*M_PI/4.-0.17793931986099812),center[1]+3.*sin(k*M_PI/4.-0.17793931986099812));
00449       Node *nodeE=new Node(center[0]+3.*cos(k*M_PI/4.),center[1]+3.*sin(k*M_PI/4.));
00450       double angle=k*M_PI/4.-0.17793931986099812;
00451       angle=angle>M_PI?angle-2.*M_PI:angle;
00452       e1=new EdgeArcCircle(nodeS,nodeE,//Problem of precision 1e-14 to easily reached.
00453                            center,3.,angle,0.17793931986099812);
00454       nodeS->decrRef(); nodeE->decrRef();
00455       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.7,M_PI+k*M_PI/4.-0.7);
00456       intersector=new ArcCArcCIntersector(*e1,*e2);
00457       bool order;
00458       bool obvious,areOverlapped;
00459       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00460       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00461       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());
00462       CPPUNIT_ASSERT(e1->getStartNode()==v4[0]);
00463       v4[0]->decrRef();
00464       v4.clear(); v3.clear();
00465       delete intersector; e2->decrRef(); e1->decrRef();
00466     }
00467   //Extremities # 5
00468   for(unsigned k=0;k<8;k++)
00469     {
00470       center[0]=0.; center[1]=0.;
00471       double center2[2]; center2[0]=3.8*cos(k*M_PI/4.); center2[1]=3.8*sin(k*M_PI/4.);
00472       Node *nodeS=new Node(center[0]+3.*cos(k*M_PI/4.-0.17793931986099812),center[1]+3.*sin(k*M_PI/4.-0.17793931986099812));
00473       Node *nodeE=new Node(center[0]+3.*cos(k*M_PI/4.)+0.5,center[1]+3.*sin(k*M_PI/4.));
00474       double angle=k*M_PI/4.-0.17793931986099812;
00475       angle=angle>M_PI?angle-2.*M_PI:angle;
00476       e1=new EdgeArcCircle(nodeS,nodeE,//Problem of precision 1e-14 to easily reached.
00477                            center,3.,angle,0.67793931986099812);
00478       nodeS->decrRef(); nodeE->decrRef();
00479       e2=buildArcOfCircle(center2,1.,M_PI+k*M_PI/4.+0.7,M_PI+k*M_PI/4.-0.7);
00480       intersector=new ArcCArcCIntersector(*e1,*e2);
00481       bool order;
00482       bool obvious,areOverlapped;
00483       intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00484       CPPUNIT_ASSERT(!obvious && !areOverlapped);
00485       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());
00486       CPPUNIT_ASSERT(e1->getStartNode()==v4[0]);
00487       v4[0]->decrRef(); v4[1]->decrRef();
00488       v4.clear(); v3.clear();
00489       delete intersector; e2->decrRef(); e1->decrRef();
00490     }
00491 }
00492 
00493 void QuadraticPlanarInterpTest::IntersectArcCircleFull()
00494 {
00495   double center1[2]; center1[0]=0.;   center1[1]=0.;   double radius1=3.;
00496   double center2[2]; center2[0]=0.75; center2[1]=-2.6; double radius2=1.;
00497   EdgeArcCircle *e1=buildArcOfCircle(center1,radius1,-M_PI/3.,4.*M_PI/3.);
00498   EdgeArcCircle *e2=buildArcOfCircle(center2,radius2,0.,M_PI/2.);
00499   MergePoints commonNode;
00500   QuadraticPolygon pol1; QuadraticPolygon pol2;
00501   QuadraticPolygon pol3; QuadraticPolygon pol4;
00502   pol3.pushBack(e1); pol4.pushBack(e2);
00503   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol3.getPerimeter(),1e-6);
00504   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol4.getPerimeter(),1e-6);
00505   CPPUNIT_ASSERT_DOUBLES_EQUAL(19.6648305849,pol3.getArea(),1e-6);
00506   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol4.getArea(),1e-6);
00507   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol1,pol2));
00508   CPPUNIT_ASSERT_EQUAL(2,pol1.size());
00509   CPPUNIT_ASSERT_EQUAL(2,pol2.size());
00510   CPPUNIT_ASSERT_DOUBLES_EQUAL(19.6648305849,pol1.getArea(),1e-6);
00511   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol2.getArea(),1e-6);
00512   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol1.getPerimeter(),1e-6);
00513   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol2.getPerimeter(),1e-6);
00514   //
00515   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
00516   e2=buildArcOfCircle(center2,radius2,0.,M_PI/2.);
00517   commonNode.clear();
00518   QuadraticPolygon pol5; QuadraticPolygon pol6;
00519   QuadraticPolygon pol7; QuadraticPolygon pol8;
00520   pol7.pushBack(e1); pol8.pushBack(e2);
00521   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol7.getPerimeter(),1e-6);
00522   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol8.getPerimeter(),1e-6);
00523   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol7.getArea(),1e-6);
00524   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol8.getArea(),1e-6);
00525   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol5,pol6));
00526   CPPUNIT_ASSERT_EQUAL(2,pol5.size());
00527   CPPUNIT_ASSERT_EQUAL(2,pol6.size());
00528   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol5.getArea(),1e-6);
00529   CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8146018366,pol6.getArea(),1e-6);
00530   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol5.getPerimeter(),1e-6);
00531   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol6.getPerimeter(),1e-6);
00532   //
00533   center2[0]=3.5; center2[1]=0.;
00534   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
00535   e2=buildArcOfCircle(center2,radius2,M_PI/2.,3*M_PI/2.);
00536   commonNode.clear();
00537   QuadraticPolygon pol9; QuadraticPolygon pol10;
00538   QuadraticPolygon pol11; QuadraticPolygon pol12;
00539   pol11.pushBack(e1); pol12.pushBack(e2);
00540   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol11.getPerimeter(),1e-6);
00541   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol12.getPerimeter(),1e-6);
00542   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol11.getArea(),1e-6);
00543   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol12.getArea(),1e-6);
00544   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol9,pol10));
00545   CPPUNIT_ASSERT_EQUAL(3,pol9.size());
00546   CPPUNIT_ASSERT_EQUAL(3,pol10.size());
00547   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol9.getPerimeter(),1e-6);
00548   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol10.getPerimeter(),1e-6);
00549   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol9.getArea(),1e-6);
00550   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5707963267949,pol10.getArea(),1e-6);
00551   //
00552   center2[0]=0.; center2[1]=0.; radius2=radius1;
00553   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
00554   e2=buildArcOfCircle(center2,radius2,M_PI/3.,2*M_PI/3.);
00555   commonNode.clear();
00556   QuadraticPolygon pol13; QuadraticPolygon pol14;
00557   QuadraticPolygon pol15; QuadraticPolygon pol16;
00558   pol15.pushBack(e1); pol16.pushBack(e2);
00559   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol15.getPerimeter(),1e-6);
00560   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol16.getPerimeter(),1e-6);
00561   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol15.getArea(),1e-6);
00562   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.6095032974147,pol16.getArea(),1e-6);
00563   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol13,pol14));
00564   CPPUNIT_ASSERT_EQUAL(3,pol13.size());
00565   CPPUNIT_ASSERT_EQUAL(1,pol14.size());
00566   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol13.getPerimeter(),1e-6);
00567   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol13.getArea(),1e-6);
00568   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol14.getPerimeter(),1e-6);
00569   CPPUNIT_ASSERT_DOUBLES_EQUAL(8.6095032974147,pol14.getArea(),1e-6);
00570   //
00571   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
00572   e2=buildArcOfCircle(center2,radius2,2*M_PI/3.,M_PI/3.);
00573   commonNode.clear();
00574   QuadraticPolygon pol17; QuadraticPolygon pol18;
00575   QuadraticPolygon pol19; QuadraticPolygon pol20;
00576   pol19.pushBack(e1); pol20.pushBack(e2);
00577   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol19.getPerimeter(),1e-6);
00578   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol20.getPerimeter(),1e-6);
00579   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol19.getArea(),1e-6);
00580   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.6095032974147,pol20.getArea(),1e-6);
00581   CPPUNIT_ASSERT(e1->intersectWith(e2,commonNode,pol17,pol18));
00582   CPPUNIT_ASSERT_EQUAL(3,pol17.size());
00583   CPPUNIT_ASSERT_EQUAL(1,pol18.size());
00584   CPPUNIT_ASSERT_DOUBLES_EQUAL(15.707963267948966,pol17.getPerimeter(),1e-6);
00585   CPPUNIT_ASSERT_DOUBLES_EQUAL(-19.6648305849,pol17.getArea(),1e-6);
00586   CPPUNIT_ASSERT_DOUBLES_EQUAL(3.1415926535897931,pol18.getPerimeter(),1e-6);
00587   CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.6095032974147,pol18.getArea(),1e-6);
00588   //no intersection #1
00589   center2[0]=4.277; center2[1]=-4.277;
00590   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
00591   e2=buildArcOfCircle(center2,radius2,M_PI/4.,5*M_PI/4.);
00592   QuadraticPolygon polTemp1; QuadraticPolygon polTemp2;
00593   CPPUNIT_ASSERT(!e1->intersectWith(e2,commonNode,polTemp1,polTemp2));
00594   e1->decrRef(); e2->decrRef();
00595   //no intersection #2
00596   center2[0]=1.; center2[1]=-1.; radius2=0.2;
00597   e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
00598   e2=buildArcOfCircle(center2,radius2,M_PI/4.,5*M_PI/4.);
00599   CPPUNIT_ASSERT(!e1->intersectWith(e2,commonNode,polTemp1,polTemp2));
00600   e1->decrRef(); e2->decrRef();
00601 }
00602 
00603 void QuadraticPlanarInterpTest::IntersectArcCircleSegumentBase()
00604 {
00605   double center[2]={2.,2.};
00606   EdgeArcCircle *e1=buildArcOfCircle(center,2.3,M_PI/4.,5.*M_PI/4.);
00607   EdgeLin *e2=new EdgeLin(-1.3,1.,3.,5.3);
00608   EdgeIntersector *intersector=new ArcCSegIntersector(*e1,*e2);
00609   bool order;
00610   bool obvious,areOverlapped;
00611   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
00612   CPPUNIT_ASSERT(!obvious && !areOverlapped);
00613   std::vector<Node *> v4;
00614   MergePoints v3;
00615   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());
00616   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[0])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3,(*v4[0])[1],1e-10);
00617   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.3,(*v4[1])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[1])[1],1e-10);
00618   v4[0]->decrRef(); v4[1]->decrRef(); e2->decrRef(); v3.clear(); v4.clear(); delete intersector;
00619   //
00620   e2=new EdgeLin(3.,5.3,-1.3,1.);
00621   intersector=new ArcCSegIntersector(*e1,*e2);
00622   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped); CPPUNIT_ASSERT(!obvious && !areOverlapped);
00623   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());
00624   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[0])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3,(*v4[0])[1],1e-10);
00625   CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.3,(*v4[1])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[1])[1],1e-10);
00626   v4[0]->decrRef(); v4[1]->decrRef(); e2->decrRef(); v3.clear(); v4.clear(); delete intersector;
00627   // tangent intersection
00628   e2=new EdgeLin(-1.,4.3,3.,4.3);
00629   intersector=new ArcCSegIntersector(*e1,*e2);
00630   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped); CPPUNIT_ASSERT(!obvious && !areOverlapped);
00631   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());
00632   CPPUNIT_ASSERT_DOUBLES_EQUAL(2.,(*v4[0])[0],1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3,(*v4[0])[1],1e-10);
00633   v4[0]->decrRef(); e2->decrRef(); v3.clear(); delete intersector;
00634   // no intersection
00635   e2=new EdgeLin(-2.,-2.,-1.,-3.);
00636   intersector=new ArcCSegIntersector(*e1,*e2);
00637   intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped); CPPUNIT_ASSERT(obvious && !areOverlapped);
00638   e2->decrRef(); v3.clear(); delete intersector;
00639   //
00640   e1->decrRef();
00641 }
00642 
00643 QuadraticPolygon *QuadraticPlanarInterpTest::buildQuadraticPolygonCoarseInfo(const double *coords, const int *conn, int lgth)
00644 {
00645   std::vector<INTERP_KERNEL::Node *> nodes;
00646   for(int i=0;i<lgth;i++)
00647     nodes.push_back(new INTERP_KERNEL::Node(coords[2*conn[i]],coords[2*conn[i]+1]));
00648   return INTERP_KERNEL::QuadraticPolygon::BuildArcCirclePolygon(nodes);
00649 }
00650 
00651 EdgeArcCircle *QuadraticPlanarInterpTest::buildArcOfCircle(const double *center, double radius, double alphaStart, double alphaEnd)
00652 {
00653   double alphaM=(alphaStart+alphaEnd)/2;
00654   return new EdgeArcCircle(center[0]+cos(alphaStart)*radius,center[1]+sin(alphaStart)*radius,
00655                            center[0]+cos(alphaM)*radius,center[1]+sin(alphaM)*radius,
00656                            center[0]+cos(alphaEnd)*radius,center[1]+sin(alphaEnd)*radius);
00657 }
00658 
00659 double QuadraticPlanarInterpTest::btw2NodesAndACenter(const Node& n1, const Node& n2, const double *center)
00660 {
00661   const double *n1Pt=n1;
00662   const double *n2Pt=n2;
00663   double tmp1[2],tmp2[2];
00664   tmp1[0]=n1Pt[0]-center[0]; tmp1[1]=n1Pt[1]-center[1];
00665   tmp2[0]=n2Pt[0]-center[0]; tmp2[1]=n2Pt[1]-center[1];
00666   double distTmp1=sqrt(tmp1[0]*tmp1[0]+tmp1[1]*tmp1[1]);
00667   double distTmp2=sqrt(tmp2[0]*tmp2[0]+tmp2[1]*tmp2[1]);
00668   double ret=acos((tmp1[0]*tmp2[0]+tmp1[1]*tmp2[1])/(distTmp1*distTmp2));
00669   if(tmp1[0]*tmp2[1]-tmp1[1]*tmp2[0]<0)
00670     ret=-ret;
00671   return ret;
00672 }
00673 
00674 }