0024510: Remove unused local variables
[occt.git] / src / IntImpParGen / IntImpParGen_Intersector.gxx
1 // Created on: 1992-03-02
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Standard_ConstructionError.hxx>
18 #include <IntRes2d_Domain.hxx>
19 #include <IntRes2d_IntersectionPoint.hxx>
20 #include <IntRes2d_IntersectionSegment.hxx>
21 #include <IntRes2d_SequenceOfIntersectionPoint.hxx>
22 #include <IntRes2d_SequenceOfIntersectionSegment.hxx>
23 #include <IntRes2d_Transition.hxx>
24 #include <IntRes2d_Position.hxx>
25
26 #include <IntImpParGen.hxx>
27
28 #include <math_FunctionSample.hxx>
29 #include <math_FunctionAllRoots.hxx>
30
31 #include <TColStd_Array1OfReal.hxx>
32 #include <gp.hxx>
33 #include <gp_Vec2d.hxx>
34
35 //======================================================================
36 #define EPSDIST Tol
37 #define EPSNUL  TolConf
38 #define EPSX    ParTool::EpsX(TheParCurve)
39 #define NB_ECHANTILLONS 
40
41
42
43
44 //======================================================================
45 void IntImpParGen_Intersector::And_Domaine_Objet1_Intersections(const ImpTool& TheImpTool,
46                               const ParCurve& TheParCurve,
47                               const IntRes2d_Domain& TheImpCurveDomain,
48                               const IntRes2d_Domain& TheParCurveDomain,
49                               Standard_Integer& NbResultats,
50                               TColStd_Array1OfReal& Inter2_And_Domain2,
51                               TColStd_Array1OfReal& Inter1,
52                               TColStd_Array1OfReal& Resultat1,
53                               TColStd_Array1OfReal& Resultat2,
54                               const Standard_Real EpsNul) const {
55
56   
57   Standard_Integer Nb_Bornes_Intersection=NbResultats;
58   NbResultats=0;
59   
60   for(Standard_Integer i=1; i<=Nb_Bornes_Intersection; i+=2) {
61     Standard_Real param1=Inter1.Value(i);
62     Standard_Real param2=Inter1.Value(i+1);
63
64     Standard_Integer indice_1=i;
65     Standard_Integer indice_2=i+1;
66
67     if(param1>param2) {
68       Standard_Real t=param1; param1=param2; param2=t;
69       indice_1=i+1;
70       indice_2=i;
71     }
72
73     gp_Pnt2d Pt1=TheImpTool.Value(param1);
74     gp_Pnt2d Pt2=TheImpTool.Value(param2);
75     gp_Pnt2d Pt;
76
77     Standard_Boolean IsOnTheImpCurveDomain1=Standard_True;
78
79     Standard_Boolean IsOnTheImpCurveDomain2=Standard_True;
80     //--------------------------------------------------------------------
81     if(TheImpCurveDomain.HasFirstPoint()) { 
82       if(param1<TheImpCurveDomain.FirstParameter()) {             
83         if(Pt1.Distance(TheImpCurveDomain.FirstPoint()) 
84            > TheImpCurveDomain.FirstTolerance()) {
85           IsOnTheImpCurveDomain1=Standard_False; 
86         }
87       }
88     }
89     if(IsOnTheImpCurveDomain1 && TheImpCurveDomain.HasLastPoint()) {
90       if(param1>TheImpCurveDomain.LastParameter()) {
91         if(Pt1.Distance(TheImpCurveDomain.LastPoint()) 
92            > TheImpCurveDomain.FirstTolerance()) {
93           IsOnTheImpCurveDomain1=Standard_False; 
94         }
95       }
96     }
97     //--------------------------------------------------------------------
98     if(TheImpCurveDomain.HasFirstPoint()) { 
99       if(param2<TheImpCurveDomain.FirstParameter()) {             
100         if(Pt2.Distance(TheImpCurveDomain.FirstPoint()) 
101            > TheImpCurveDomain.FirstTolerance()) {
102           IsOnTheImpCurveDomain2=Standard_False; 
103         }
104       }
105     }
106     if(IsOnTheImpCurveDomain2 && TheImpCurveDomain.HasLastPoint()) {
107       if(param2>TheImpCurveDomain.LastParameter()) {
108         if(Pt2.Distance(TheImpCurveDomain.LastPoint()) 
109            > TheImpCurveDomain.FirstTolerance()) {
110           IsOnTheImpCurveDomain2=Standard_False; 
111         }
112       }
113     }
114
115     if(IsOnTheImpCurveDomain1) {
116       //------------------------------------------------------------------
117       //---                 la borne 1 est sur le domaine               --
118       NbResultats++;
119       Resultat1.SetValue(NbResultats,Inter1.Value(indice_1));
120       Resultat2.SetValue(NbResultats,Inter2_And_Domain2.Value(indice_1));
121       //---               la borne2 est aussi sur le domaine           ---
122       if(IsOnTheImpCurveDomain2) {
123         NbResultats++;
124         Resultat1.SetValue(NbResultats,Inter1.Value(indice_2));
125         Resultat2.SetValue(NbResultats,Inter2_And_Domain2.Value(indice_2));
126       }
127       else {
128         //---    Borne1 sur domaine et Borne 2 Hors Domaine           ---
129         Standard_Real t;
130         NbResultats++;
131         t=TheImpCurveDomain.LastParameter();  
132         Resultat1.SetValue(NbResultats,t);
133 //      Standard_Real popResult = FindV(t,Pt,TheImpTool,TheParCurve,
134 //                                                                TheParCurveDomain,
135 //                                                                Inter2_And_Domain2.Value(indice_1),
136 //                                                                Inter2_And_Domain2.Value(indice_2),
137 //                                                                EpsNul);
138 //      
139 //      Resultat2.SetValue(NbResultats,popResult);
140         Resultat2.SetValue(NbResultats,
141                            IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
142                                                            TheParCurveDomain,
143                                                            Inter2_And_Domain2.Value(indice_1),
144                                                            Inter2_And_Domain2.Value(indice_2),
145                                                            EpsNul));
146       }
147     }
148     else { //======= la borne1 n est pas sur le domaine ========
149       if(IsOnTheImpCurveDomain2) {
150         Standard_Real t;
151         NbResultats++;
152         t=TheImpCurveDomain.FirstParameter(); 
153         
154         Resultat1.SetValue(NbResultats,t);
155         Resultat2.SetValue(NbResultats,
156                            IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
157                                  TheParCurveDomain,
158                                  Inter2_And_Domain2.Value(indice_1),
159                                  Inter2_And_Domain2.Value(indice_2),
160                                  EpsNul));
161         
162         NbResultats++;
163         Resultat1.SetValue(NbResultats,Inter1.Value(indice_2));
164         Resultat2.SetValue(NbResultats,Inter2_And_Domain2.Value(indice_2));
165       }
166       else {  //====== la borne2 et la borne1 sont hors domaine =====
167         if(param1<TheImpCurveDomain.FirstParameter()
168            && param2>TheImpCurveDomain.LastParameter()) {
169           Standard_Real t;
170           NbResultats++;
171           t=TheImpCurveDomain.FirstParameter();
172           Resultat1.SetValue(NbResultats,t);
173           Resultat2.SetValue(NbResultats,
174                              IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
175                                                              TheParCurveDomain,
176                                                              Inter2_And_Domain2.Value(indice_1),
177                                                              Inter2_And_Domain2.Value(indice_2),
178                                                              EpsNul));
179
180
181           
182           NbResultats++;
183           t=TheImpCurveDomain.LastParameter();
184           Resultat1.SetValue(NbResultats,t);
185           Resultat2.SetValue(NbResultats,
186                              IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
187                                    TheParCurveDomain,
188                                    Inter2_And_Domain2.Value(indice_1),
189                                    Inter2_And_Domain2.Value(indice_2),
190                                    EpsNul));
191           
192         }
193       }
194     }
195   }
196 }
197 //======================================================================
198 //--     C o n s t r u c t e u r s     e t     P e r f o r m 
199 IntImpParGen_Intersector::IntImpParGen_Intersector() {
200   done=Standard_False;
201 }
202 //----------------------------------------------------------------------
203 //--
204 IntImpParGen_Intersector::IntImpParGen_Intersector(const ImpTool& TheImpTool,
205                                         const IntRes2d_Domain& TheImpCurveDomain,
206                                         const ParCurve& TheParCurve,
207                                         const IntRes2d_Domain& TheParCurveDomain,
208                                         const Standard_Real TolConf,
209                                         const Standard_Real Tol) {
210   Perform(TheImpTool,TheImpCurveDomain,TheParCurve,TheParCurveDomain,TolConf,Tol);
211 }
212 //----------------------------------------------------------------------
213 //--
214 void IntImpParGen_Intersector::Perform(const ImpTool& TheImpTool,
215                                         const IntRes2d_Domain& TheImpCurveDomain,
216                                         const ParCurve& TheParCurve,
217                                         const IntRes2d_Domain& TheParCurveDomain,
218                                         const Standard_Real TolConf,
219                                         const Standard_Real Tol) {
220
221
222   Standard_Integer i,nb_segments_solution, nb_points_solution;
223   Standard_Real param1,param2,EpsX, EpsNul, EpsDist;
224   
225   IntRes2d_Transition Trans1,Trans2;
226   gp_Pnt2d pt1,pt2;
227   gp_Vec2d Tan1,Tan2,Norm1,Norm2;
228   IntRes2d_Position Pos1,Pos2;
229
230
231   //----------------------------------------------
232   //-- On teste apres appel aux maths si les bornes 
233   //-- des domaines sont des solutions
234   //-- 
235   Standard_Boolean HeadOnImp =Standard_False;
236   Standard_Boolean HeadOnPar =Standard_False;
237   Standard_Boolean EndOnImp  =Standard_False;
238   Standard_Boolean EndOnPar  =Standard_False;
239
240   this->ResetFields();
241
242   IntImpParGen_MyImpParTool TheImpParTool(TheImpTool,TheParCurve);
243
244   if (! (TheParCurveDomain.HasFirstPoint() &&
245          TheParCurveDomain.HasLastPoint())) {
246     Standard_ConstructionError::Raise("Domaine sur courbe incorrect");
247     }
248   
249   Standard_Integer nb_echantillons = ParTool::NbSamples(TheParCurve,
250                                                         TheParCurveDomain.FirstParameter(),
251                                                         TheParCurveDomain.LastParameter());
252
253   EpsX = EPSX;
254   if(EpsX>1.0e-10) EpsX = 1.0e-10;
255   EpsNul=(TolConf<=1.0e-10)? 1.0e-10: TolConf;
256   EpsDist=(Tol<=1.0e-10)? 1.0e-10: Tol;
257   
258   Standard_Real Tolerance_Angulaire=EpsDist;  
259   
260
261
262   if((TheParCurveDomain.LastParameter() - TheParCurveDomain.FirstParameter()) < 100.0*EpsX) {
263     EpsX = (TheParCurveDomain.LastParameter() - TheParCurveDomain.FirstParameter())*0.01;
264   }
265
266     math_FunctionSample Sample2(TheParCurveDomain.FirstParameter(),
267                                 TheParCurveDomain.LastParameter(),
268                                 nb_echantillons);
269     
270     math_FunctionAllRoots Sol(TheImpParTool,
271                               Sample2,
272                               EpsX,
273                               EpsDist,
274                               EpsNul);
275     
276     if(!Sol.IsDone()) {done = Standard_False; return; }
277     
278     nb_segments_solution=Sol.NbIntervals();
279     nb_points_solution=Sol.NbPoints();
280     
281     //--------------------------------------------------------------------
282   //--   T r a i t e m e n t    d e s   P o i n t s   S o l u t i o n s
283   for(i=1; i<=nb_points_solution; i++) {
284     gp_Pnt2d Pt;
285     param2=Sol.GetPoint(i);
286     param1=FindU(param2,Pt,TheParCurve,TheImpTool);
287   
288     if(TheImpCurveDomain.IsClosed()) {
289       param1 = IntImpParGen::NormalizeOnDomain( param1
290                                  ,TheImpCurveDomain);
291     }
292     
293     Standard_Boolean IsOnTheImpCurveDomain=Standard_True;
294     if(TheImpCurveDomain.HasFirstPoint()) { 
295       if(param1<TheImpCurveDomain.FirstParameter()) {             
296         if(Pt.Distance(TheImpCurveDomain.FirstPoint()) 
297            > TheImpCurveDomain.FirstTolerance()) {
298           IsOnTheImpCurveDomain=Standard_False; 
299         }
300       }
301     }
302     if(IsOnTheImpCurveDomain && TheImpCurveDomain.HasLastPoint()) {
303       if(param1>TheImpCurveDomain.LastParameter()) {
304         if(Pt.Distance(TheImpCurveDomain.LastPoint()) 
305            > TheImpCurveDomain.FirstTolerance()) {
306           IsOnTheImpCurveDomain=Standard_False; 
307         }
308       }
309     }
310     
311     if(IsOnTheImpCurveDomain) {
312       TheImpTool.D2(param1,pt1,Tan1,Norm1);
313       ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
314       
315       IntImpParGen::DeterminePosition(Pos1,TheImpCurveDomain,pt1,param1);
316       IntImpParGen::DeterminePosition(Pos2,TheParCurveDomain,pt2,param2);
317       
318       if(Pos1==IntRes2d_End)  EndOnImp  = Standard_True;
319       else if(Pos1==IntRes2d_Head) HeadOnImp = Standard_True;
320       if(Pos2==IntRes2d_End)  EndOnPar  = Standard_True;
321       else if(Pos2==IntRes2d_Head) HeadOnPar = Standard_True;
322
323       IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
324                            Pos2,Tan2,Norm2,Trans2,
325                            Tolerance_Angulaire);
326
327       IntRes2d_IntersectionPoint IP(pt1,param1,param2
328                                     ,Trans1,Trans2
329                                     ,ReversedParameters());
330       Insert(IP);
331     }
332   } 
333   //-- F i n   d u   T r a i t e m e n t   d e s   P t s   S o l.
334
335
336   //--------------------------------------------------------------------
337   //--        T r a i t e m e n t   D e s   S e g m e n t s          ---
338   //--------------------------------------------------------------------
339   //--  On a N segments solution sur le domaine de V    soit au pire :
340   //--    --> N segments solution sur le domaine de U 
341   //--    -->2N segments si la courbe en U est fermee
342   //--   
343
344   TColStd_Array1OfReal Inter2_and_Domaine2(1,2+8*nb_segments_solution);
345   TColStd_Array1OfReal Inter1(1,2+8*nb_segments_solution);
346
347   Standard_Integer nb_segments_crees=0;
348
349   for (Standard_Integer j2=1,j=1;j<=nb_segments_solution;j++,j2+=2) {
350     Standard_Real param2_inf,param2_sup;
351     Standard_Real param1_inf,param1_sup;
352     gp_Pnt2d Ptemp;
353     
354     Sol.GetInterval(j,param2_inf,param2_sup);
355     param1_inf=FindU(param2_inf,Ptemp,TheParCurve,TheImpTool);
356     param1_sup=FindU(param2_sup,Ptemp,TheParCurve,TheImpTool);    
357
358     //----------------------------------------------------------------------
359     //--         C o u r b e    I m p l i c i t e    F e r m e e 
360
361     if(TheImpCurveDomain.IsClosed()) {
362
363       gp_Pnt2d Ptemp;
364       gp_Vec2d T1,T2,N1,N2;
365       Standard_Real param1_origine,param1_fin;
366
367       TheImpCurveDomain.EquivalentParameters(param1_origine,param1_fin);
368       Standard_Real Periode=param1_fin-param1_origine;
369
370       while(param1_inf<param1_origine) { param1_inf+=Periode; }
371       while(param1_sup<param1_origine) { param1_sup+=Periode; }      
372
373       ParTool::D2(TheParCurve,param2_inf,Ptemp,T2,N2);
374       TheImpTool.D2(param1_inf,Ptemp,T1,N1);
375       if(T1.Magnitude()<=gp::Resolution()) T1=N1;
376       if(T2.Magnitude()<=gp::Resolution()) T2=N2;
377
378       if(T1.Dot(T2) >=0.0) {
379         //---  param1_inf designe un point entrant (et T1 est vers la matiere)
380         if(param1_inf>=param1_sup) {    param1_sup+=Periode;    }
381       }
382       else { //---  param1_inf : point sortant (et T1 est Hors matiere)
383         if(param1_inf<=param1_sup) {    param1_inf+=Periode;     }
384       }
385       //--- On cree un nouveau segment decale de Periode
386       //--  Exemple de Pb : Domaine PI/4  PI/2   et intervalle 0,PI
387       //--                  Domaine 1.5PI 2.5PI  et intervalle 0,PI
388       //--        -2pi                  0                2pi     
389       //--   ------|--------------------|-----------------|-----------
390       //--            [----------------------------]               Domaine
391       //--                                   [~~~~~~~~~~~~~~~~~]   Inters.
392       //--
393       //--  On cree un nouvel intervalle 
394       //--   interv decale
395       //--  [a~~~~~~~~~~~~b]                 [a~~~~~~~~~~~~~~~b]  et  [a~~~]
396       //--
397       //
398
399       if(TheImpCurveDomain.LastParameter() 
400          > ((param1_inf>param1_sup)? (param1_sup+Periode): 
401                                       (param1_inf+Periode))) {
402         Inter2_and_Domaine2.SetValue(j2,param2_inf);
403         Inter1.SetValue(j2,param1_inf+Periode);
404       
405         Inter2_and_Domaine2.SetValue(j2+1,param2_sup);
406         Inter1.SetValue(j2+1,param1_sup+Periode);     
407         j2+=2;
408         nb_segments_crees++;
409       }
410                                                                        
411       if(TheImpCurveDomain.FirstParameter() 
412          <((param1_inf<param1_sup)? (param1_sup-Periode): (param1_inf-Periode))) {
413         Inter2_and_Domaine2.SetValue(j2,param2_inf);
414         Inter1.SetValue(j2,param1_inf-Periode);
415         
416         Inter2_and_Domaine2.SetValue(j2+1,param2_sup);
417         Inter1.SetValue(j2+1,param1_sup-Periode);     
418         j2+=2;
419         nb_segments_crees++;
420       }
421     }
422     //--   F i n     C o u r b e    I m p l i c i t e    F e r m e e 
423     //----------------------------------------------------------------------
424
425
426     Inter2_and_Domaine2.SetValue(j2,param2_inf);
427     Inter1.SetValue(j2,param1_inf);
428     
429     Inter2_and_Domaine2.SetValue(j2+1,param2_sup);
430     Inter1.SetValue(j2+1,param1_sup);
431   } 
432   
433   //------------------------------------------------------------------
434   //--  INTER2_DOMAINE2 : Intersection AND CurveDomain : Function of PARAM2
435   //--    INTER1        : Intersection AND CurveDomain : Function of PARAM1
436   //------------------------------------------------------------------  
437   //--
438   TColStd_Array1OfReal Resultat1(1,2+(1+nb_segments_solution)*2);
439   TColStd_Array1OfReal Resultat2(1,2+(1+nb_segments_solution)*2);
440   nb_segments_solution+=nb_segments_crees;
441   Standard_Integer NbResultats=nb_segments_solution*2;
442
443   And_Domaine_Objet1_Intersections(TheImpTool,
444                                    TheParCurve,
445                                    TheImpCurveDomain,
446                                    TheParCurveDomain,
447                                    NbResultats,
448                                    Inter2_and_Domaine2,Inter1,
449                                    Resultat1,Resultat2,EpsNul);
450
451   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
452   //Calcule_Toutes_Transitions(NbResultats,
453   //                         Resultat1,Resultat2,
454   //                         TheImpTool,
455   //                         TheImpCurveDomain,
456   //                         TheParCurve,
457   //                         TheParCurveDomain); 
458   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
459   //~~~ Fonction Calcule_Toutes_Transitions Repportee ici pour cause ~~~~~
460   //~~~~~       D acces aux methodes Protected APPEND
461   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
462   {
463     IntRes2d_Position Pos1,Pos2;
464     IntRes2d_Transition Trans1,Trans2;
465     gp_Vec2d Tan1,Tan2,Norm1,Norm2;
466     gp_Pnt2d Pt1_on1,Pt2_on1,Pt1_on2,Pt2_on2;
467     Standard_Real Param1_on1,Param2_on1,Param1_on2,Param2_on2;
468     
469     Standard_Real Dist_Mini_ImpCurve=EPSNUL;
470     Standard_Real Tolerance_Angulaire=Dist_Mini_ImpCurve; 
471     
472     
473     for(Standard_Integer i=1; i<=NbResultats ; i+=2) {
474       Standard_Integer ip1=i+1;
475       Standard_Boolean OnlyOnePoint=Standard_False;
476       
477       Param1_on1=Resultat1.Value(i);
478       Param1_on2=Resultat2.Value(i);
479       Param2_on1=Resultat1.Value(ip1);
480       Param2_on2=Resultat2.Value(ip1);
481
482       Pt1_on1=TheImpTool.Value(Param1_on1);
483       Pt2_on1=TheImpTool.Value(Param2_on1);
484       Pt1_on2=ParTool::Value(TheParCurve,Param1_on2);
485       Pt2_on2=ParTool::Value(TheParCurve,Param2_on2);
486       
487       if(!TheImpCurveDomain.IsClosed()) { 
488         if( Pt1_on1.Distance(Pt2_on1) <= Dist_Mini_ImpCurve ) {
489           if( Pt1_on2.Distance(Pt2_on2) <= Dist_Mini_ImpCurve ) {
490             OnlyOnePoint=Standard_True;
491           }
492         }
493       }  
494
495       Param1_on1=IntImpParGen::NormalizeOnDomain(Param1_on1,TheImpCurveDomain);
496       Param1_on2=IntImpParGen::NormalizeOnDomain(Param1_on2,TheParCurveDomain);
497
498       TheImpTool.D2(Param1_on1,Pt1_on1,Tan1,Norm1);
499       ParTool::D2(TheParCurve,Param1_on2,Pt1_on2,Tan2,Norm2);
500       
501       IntImpParGen::DeterminePosition(Pos1,TheImpCurveDomain,Pt1_on1,Param1_on1);
502       IntImpParGen::DeterminePosition(Pos2,TheParCurveDomain,Pt1_on2,Param1_on2);
503
504       if(Pos1==IntRes2d_End)  EndOnImp  = Standard_True;
505       else if(Pos1==IntRes2d_Head) HeadOnImp = Standard_True;
506       if(Pos2==IntRes2d_End)  EndOnPar  = Standard_True;
507       else if(Pos2==IntRes2d_Head) HeadOnPar = Standard_True;
508       
509
510       IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
511                            Pos2,Tan2,Norm2,Trans2,
512                            Tolerance_Angulaire);
513       
514       //============== Detection du cas : L intersection est en bout
515       //==============  sur les 2 domaines
516       
517       if(Pos1!=IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
518         Standard_Real m=0.5*(Pt1_on1.X() + Pt1_on2.X());
519         Pt1_on1.SetX(m);
520         m=0.5*(Pt1_on1.Y() + Pt1_on2.Y());
521         Pt1_on1.SetY(m);
522       }
523
524       IntRes2d_IntersectionPoint new_p1(Pt1_on1
525                                         ,Param1_on1,Param1_on2
526                                         ,Trans1,Trans2
527                                         ,ReversedParameters());
528       if(!OnlyOnePoint) {
529         IntRes2d_IntersectionPoint new_p2;
530
531         Param2_on1=IntImpParGen::NormalizeOnDomain(Param2_on1,TheImpCurveDomain);
532         Param2_on2=IntImpParGen::NormalizeOnDomain(Param2_on2,TheParCurveDomain);
533
534         TheImpTool.D2(Param2_on1,Pt2_on1,Tan1,Norm1);
535         ParTool::D2(TheParCurve,Param2_on2,Pt2_on2,Tan2,Norm2);
536         
537         IntImpParGen::DeterminePosition(Pos1,TheImpCurveDomain,Pt2_on1,Param2_on1);
538         IntImpParGen::DeterminePosition(Pos2,TheParCurveDomain,Pt2_on2,Param2_on2);
539         
540         if(Pos1==IntRes2d_End)  EndOnImp  = Standard_True;
541         else if(Pos1==IntRes2d_Head) HeadOnImp = Standard_True;
542         if(Pos2==IntRes2d_End)  EndOnPar  = Standard_True;
543         else if(Pos2==IntRes2d_Head) HeadOnPar = Standard_True;
544
545         IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
546                                           Pos2,Tan2,Norm2,Trans2,
547                                           Tolerance_Angulaire);
548         
549         
550         //============== Detection du cas : L intersection est en bout
551         //==============  sur les 2 domaines 
552         
553         if(Pos1!=IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
554           Standard_Real m=0.5*(Pt2_on1.X() + Pt2_on2.X() );
555           Pt2_on1.SetX(m);
556           m=0.5*(Pt2_on1.Y() + Pt2_on2.Y());
557           Pt2_on1.SetY(m);
558         }
559
560         new_p2.SetValues(Pt2_on1,Param2_on1,Param2_on2
561                          ,Trans1,Trans2
562                          ,ReversedParameters());
563
564         Standard_Boolean segopposite=((Tan1.Dot(Tan2) < 0.0)? 
565                                       Standard_True : Standard_False);
566         
567         IntRes2d_IntersectionSegment new_seg(new_p1,new_p2
568                                              ,segopposite
569                                              ,ReversedParameters());
570         Append(new_seg);
571       }
572       else {
573         Insert(new_p1); 
574       }
575     }
576   } //~~~~~~~~~~~~  Fin du corps de la fonction Calc...Transitions~~~~~~~~~~
577   
578   //-------------------------------------------
579   //-- On teste les points en bouts solutions
580   //-- 
581   if(!HeadOnImp && TheImpCurveDomain.HasFirstPoint()) { 
582     if(!HeadOnPar) { 
583       if(TheImpCurveDomain.FirstPoint().Distance(TheParCurveDomain.FirstPoint()) 
584          <= Max(TheImpCurveDomain.FirstTolerance(),TheParCurveDomain.FirstTolerance())) { 
585         param1 = TheImpCurveDomain.FirstParameter();
586         param2 = TheParCurveDomain.FirstParameter();
587         TheImpTool.D2(param1,pt1,Tan1,Norm1);
588         ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
589         IntImpParGen::DetermineTransition(IntRes2d_Head,Tan1,Norm1,Trans1,
590                                           IntRes2d_Head,Tan2,Norm2,Trans2,
591                                           Tolerance_Angulaire);
592         IntRes2d_IntersectionPoint IP(TheImpCurveDomain.FirstPoint(),
593                                       param1,param2,
594                                       Trans1,Trans2,
595                                       ReversedParameters());
596         Insert(IP);
597       }
598     }
599     if(!EndOnPar) { 
600       if(TheImpCurveDomain.FirstPoint().Distance(TheParCurveDomain.LastPoint()) 
601          <= Max(TheImpCurveDomain.FirstTolerance(),TheParCurveDomain.LastTolerance())) { 
602         param1 = TheImpCurveDomain.FirstParameter();
603         param2 = TheParCurveDomain.LastParameter();
604         TheImpTool.D2(param1,pt1,Tan1,Norm1);
605         ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
606         IntImpParGen::DetermineTransition(IntRes2d_Head,Tan1,Norm1,Trans1,
607                                           IntRes2d_End ,Tan2,Norm2,Trans2,
608                                           Tolerance_Angulaire);
609         IntRes2d_IntersectionPoint IP(TheImpCurveDomain.FirstPoint(),
610                                       param1,param2,
611                                       Trans1,Trans2,
612                                       ReversedParameters());
613         Insert(IP);
614       }
615     }
616   }
617   
618   if(!EndOnImp && TheImpCurveDomain.HasLastPoint()) { 
619     if(!HeadOnPar) { 
620       if(TheImpCurveDomain.LastPoint().Distance(TheParCurveDomain.FirstPoint()) 
621          <= Max(TheImpCurveDomain.LastTolerance(),TheParCurveDomain.FirstTolerance())) {
622         param1 = TheImpCurveDomain.LastParameter();
623         param2 = TheParCurveDomain.FirstParameter();
624         TheImpTool.D2(param1,pt1,Tan1,Norm1);
625         ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
626         IntImpParGen::DetermineTransition(IntRes2d_End,Tan1,Norm1,Trans1,
627                                           IntRes2d_Head,Tan2,Norm2,Trans2,
628                                           Tolerance_Angulaire);
629         IntRes2d_IntersectionPoint IP(TheImpCurveDomain.LastPoint(),
630                                       param1,param2,
631                                       Trans1,Trans2,
632                                       ReversedParameters());
633         Insert(IP);
634       }
635     }
636     if(!EndOnPar) { 
637       if(TheImpCurveDomain.LastPoint().Distance(TheParCurveDomain.LastPoint()) 
638          <= Max(TheImpCurveDomain.LastTolerance(),TheParCurveDomain.LastTolerance())) {
639         param1 = TheImpCurveDomain.LastParameter();
640         param2 = TheParCurveDomain.LastParameter();
641         TheImpTool.D2(param1,pt1,Tan1,Norm1);
642         ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
643         IntImpParGen::DetermineTransition(IntRes2d_End,Tan1,Norm1,Trans1,
644                                           IntRes2d_End,Tan2,Norm2,Trans2,
645                                           Tolerance_Angulaire);
646         IntRes2d_IntersectionPoint IP(TheImpCurveDomain.LastPoint(),
647                                       param1,param2,
648                                       Trans1,Trans2,
649                                       ReversedParameters());
650         Insert(IP);
651       }
652     }
653   }
654   done=Standard_True; 
655 }
656
657
658
659
660
661
662 Standard_Real IntImpParGen_Intersector::FindU(const Standard_Real parameter
663                                               ,gp_Pnt2d& point
664                                               ,const ParCurve& TheParCurve
665                                               ,const ImpTool& TheImpTool) const 
666 {
667   point=ParTool::Value(TheParCurve,parameter);
668   return(TheImpTool.FindParameter(point));
669 }
670
671 Standard_Real IntImpParGen_Intersector::FindV(const Standard_Real parameter
672                   ,gp_Pnt2d& point
673                   ,const ImpTool& TheImpTool
674                   ,const ParCurve& TheParCurve
675                   ,const IntRes2d_Domain& TheParCurveDomain
676                   ,const Standard_Real V0
677                   ,const Standard_Real V1
678                   ,const Standard_Real Tolerance) const 
679 {
680   point=TheImpTool.Value(parameter);
681   if(TheParCurveDomain.IsClosed()) {
682     Standard_Real V = ProjectOnPCurveTool::FindParameter(TheParCurve,
683                                                          point,
684                                                          Tolerance);
685     return(IntImpParGen::NormalizeOnDomain(V,TheParCurveDomain));
686   }
687   else {
688     Standard_Real VV0 = V0;
689     Standard_Real VV1 = V1;
690     if(V1<V0) { VV0 = V1; VV1 = V0; } 
691     //-- ??????????????????????????????????????????????????????????????????????
692     //-- Modif le 15 Septembre 1992 : On Teste le parametre retourne 
693     //--??????????????????????????????????????????????????????????????????????
694     Standard_Real X = ProjectOnPCurveTool::FindParameter(TheParCurve,
695                                                          point,
696                                                          VV0,VV1,Tolerance);
697     if(X>VV1) X=VV1; else if(X<VV0) X=VV0;
698     return(X);
699   }
700 }