1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "QuadraticPlanarInterpTest.hxx"
22 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
23 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
24 #include "InterpKernelGeo2DEdgeLin.hxx"
30 using namespace INTERP_KERNEL;
35 static const double ADMISSIBLE_ERROR = 1.e-14;
37 void QuadraticPlanarInterpTest::IntersectArcCircleBase()
39 double center[2]={0.5,0.5};
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);
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);
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);//<<
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);
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);
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);
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);
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);
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);
104 // ArcCArcCIntersector
106 TypeOfLocInEdge where1,where2;
107 std::vector<Node *> v4;
110 ArcCArcCIntersector *intersector=0;
111 for(unsigned k=0;k<8;k++)
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();
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();
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();
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();
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();
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();
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++)
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);
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++)
173 v4.clear(); v3.clear();
174 delete intersector; e2->decrRef(); e1->decrRef();
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++)
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);
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++)
198 v4.clear(); v3.clear();
199 delete intersector; e2->decrRef(); e1->decrRef();
201 // 2 intersections R1>R2 ; dist(circle1,circle2)<R1; Same order.
202 for(unsigned k=0;k<8;k++)
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);
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++)
223 v4.clear(); v3.clear();
224 delete intersector; e2->decrRef(); e1->decrRef();
226 // 2 intersections R1>R2 ; dist(circle1,circle2)<R1; Opp order.
227 for(unsigned k=0;k<8;k++)
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);
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++)
248 v4.clear(); v3.clear();
249 delete intersector; e2->decrRef(); e1->decrRef();
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++)
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);
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++)
273 v4.clear(); v3.clear();
274 delete intersector; e2->decrRef(); e1->decrRef();
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++)
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);
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++)
298 v4.clear(); v3.clear();
299 delete intersector; e2->decrRef(); e1->decrRef();
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++)
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);
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++)
323 v4.clear(); v3.clear();
324 delete intersector; e2->decrRef(); e1->decrRef();
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++)
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);
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++)
348 v4.clear(); v3.clear();
349 delete intersector; e2->decrRef(); e1->decrRef();
351 // Tangent intersection
352 QuadraticPlanarPrecision::setPrecision(1e-5);
353 for(unsigned k=0;k<8;k++)
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);
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++)
370 v4.clear(); v4.clear();
371 delete intersector; e2->decrRef(); e1->decrRef();
373 QuadraticPlanarPrecision::setPrecision(1e-14);
375 for(unsigned k=0;k<8;k++)
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);
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();
391 for(unsigned k=0;k<8;k++)
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);
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();
408 for(unsigned k=0;k<8;k++)
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);
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]);
423 v4.clear(); v3.clear();
424 delete intersector; e2->decrRef(); e1->decrRef();
427 for(unsigned k=0;k<8;k++)
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);
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();
445 for(unsigned k=0;k<8;k++)
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);
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]);
465 v4.clear(); v3.clear();
466 delete intersector; e2->decrRef(); e1->decrRef();
469 for(unsigned k=0;k<8;k++)
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);
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();
494 void QuadraticPlanarInterpTest::IntersectArcCircleFull()
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);
516 e1=buildArcOfCircle(center1,radius1,-2*M_PI/3.,-7.*M_PI/3.);
517 e2=buildArcOfCircle(center2,radius2,0.,M_PI/2.);
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);
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.);
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);
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.);
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);
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.);
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);
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();
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();
604 void QuadraticPlanarInterpTest::IntersectArcCircleSegumentBase()
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);
611 bool obvious,areOverlapped;
612 intersector->areOverlappedOrOnlyColinears(0,obvious,areOverlapped);
613 CPPUNIT_ASSERT(!obvious && !areOverlapped);
614 std::vector<Node *> v4;
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;
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;
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;
644 QuadraticPolygon *QuadraticPlanarInterpTest::buildQuadraticPolygonCoarseInfo(const double *coords, const int *conn, int lgth)
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);
652 EdgeArcCircle *QuadraticPlanarInterpTest::buildArcOfCircle(const double *center, double radius, double alphaStart, double alphaEnd)
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);
660 double QuadraticPlanarInterpTest::btw2NodesAndACenter(const Node& n1, const Node& n2, const double *center)
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)