b311480e |
1 | // Created on: 1992-04-27 |
2 | // Created by: Laurent BUCHARD |
3 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // Modified: OFV Thu Nov 6 17:03:52 2003 |
18 | |
42cf5bc1 |
19 | #include <ElCLib.hxx> |
20 | #include <gp.hxx> |
21 | #include <gp_Circ2d.hxx> |
22 | #include <gp_Elips2d.hxx> |
23 | #include <gp_Hypr2d.hxx> |
24 | #include <gp_Lin2d.hxx> |
25 | #include <gp_Parab2d.hxx> |
26 | #include <IntAna2d_AnaIntersection.hxx> |
27 | #include <IntAna2d_Conic.hxx> |
28 | #include <IntAna2d_IntPoint.hxx> |
7fd59977 |
29 | #include <IntCurve_IConicTool.hxx> |
42cf5bc1 |
30 | #include <IntCurve_IntConicConic.hxx> |
7fd59977 |
31 | #include <IntCurve_PConic.hxx> |
32 | #include <IntRes2d_Domain.hxx> |
7fd59977 |
33 | #include <Precision.hxx> |
34 | #include <Standard_ConstructionError.hxx> |
35 | |
7fd59977 |
36 | //======================================================================= |
37 | // Perform() for |
38 | // Line - Parabola |
7fd59977 |
39 | // Line - Hyperbola |
40 | // Circle - Parabola |
41 | // Circle - Elipse |
42 | // Circle - Hyperbola |
43 | // Parabola - Parabola |
44 | // Elipse - Parabola |
45 | // Parabola - Hyperbola |
46 | // Elipse - Elipse |
47 | // Elipse - Hyperbola |
48 | // Hyperbola - Hyperbola |
49 | //======================================================================= |
7fd59977 |
50 | static const Standard_Real PARAM_MAX_ON_PARABOLA = 100000000.0; |
51 | static const Standard_Real PARAM_MAX_ON_HYPERBOLA = 10000.0; |
52 | static const Standard_Real TOL_EXACT_INTER = 1.e-7; |
53 | |
54 | static inline Standard_Boolean BOUNDED_DOMAIN(const IntRes2d_Domain& domain) |
55 | { |
56 | return (domain.HasFirstPoint() && domain.HasLastPoint()); |
57 | } |
58 | |
59 | static Standard_Boolean SET_BOUNDED_DOMAIN(const IntRes2d_Domain domain, |
60 | Standard_Real& binf, |
61 | Standard_Real& tolinf, |
62 | gp_Pnt2d& Pntinf, |
63 | Standard_Real& bsup, |
64 | Standard_Real& tolsup, |
65 | gp_Pnt2d& Pntsup) |
66 | { |
67 | if(domain.HasFirstPoint()) { |
68 | if(binf<domain.FirstParameter()) { |
69 | Pntinf = domain.FirstPoint(); |
70 | binf = domain.FirstParameter(); |
71 | tolinf = domain.FirstTolerance(); |
72 | } |
73 | } |
74 | if(domain.HasLastPoint()) { |
75 | if(bsup>domain.FirstParameter()) { |
76 | Pntsup = domain.LastPoint(); |
77 | bsup = domain.LastParameter(); |
78 | tolsup = domain.LastTolerance(); |
79 | } |
80 | } |
81 | Standard_Boolean result = (bsup <= binf) ? Standard_False : Standard_True; |
82 | // if(bsup<=binf) return(Standard_False); |
83 | // return(Standard_True); |
84 | return result; |
85 | } |
86 | |
87 | void SetBinfBsupFromIntAna2d(const IntAna2d_AnaIntersection& theIntAna2d, |
88 | Standard_Real& binf, |
89 | gp_Pnt2d& pntinf, |
90 | Standard_Real& bsup,gp_Pnt2d& pntsup, |
91 | const gp_Hypr2d& H, |
92 | const Standard_Real maxtol, |
93 | const Standard_Real LIMITE); |
94 | |
95 | void SetBinfBsupFromIntAna2d(const IntAna2d_AnaIntersection &theIntAna2d, |
96 | Standard_Real& binf,gp_Pnt2d& pntinf, |
97 | Standard_Real& bsup,gp_Pnt2d& pntsup, |
98 | const gp_Parab2d& PR, |
99 | const Standard_Real maxtol, |
100 | const Standard_Real LIMITE); |
101 | |
102 | //======================================================================= |
103 | //function : Perform |
104 | //purpose : Line - Parabola |
105 | //======================================================================= |
106 | void IntCurve_IntConicConic::Perform(const gp_Lin2d& L, |
107 | const IntRes2d_Domain& DL, |
108 | const gp_Parab2d& P, |
109 | const IntRes2d_Domain& DP, |
110 | const Standard_Real TolConf, |
111 | const Standard_Real Tol) |
112 | { |
113 | |
114 | this->ResetFields(); |
115 | IntCurve_IConicTool ITool(L); |
116 | IntCurve_PConic PCurve(P); |
117 | |
118 | PCurve.SetAccuracy(20); |
119 | Inter.SetReversedParameters(ReversedParameters()); |
120 | |
121 | Standard_Real binf = Precision::Infinite(); |
122 | Standard_Real bsup = -Precision::Infinite(); |
123 | Standard_Real maxtol = (Tol > TolConf) ? Tol : TolConf; |
124 | if( maxtol< 1.e-7 ) maxtol = 1.e-7; |
125 | Standard_Boolean wasSet = Standard_False; |
126 | |
127 | gp_Pnt2d Pntinf,Pntsup; |
128 | IntAna2d_AnaIntersection theIntAna2d; |
129 | |
130 | maxtol*=100.0; |
131 | // if(maxtol<0.000001) maxtol = 0.000001; |
132 | |
133 | gp_Vec2d Offset(maxtol*L.Direction().Y(),maxtol*L.Direction().X()); |
134 | gp_Lin2d Lp(L.Translated(Offset)); |
135 | theIntAna2d.Perform(P,Lp); |
136 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P,maxtol,PARAM_MAX_ON_PARABOLA); |
137 | |
138 | Offset.Reverse(); |
139 | gp_Lin2d Lm(L.Translated(Offset)); |
140 | theIntAna2d.Perform(P,Lm); |
141 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P,maxtol,PARAM_MAX_ON_PARABOLA); |
142 | |
143 | if(binf<=bsup) { |
144 | if(!BOUNDED_DOMAIN(DP)) { |
145 | Standard_Real tolinf = 0.0; |
146 | Standard_Real tolsup = 0.0; |
147 | if(SET_BOUNDED_DOMAIN(DP,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
148 | IntRes2d_Domain DPModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
149 | Inter.Perform(ITool,DL,PCurve,DPModif,TolConf,Tol); |
150 | } |
151 | else { |
152 | done = Standard_True; return; |
153 | } |
154 | } |
155 | else { |
156 | Standard_Real ft=0.0,lt=0.0; |
157 | if(binf< DP.FirstParameter()) { |
158 | binf = DP.FirstParameter(); |
159 | Pntinf = DP.FirstPoint(); |
160 | ft = DP.FirstTolerance(); |
161 | if(bsup < DP.FirstParameter()) { |
162 | done=Standard_True; return; |
163 | } |
164 | } |
165 | if(bsup> DP.LastParameter()) { |
166 | bsup = DP.LastParameter(); |
167 | Pntsup = DP.LastPoint(); |
168 | lt = DP.LastTolerance(); |
169 | if(binf>DP.LastParameter()) { |
170 | done=Standard_True; return; |
171 | } |
172 | } |
173 | IntRes2d_Domain DPModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
174 | // Inter.Perform(ITool,DL,PCurve,DPModif,TolConf,Tol); |
175 | Inter.Perform(ITool,DL,PCurve,DPModif,TOL_EXACT_INTER,TOL_EXACT_INTER); |
176 | this->SetValues(Inter); |
177 | wasSet = Standard_True; |
178 | if( this->IsDone() && this->NbPoints() == 0 ) { |
179 | this->ResetFields(); |
180 | Inter.Perform(ITool,DL,PCurve,DPModif,TolConf,Tol); |
181 | wasSet = Standard_False; |
182 | } |
183 | } |
184 | if( !wasSet ) this->SetValues(Inter); |
185 | } |
186 | else { |
187 | done = Standard_True; |
188 | } |
189 | } |
190 | |
7fd59977 |
191 | |
192 | //======================================================================= |
193 | //function : Perform |
194 | //purpose : Line - Hyperbola |
195 | //======================================================================= |
196 | void IntCurve_IntConicConic::Perform(const gp_Lin2d& L, |
197 | const IntRes2d_Domain& DL, |
198 | const gp_Hypr2d& H, |
199 | const IntRes2d_Domain& DH, |
200 | const Standard_Real TolConf, |
201 | const Standard_Real Tol) |
202 | { |
203 | this->ResetFields(); |
204 | IntCurve_IConicTool ITool(L); |
205 | IntCurve_PConic PCurve(H); |
206 | PCurve.SetAccuracy(20); |
207 | |
208 | |
209 | Inter.SetReversedParameters(ReversedParameters()); |
210 | |
211 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
212 | gp_Pnt2d Pntinf,Pntsup; |
213 | if(Tol > TolConf) maxtol = Tol; else maxtol = TolConf; |
214 | maxtol*=100.0; |
215 | if(maxtol<0.000001) maxtol = 0.000001; |
216 | gp_Vec2d Offset(maxtol*H.XAxis().Direction().X(), |
217 | maxtol*H.XAxis().Direction().Y()); |
218 | gp_Hypr2d Hp(H.Translated(Offset)); |
219 | IntAna2d_AnaIntersection theIntAna2d; |
220 | theIntAna2d.Perform(Hp,L); |
221 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
222 | Offset.Reverse(); |
223 | gp_Hypr2d Hm(H.Translated(Offset)); |
224 | theIntAna2d.Perform(Hm,L); |
225 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
226 | if(binf<=bsup) { |
227 | if(!BOUNDED_DOMAIN(DH)) { |
228 | Standard_Real tolinf = 0.0; |
229 | Standard_Real tolsup = 0.0; |
230 | if(SET_BOUNDED_DOMAIN(DH,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
231 | IntRes2d_Domain DHModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
232 | Inter.Perform(ITool,DL,PCurve,DHModif,TolConf,Tol); |
233 | } |
234 | else { |
235 | done = Standard_True; return; |
236 | } |
237 | } |
238 | else { |
239 | Standard_Real ft=0.0,lt=0.0; |
240 | if(binf< DH.FirstParameter()) { |
241 | binf = DH.FirstParameter(); |
242 | Pntinf = DH.FirstPoint(); |
243 | ft = DH.FirstTolerance(); |
244 | if(bsup < DH.FirstParameter()) { |
245 | done=Standard_True; return; |
246 | } |
247 | } |
248 | if(bsup> DH.LastParameter()) { |
249 | bsup = DH.LastParameter(); |
250 | Pntsup = DH.LastPoint(); |
251 | lt = DH.LastTolerance(); |
252 | if(binf>DH.LastParameter()) { |
253 | done=Standard_True; return; |
254 | } |
255 | } |
256 | IntRes2d_Domain DHModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
257 | Inter.Perform(ITool,DL,PCurve,DHModif,TolConf,Tol); |
258 | } |
259 | this->SetValues(Inter); |
260 | } |
261 | else { |
262 | done = Standard_True; |
263 | } |
264 | } |
265 | |
266 | //======================================================================= |
267 | //function : Perform |
268 | //purpose : Circle - Parabola |
269 | //======================================================================= |
270 | void IntCurve_IntConicConic::Perform(const gp_Circ2d& C, |
271 | const IntRes2d_Domain& DC, |
272 | const gp_Parab2d& P, |
273 | const IntRes2d_Domain& DP, |
274 | const Standard_Real TolConf, |
275 | const Standard_Real Tol) |
276 | { |
277 | this->ResetFields(); |
278 | IntCurve_IConicTool ITool(C); |
279 | IntCurve_PConic PCurve(P); |
280 | PCurve.SetAccuracy(20); |
281 | Inter.SetReversedParameters(ReversedParameters()); |
282 | |
283 | IntRes2d_Domain D(DC); |
284 | if(! DC.IsClosed()) { |
c6541a0c |
285 | D.SetEquivalentParameters(DC.FirstParameter(),DC.FirstParameter()+M_PI+M_PI); |
7fd59977 |
286 | } |
287 | |
288 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
289 | gp_Pnt2d Pntinf,Pntsup; |
290 | maxtol = C.Radius() / 10.0; |
291 | gp_Circ2d Cp(C); |
292 | Cp.SetRadius(C.Radius()+maxtol); |
293 | IntAna2d_AnaIntersection theIntAna2d; |
294 | theIntAna2d.Perform(P,Cp); |
295 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P,maxtol,PARAM_MAX_ON_PARABOLA); |
296 | if(C.Radius() > maxtol) { |
297 | Cp.SetRadius(C.Radius() - maxtol); |
298 | theIntAna2d.Perform(P,Cp); |
299 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P,maxtol,PARAM_MAX_ON_PARABOLA); |
300 | } |
301 | if(binf<=bsup) { |
302 | if(!BOUNDED_DOMAIN(DP)) { |
303 | Standard_Real tolinf = 0.0; |
304 | Standard_Real tolsup = 0.0; |
305 | if(SET_BOUNDED_DOMAIN(DP,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
306 | IntRes2d_Domain DPModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
307 | Inter.Perform(ITool,D,PCurve,DPModif,TolConf,Tol); |
308 | } |
309 | else { |
310 | done = Standard_True; return; |
311 | } |
312 | } |
313 | else { |
314 | Standard_Real ft=0.0,lt=0.0; |
315 | if(binf< DP.FirstParameter()) { |
316 | binf = DP.FirstParameter(); |
317 | Pntinf = DP.FirstPoint(); |
318 | ft = DP.FirstTolerance(); |
319 | if(bsup < DP.FirstParameter()) { |
320 | done=Standard_True; return; |
321 | } |
322 | } |
323 | if(bsup> DP.LastParameter()) { |
324 | bsup = DP.LastParameter(); |
325 | Pntsup = DP.LastPoint(); |
326 | lt = DP.LastTolerance(); |
327 | if(binf>DP.LastParameter()) { |
328 | done=Standard_True; return; |
329 | } |
330 | } |
331 | IntRes2d_Domain DPModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
332 | Inter.Perform(ITool,D,PCurve,DPModif,TolConf,Tol); |
333 | } |
334 | this->SetValues(Inter); |
335 | } |
336 | else { |
337 | done = Standard_True; |
338 | } |
339 | } |
340 | |
341 | //======================================================================= |
342 | //function : Perform |
343 | //purpose : Circle - Elipse |
344 | //======================================================================= |
345 | void IntCurve_IntConicConic::Perform(const gp_Circ2d& C, |
346 | const IntRes2d_Domain& DC, |
347 | const gp_Elips2d& E, |
348 | const IntRes2d_Domain& DE, |
349 | const Standard_Real TolConf, |
350 | const Standard_Real Tol) |
351 | { |
352 | this->ResetFields(); |
353 | IntCurve_IConicTool ITool(C); |
354 | IntCurve_PConic PCurve(E); |
355 | PCurve.SetAccuracy(20); |
356 | |
357 | Inter.SetReversedParameters(ReversedParameters()); |
358 | |
359 | if(! DC.IsClosed()) { |
360 | IntRes2d_Domain D1(DC); |
c6541a0c |
361 | D1.SetEquivalentParameters(DC.FirstParameter(),DC.FirstParameter()+M_PI+M_PI); |
7fd59977 |
362 | if(! DE.IsClosed()) { |
363 | IntRes2d_Domain D2(DE); |
c6541a0c |
364 | D2.SetEquivalentParameters(DE.FirstParameter(),DE.FirstParameter()+M_PI+M_PI); |
7fd59977 |
365 | Inter.Perform(ITool,D1,PCurve,D2,TolConf,Tol); |
366 | } |
367 | else { |
368 | Inter.Perform(ITool,D1,PCurve,DE,TolConf,Tol); |
369 | } |
370 | } |
371 | else { |
372 | if(! DE.IsClosed()) { |
373 | IntRes2d_Domain D2(DE); |
c6541a0c |
374 | D2.SetEquivalentParameters(DE.FirstParameter(),DE.FirstParameter()+M_PI+M_PI); |
7fd59977 |
375 | Inter.Perform(ITool,DC,PCurve,D2,TolConf,Tol); |
376 | } |
377 | else { |
378 | Inter.Perform(ITool,DC,PCurve,DE,TolConf,Tol); |
379 | } |
380 | } |
381 | this->SetValues(Inter); |
382 | } |
383 | |
384 | //======================================================================= |
385 | //function : Perform |
386 | //purpose : Circle - Hyperbola |
387 | //======================================================================= |
388 | void IntCurve_IntConicConic::Perform(const gp_Circ2d& C, |
389 | const IntRes2d_Domain& DC, |
390 | const gp_Hypr2d& H, |
391 | const IntRes2d_Domain& DH, |
392 | const Standard_Real TolConf, |
393 | const Standard_Real Tol) |
394 | { |
395 | this->ResetFields(); |
396 | IntCurve_IConicTool ITool(C); |
397 | IntCurve_PConic PCurve(H); |
398 | PCurve.SetAccuracy(20); |
399 | Inter.SetReversedParameters(ReversedParameters()); |
400 | IntRes2d_Domain D(DC); |
401 | |
402 | if(! DC.IsClosed()) { |
c6541a0c |
403 | D.SetEquivalentParameters(DC.FirstParameter(),DC.FirstParameter()+M_PI+M_PI); |
7fd59977 |
404 | } |
405 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
406 | gp_Pnt2d Pntinf,Pntsup; |
407 | maxtol = C.Radius() / 10.0; |
408 | gp_Vec2d Offset(maxtol*H.XAxis().Direction().X(), |
409 | maxtol*H.XAxis().Direction().Y()); |
410 | gp_Hypr2d Hp(H.Translated(Offset)); |
411 | IntAna2d_AnaIntersection theIntAna2d; |
412 | theIntAna2d.Perform(Hp,C); |
413 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
414 | Offset.Reverse(); |
415 | gp_Hypr2d Hm(H.Translated(Offset)); |
416 | theIntAna2d.Perform(Hm,C); |
417 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
418 | if(binf<=bsup) { |
419 | if(!BOUNDED_DOMAIN(DH)) { |
420 | Standard_Real tolinf = 0.0; |
421 | Standard_Real tolsup = 0.0; |
422 | if(SET_BOUNDED_DOMAIN(DH,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
423 | IntRes2d_Domain DHModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
424 | Inter.Perform(ITool,D,PCurve,DHModif,TolConf,Tol); |
425 | } |
426 | else { |
427 | done = Standard_True; return; |
428 | } |
429 | } |
430 | else { |
431 | Standard_Real ft=0.0,lt=0.0; |
432 | if(binf< DH.FirstParameter()) { |
433 | binf = DH.FirstParameter(); |
434 | Pntinf = DH.FirstPoint(); |
435 | ft = DH.FirstTolerance(); |
436 | if(bsup < DH.FirstParameter()) { |
437 | done=Standard_True; return; |
438 | } |
439 | } |
440 | if(bsup> DH.LastParameter()) { |
441 | bsup = DH.LastParameter(); |
442 | Pntsup = DH.LastPoint(); |
443 | lt = DH.LastTolerance(); |
444 | if(binf>DH.LastParameter()) { |
445 | done=Standard_True; return; |
446 | } |
447 | } |
448 | IntRes2d_Domain DHModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
449 | Inter.Perform(ITool,D,PCurve,DHModif,TolConf,Tol); |
450 | } |
451 | this->SetValues(Inter); |
452 | } |
453 | else { |
454 | done = Standard_True; |
455 | } |
456 | } |
457 | |
458 | //======================================================================= |
459 | //function : Perform |
460 | //purpose : Parabola - Parabola |
461 | //======================================================================= |
462 | void IntCurve_IntConicConic::Perform(const gp_Parab2d& P1, |
463 | const IntRes2d_Domain& DP1, |
464 | const gp_Parab2d& P2, |
465 | const IntRes2d_Domain& DP2, |
466 | const Standard_Real TolConf, |
467 | const Standard_Real Tol) |
468 | { |
469 | this->ResetFields(); |
470 | IntCurve_IConicTool ITool(P1); |
471 | IntCurve_PConic PCurve(P2); |
472 | PCurve.SetAccuracy(20); |
473 | Inter.SetReversedParameters(ReversedParameters()); |
474 | |
475 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
476 | gp_Pnt2d Pntinf,Pntsup; |
477 | if(Tol > TolConf) maxtol = Tol; else maxtol = TolConf; |
478 | maxtol*=100.0; |
479 | if(maxtol<0.000001) maxtol = 0.000001; |
480 | gp_Vec2d Offset(maxtol*P2.MirrorAxis().Direction().X(), |
481 | maxtol*P2.MirrorAxis().Direction().Y()); |
482 | gp_Parab2d Pp(P2.Translated(Offset)); |
483 | IntAna2d_AnaIntersection theIntAna2d; |
484 | theIntAna2d.Perform(Pp,P1); |
485 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P2,maxtol,PARAM_MAX_ON_PARABOLA); |
486 | Offset.Reverse(); |
487 | gp_Parab2d Pm(P2.Translated(Offset)); |
488 | theIntAna2d.Perform(Pm,P1); |
489 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P2,maxtol,PARAM_MAX_ON_PARABOLA); |
490 | if(binf<=bsup) { |
491 | if(!BOUNDED_DOMAIN(DP2)) { |
492 | Standard_Real tolinf = 0.0; |
493 | Standard_Real tolsup = 0.0; |
494 | if(SET_BOUNDED_DOMAIN(DP2,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
495 | IntRes2d_Domain DPModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
496 | Inter.Perform(ITool,DP1,PCurve,DPModif,TolConf,Tol); |
497 | } |
498 | else { |
499 | done = Standard_True; return; |
500 | } |
501 | } |
502 | else { |
503 | Standard_Real ft=0.0,lt=0.0; |
504 | if(binf< DP2.FirstParameter()) { |
505 | binf = DP2.FirstParameter(); |
506 | Pntinf = DP2.FirstPoint(); |
507 | ft = DP2.FirstTolerance(); |
508 | if(bsup < DP2.FirstParameter()) { |
509 | done=Standard_True; return; |
510 | } |
511 | } |
512 | if(bsup> DP2.LastParameter()) { |
513 | bsup = DP2.LastParameter(); |
514 | Pntsup = DP2.LastPoint(); |
515 | lt = DP2.LastTolerance(); |
516 | if(binf>DP2.LastParameter()) { |
517 | done=Standard_True; return; |
518 | } |
519 | } |
520 | IntRes2d_Domain DPModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
521 | Inter.Perform(ITool,DP1,PCurve,DPModif,TolConf,Tol); |
522 | } |
523 | this->SetValues(Inter); |
524 | } |
525 | else { |
526 | done = Standard_True; |
527 | } |
528 | } |
529 | |
530 | //======================================================================= |
531 | //function : Perform |
532 | //purpose : Elipse - Parabola |
533 | //======================================================================= |
534 | void IntCurve_IntConicConic::Perform(const gp_Elips2d& E, |
535 | const IntRes2d_Domain& DE, |
536 | const gp_Parab2d& P, |
537 | const IntRes2d_Domain& DP, |
538 | const Standard_Real TolConf, |
539 | const Standard_Real Tol) |
540 | { |
541 | this->ResetFields(); |
542 | IntCurve_IConicTool ITool(E); |
543 | IntCurve_PConic PCurve(P); |
544 | PCurve.SetAccuracy(20); |
545 | Inter.SetReversedParameters(ReversedParameters()); |
546 | |
547 | IntRes2d_Domain D(DE); |
548 | if(! DE.IsClosed()) { |
c6541a0c |
549 | D.SetEquivalentParameters(DE.FirstParameter(),DE.FirstParameter()+M_PI+M_PI); |
7fd59977 |
550 | } |
551 | |
04232180 |
552 | //-- std::cout<<" Parab Elips "<<std::endl; |
7fd59977 |
553 | |
554 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
555 | gp_Pnt2d Pntinf,Pntsup; |
556 | if(Tol > TolConf) maxtol = Tol; else maxtol = TolConf; |
557 | |
558 | maxtol = E.MinorRadius() / 10.0; |
559 | gp_Elips2d Ep(E); |
560 | Ep.SetMajorRadius(E.MajorRadius()+maxtol); |
561 | Ep.SetMinorRadius(E.MinorRadius()+maxtol); |
562 | IntAna2d_AnaIntersection theIntAna2d; |
563 | theIntAna2d.Perform(P,Ep); |
564 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P,maxtol,PARAM_MAX_ON_PARABOLA); |
565 | if(E.MinorRadius() > maxtol) { |
566 | Ep.SetMinorRadius(E.MinorRadius() - maxtol); |
567 | Ep.SetMajorRadius(E.MajorRadius() - maxtol); |
568 | theIntAna2d.Perform(P,Ep); |
569 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,P,maxtol,PARAM_MAX_ON_PARABOLA); |
570 | } |
04232180 |
571 | //-- std::cout<<" binf,bsup "<<binf<<" "<<bsup<<std::endl; |
7fd59977 |
572 | if(binf<=bsup) { |
573 | if(!BOUNDED_DOMAIN(DP)) { |
574 | Standard_Real tolinf = 0.0; |
575 | Standard_Real tolsup = 0.0; |
576 | if(SET_BOUNDED_DOMAIN(DP,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
577 | IntRes2d_Domain DPModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
578 | Inter.Perform(ITool,D,PCurve,DPModif,TolConf,Tol); |
579 | } |
580 | else { |
581 | done = Standard_True; return; |
582 | } |
583 | } |
584 | else { |
585 | Standard_Real ft=0.0,lt=0.0; |
586 | if(binf< DP.FirstParameter()) { |
587 | binf = DP.FirstParameter(); |
588 | Pntinf = DP.FirstPoint(); |
589 | ft = DP.FirstTolerance(); |
590 | if(bsup < DP.FirstParameter()) { |
591 | done=Standard_True; return; |
592 | } |
593 | } |
594 | if(bsup> DP.LastParameter()) { |
595 | bsup = DP.LastParameter(); |
596 | Pntsup = DP.LastPoint(); |
597 | lt = DP.LastTolerance(); |
598 | if(binf>DP.LastParameter()) { |
599 | done=Standard_True; return; |
600 | } |
601 | } |
04232180 |
602 | //-- std::cout<<"BOUNDED binf,bsup "<<binf<<" "<<bsup<<std::endl; |
603 | //-- std::cout<<"Domain "<<DP.FirstParameter()<<" "<<DP.LastParameter()<<std::endl; |
7fd59977 |
604 | IntRes2d_Domain DPModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
605 | Inter.Perform(ITool,D,PCurve,DPModif,TolConf,Tol); |
606 | } |
607 | this->SetValues(Inter); |
608 | } |
609 | else { |
610 | done = Standard_True; |
611 | } |
612 | } |
613 | |
614 | //======================================================================= |
615 | //function : Perform |
616 | //purpose : Parabola - Hyperbola |
617 | //======================================================================= |
618 | void IntCurve_IntConicConic::Perform(const gp_Parab2d& P, |
619 | const IntRes2d_Domain& DP, |
620 | const gp_Hypr2d& H, |
621 | const IntRes2d_Domain& DH, |
622 | const Standard_Real TolConf, |
623 | const Standard_Real Tol) |
624 | { |
625 | this->ResetFields(); |
626 | IntCurve_IConicTool ITool(P); |
627 | IntCurve_PConic PCurve(H); |
628 | Inter.SetReversedParameters(ReversedParameters()); |
629 | |
630 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
631 | gp_Pnt2d Pntinf,Pntsup; |
632 | if(Tol > TolConf) maxtol = Tol; else maxtol = TolConf; |
633 | maxtol*=100.0; |
634 | if(maxtol<0.000001) maxtol = 0.000001; |
635 | gp_Vec2d Offset(maxtol*H.XAxis().Direction().X(), |
636 | maxtol*H.XAxis().Direction().Y()); |
637 | gp_Hypr2d Hp(H.Translated(Offset)); |
638 | IntAna2d_AnaIntersection theIntAna2d; |
639 | theIntAna2d.Perform(Hp,P); |
640 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
641 | Offset.Reverse(); |
642 | gp_Hypr2d Hm(H.Translated(Offset)); |
643 | theIntAna2d.Perform(Hm,P); |
644 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
645 | if(binf<=bsup) { |
646 | if(!BOUNDED_DOMAIN(DH)) { |
647 | Standard_Real tolinf = 0.0; |
648 | Standard_Real tolsup = 0.0; |
649 | if(SET_BOUNDED_DOMAIN(DH,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
650 | IntRes2d_Domain DHModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
651 | Inter.Perform(ITool,DP,PCurve,DHModif,TolConf,Tol); |
652 | } |
653 | else { |
654 | done = Standard_True; return; |
655 | } |
656 | } |
657 | else { |
658 | Standard_Real ft=0.0,lt=0.0; |
659 | if(binf< DH.FirstParameter()) { |
660 | binf = DH.FirstParameter(); |
661 | Pntinf = DH.FirstPoint(); |
662 | ft = DH.FirstTolerance(); |
663 | if(bsup < DH.FirstParameter()) { |
664 | done=Standard_True; return; |
665 | } |
666 | } |
667 | if(bsup> DH.LastParameter()) { |
668 | bsup = DH.LastParameter(); |
669 | Pntsup = DH.LastPoint(); |
670 | lt = DH.LastTolerance(); |
671 | if(binf>DH.LastParameter()) { |
672 | done=Standard_True; return; |
673 | } |
674 | } |
675 | IntRes2d_Domain DHModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
676 | Inter.Perform(ITool,DP,PCurve,DHModif,TolConf,Tol); |
677 | } |
678 | this->SetValues(Inter); |
679 | } |
680 | else { |
681 | done = Standard_True; |
682 | } |
683 | } |
684 | |
685 | //======================================================================= |
686 | //function : Perform |
687 | //purpose : Elipse - Elipse |
688 | //======================================================================= |
689 | |
690 | void IntCurve_IntConicConic::Perform(const gp_Elips2d& E1, |
691 | const IntRes2d_Domain& DE1, |
692 | const gp_Elips2d& E2, |
693 | const IntRes2d_Domain& DE2, |
694 | const Standard_Real TolConf, |
695 | const Standard_Real Tol) |
696 | { |
697 | this->ResetFields(); |
698 | IntCurve_IConicTool ITool(E1); |
699 | IntCurve_PConic PCurve(E2); |
700 | PCurve.SetAccuracy(20); |
701 | |
702 | |
703 | Inter.SetReversedParameters(ReversedParameters()); |
704 | |
705 | if(! DE1.IsClosed()) { |
706 | IntRes2d_Domain D1(DE1); |
c6541a0c |
707 | D1.SetEquivalentParameters(DE1.FirstParameter(),DE1.FirstParameter()+M_PI+M_PI); |
7fd59977 |
708 | if(! DE2.IsClosed()) { |
709 | IntRes2d_Domain D2(DE2); |
c6541a0c |
710 | D2.SetEquivalentParameters(DE2.FirstParameter(),DE2.FirstParameter()+M_PI+M_PI); |
7fd59977 |
711 | Inter.Perform(ITool,D1,PCurve,D2,TolConf,Tol); |
712 | } |
713 | else { |
714 | Inter.Perform(ITool,D1,PCurve,DE2,TolConf,Tol); |
715 | } |
716 | } |
717 | else { |
718 | if(! DE2.IsClosed()) { |
719 | IntRes2d_Domain D2(DE2); |
c6541a0c |
720 | D2.SetEquivalentParameters(DE2.FirstParameter(),DE2.FirstParameter()+M_PI+M_PI); |
7fd59977 |
721 | Inter.Perform(ITool,DE1,PCurve,D2,TolConf,Tol); |
722 | } |
723 | else { |
724 | Inter.Perform(ITool,DE1,PCurve,DE2,TolConf,Tol); |
725 | } |
726 | } |
727 | this->SetValues(Inter); |
728 | } |
729 | |
730 | //======================================================================= |
731 | //function : Perform |
732 | //purpose : Elipse - Hyperbola |
733 | //======================================================================= |
734 | void IntCurve_IntConicConic::Perform(const gp_Elips2d& E, |
735 | const IntRes2d_Domain& DE, |
736 | const gp_Hypr2d& H, |
737 | const IntRes2d_Domain& DH, |
738 | const Standard_Real TolConf, |
739 | const Standard_Real Tol) |
740 | { |
741 | this->ResetFields(); |
742 | IntCurve_IConicTool ITool(E); |
743 | IntCurve_PConic PCurve(H); |
744 | PCurve.SetAccuracy(20); |
745 | Inter.SetReversedParameters(ReversedParameters()); |
746 | IntRes2d_Domain DEModif(DE); |
747 | |
748 | if(! DE.IsClosed()) { |
c6541a0c |
749 | DEModif.SetEquivalentParameters(DE.FirstParameter(),DE.FirstParameter()+M_PI+M_PI); |
7fd59977 |
750 | } |
751 | |
752 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
753 | gp_Pnt2d Pntinf,Pntsup; |
754 | maxtol = E.MinorRadius() / 10.0; |
755 | gp_Vec2d Offset(maxtol*H.XAxis().Direction().X(), |
756 | maxtol*H.XAxis().Direction().Y()); |
757 | gp_Hypr2d Hp(H.Translated(Offset)); |
758 | IntAna2d_AnaIntersection theIntAna2d; |
759 | theIntAna2d.Perform(Hp,E); |
760 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
761 | Offset.Reverse(); |
762 | gp_Hypr2d Hm(H.Translated(Offset)); |
763 | theIntAna2d.Perform(Hm,E); |
764 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H,maxtol,PARAM_MAX_ON_HYPERBOLA); |
765 | if(binf<=bsup) { |
766 | if(!BOUNDED_DOMAIN(DH)) { |
767 | Standard_Real tolinf = 0.0; |
768 | Standard_Real tolsup = 0.0; |
769 | if(SET_BOUNDED_DOMAIN(DH,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
770 | IntRes2d_Domain DHModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
771 | Inter.Perform(ITool,DEModif,PCurve,DHModif,TolConf,Tol); |
772 | } |
773 | else { |
774 | done = Standard_True; return; |
775 | } |
776 | } |
777 | else { |
778 | Standard_Real ft=0.0,lt=0.0; |
779 | if(binf< DH.FirstParameter()) { |
780 | binf = DH.FirstParameter(); |
781 | Pntinf = DH.FirstPoint(); |
782 | ft = DH.FirstTolerance(); |
783 | if(bsup < DH.FirstParameter()) { |
784 | done=Standard_True; return; |
785 | } |
786 | } |
787 | if(bsup> DH.LastParameter()) { |
788 | bsup = DH.LastParameter(); |
789 | Pntsup = DH.LastPoint(); |
790 | lt = DH.LastTolerance(); |
791 | if(binf>DH.LastParameter()) { |
792 | done=Standard_True; return; |
793 | } |
794 | } |
795 | if(binf>=bsup) { |
796 | done = Standard_True; return; |
797 | } |
798 | IntRes2d_Domain DHModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
799 | Inter.Perform(ITool,DEModif,PCurve,DHModif,TolConf,Tol); |
800 | } |
801 | this->SetValues(Inter); |
802 | } |
803 | else { |
804 | done = Standard_True; |
805 | } |
806 | } |
807 | |
808 | //======================================================================= |
809 | //function : Perform |
810 | //purpose : Hyperbola - Hyperbola |
811 | //======================================================================= |
812 | |
813 | void IntCurve_IntConicConic::Perform(const gp_Hypr2d& H1, |
814 | const IntRes2d_Domain& DH1, |
815 | const gp_Hypr2d& H2, |
816 | const IntRes2d_Domain& DH2, |
817 | const Standard_Real TolConf, |
818 | const Standard_Real Tol) |
819 | { |
820 | this->ResetFields(); |
821 | IntCurve_IConicTool ITool(H1); |
822 | IntCurve_PConic PCurve(H2); |
823 | PCurve.SetAccuracy(20); |
824 | |
825 | Inter.SetReversedParameters(ReversedParameters()); |
826 | |
827 | Standard_Real binf = Precision::Infinite(),bsup = -Precision::Infinite(),maxtol; |
828 | gp_Pnt2d Pntinf,Pntsup; |
829 | if(Tol > TolConf) maxtol = Tol; else maxtol = TolConf; |
830 | maxtol*=100.0; |
831 | if(maxtol<0.000001) maxtol = 0.000001; |
832 | gp_Vec2d Offset(maxtol*H2.XAxis().Direction().X(), |
833 | maxtol*H2.XAxis().Direction().Y()); |
834 | gp_Hypr2d Hp(H2.Translated(Offset)); |
835 | IntAna2d_AnaIntersection theIntAna2d; |
836 | theIntAna2d.Perform(Hp,H1); |
837 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H2,maxtol,PARAM_MAX_ON_HYPERBOLA); |
838 | Offset.Reverse(); |
839 | gp_Hypr2d Hm(H2.Translated(Offset)); |
840 | theIntAna2d.Perform(Hm,H1); |
841 | SetBinfBsupFromIntAna2d(theIntAna2d,binf,Pntinf,bsup,Pntsup,H2,maxtol,PARAM_MAX_ON_HYPERBOLA); |
842 | if(binf<=bsup) { |
843 | if(!BOUNDED_DOMAIN(DH2)) { |
844 | Standard_Real tolinf = 0.0; |
845 | Standard_Real tolsup = 0.0; |
846 | if(SET_BOUNDED_DOMAIN(DH2,binf,tolinf,Pntinf,bsup,tolsup,Pntsup)) { |
847 | IntRes2d_Domain DHModif(Pntinf,binf,tolinf,Pntsup,bsup,tolsup); |
848 | Inter.Perform(ITool,DH1,PCurve,DHModif,TolConf,Tol); |
849 | } |
850 | else { |
851 | done = Standard_True; return; |
852 | } |
853 | } |
854 | else { |
855 | Standard_Real ft=0.0,lt=0.0; |
856 | if(binf< DH2.FirstParameter()) { |
857 | binf = DH2.FirstParameter(); |
858 | Pntinf = DH2.FirstPoint(); |
859 | ft = DH2.FirstTolerance(); |
860 | } |
861 | if(bsup> DH2.LastParameter()) { |
862 | bsup = DH2.LastParameter(); |
863 | Pntsup = DH2.LastPoint(); |
864 | lt = DH2.LastTolerance(); |
865 | } |
866 | |
867 | //-- lbr le 22 sept 97 |
868 | //-- binf=-5.6 bsup=-5.3 DH2=(5.6,5.7) -> binf=+5.6 bsup=-5.3 |
869 | if(binf>=bsup) { |
870 | done = Standard_True; return; |
871 | } |
872 | IntRes2d_Domain DHModif(Pntinf,binf,ft,Pntsup,bsup,lt); |
873 | Inter.Perform(ITool,DH1,PCurve,DHModif,TolConf,Tol); |
874 | } |
875 | this->SetValues(Inter); |
876 | } |
877 | else { |
878 | done = Standard_True; |
879 | } |
880 | } |
881 | //---------------------------------------------------------------------- |
882 | |
883 | |
884 | void SetBinfBsupFromIntAna2d(const IntAna2d_AnaIntersection &theIntAna2d, |
885 | Standard_Real& binf,gp_Pnt2d& Pntinf, |
886 | Standard_Real& bsup,gp_Pnt2d& Pntsup, |
887 | const gp_Parab2d& PR, |
888 | const Standard_Real maxtol, |
889 | const Standard_Real LIMITE) { |
890 | |
891 | |
892 | if(theIntAna2d.IsDone()) { |
893 | if(!theIntAna2d.IsEmpty()) { |
894 | for(Standard_Integer p=1; p<=theIntAna2d.NbPoints(); p++) { |
895 | Standard_Real param = theIntAna2d.Point(p).ParamOnFirst(); |
896 | |
897 | if(Abs(param) < LIMITE) { |
898 | gp_Vec2d V; |
899 | gp_Pnt2d P; |
900 | ElCLib::D1(param,PR,P,V); |
901 | Standard_Real NormeD1 = V.Magnitude(); |
902 | Standard_Real dparam = 100.0*maxtol/NormeD1; |
903 | if(dparam<1e-3) dparam = 1e-3; |
904 | param-=dparam; |
905 | |
906 | if(param < binf) { |
907 | binf = param; |
908 | Pntinf=ElCLib::Value(param,PR); |
909 | } |
910 | param+=dparam+dparam; |
911 | if(param > bsup) { |
912 | bsup = param; |
913 | Pntsup=ElCLib::Value(param,PR); |
914 | } |
915 | } |
916 | } |
917 | } |
918 | } |
919 | } |
920 | void SetBinfBsupFromIntAna2d(const IntAna2d_AnaIntersection &theIntAna2d, |
921 | Standard_Real& binf,gp_Pnt2d& Pntinf, |
922 | Standard_Real& bsup,gp_Pnt2d& Pntsup, |
923 | const gp_Hypr2d& H, |
924 | const Standard_Real maxtol, |
925 | const Standard_Real LIMITE) { |
926 | |
927 | |
928 | if(theIntAna2d.IsDone()) { |
929 | if(!theIntAna2d.IsEmpty()) { |
930 | for(Standard_Integer p=1; p<=theIntAna2d.NbPoints(); p++) { |
931 | Standard_Real param = theIntAna2d.Point(p).ParamOnFirst(); |
932 | |
933 | if(Abs(param) < LIMITE) { |
934 | gp_Vec2d V; |
935 | gp_Pnt2d P; |
936 | ElCLib::D1(param,H,P,V); |
937 | Standard_Real NormeD1 = V.Magnitude(); |
938 | Standard_Real dparam = 100.0*maxtol/NormeD1; |
939 | if(dparam<1e-3) dparam = 1e-3; |
940 | param-=dparam; |
941 | |
942 | if(param < binf) { |
943 | binf = param; |
944 | Pntinf=ElCLib::Value(param,H); |
945 | } |
946 | param+=dparam+dparam; |
947 | if(param > bsup) { |
948 | bsup = param; |
949 | Pntsup=ElCLib::Value(param,H); |
950 | } |
951 | } |
952 | } |
953 | } |
954 | } |
955 | } |
956 | |
957 | |
958 | |