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