Test for 0022778: Bug in BRepMesh
[occt.git] / src / IntAna2d / IntAna2d_AnaIntersection_8.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 //============================================ IntAna2d_AnaIntersection_8.cxx
20 //============================================================================
21 #include <IntAna2d_AnaIntersection.jxx>
22
23 #include <IntAna2d_Outils.hxx>
24
25 // -----------------------------------------------------------------
26 // ------ Verification de la validite des points obtenus  ----------
27 // --- Methode a implementer dans les autres routines si on constate
28 // --- des problemes d'instabilite numerique sur
29 // ---      * la construction des polynomes en t (t:parametre)
30 // ---      * la resolution du polynome
31 // ---      * le retour : parametre t -> point d'intersection
32 // --- Probleme : A partir de quelle Tolerance un point n'est
33 // ---            plus un point de la courbe. (f(x,y)=1e-10 ??)
34 // ---            ne donne pas d'info. sur la dist. du pt a la courbe
35 // -----------------------------------------------------------------
36 // ------ Methode non implementee pour les autres Intersections
37 // --- Si un probleme est constate : Dupliquer le code entre les
38 // --- commentaires VERIF-VALID
39 // -----------------------------------------------------------------
40
41 void IntAna2d_AnaIntersection::Perform(const gp_Hypr2d& H,
42                                        const IntAna2d_Conic& Conic)
43   {
44     Standard_Boolean HIsDirect = H.IsDirect();
45     Standard_Real A,B,C,D,E,F;
46     Standard_Real px0,px1,px2,px3,px4;
47     Standard_Real minor_radius=H.MinorRadius();
48     Standard_Real major_radius=H.MajorRadius();
49     Standard_Integer i;
50     Standard_Real tx,ty,S;
51
52     done = Standard_False;
53     nbp = 0;
54     para = Standard_False;
55     iden = Standard_False;
56     empt = Standard_False;
57
58     gp_Ax2d Axe_rep(H.XAxis());
59     Conic.Coefficients(A,B,C,D,E,F);
60     Conic.NewCoefficients(A,B,C,D,E,F,Axe_rep);
61   
62     Standard_Real A_major_radiusP2=A*major_radius*major_radius;
63     Standard_Real B_minor_radiusP2=B*minor_radius*minor_radius;
64     Standard_Real C_2_major_minor_radius=C*2.0*major_radius*minor_radius;
65
66     // Parametre : t avec x=MajorRadius*Ch(t)  y=:minorRadius*Sh(t)
67     // Le polynome est reecrit en Exp(t)
68     // Suivent les Coeffs du polynome P multiplie par 4*Exp(t)^2
69
70     px0=A_major_radiusP2 - C_2_major_minor_radius + B_minor_radiusP2;
71     px1=4.0*(D*major_radius-E*minor_radius);
72     px2=2.0*(A_major_radiusP2 + 2.0*F - B_minor_radiusP2);
73     px3=4.0*(D*major_radius+E*minor_radius);
74     px4=A_major_radiusP2 + C_2_major_minor_radius + B_minor_radiusP2;
75
76     MyDirectPolynomialRoots Sol(px4,px3,px2,px1,px0);
77
78     if(!Sol.IsDone()) {
79       //-- cout<<" Done = False ds IntAna2d_AnaIntersection_8.cxx "<<endl;
80       done=Standard_False;
81       return;
82     }
83     else { 
84       if(Sol.InfiniteRoots()) { 
85         iden=Standard_True;
86         done=Standard_True;
87         return;
88       }
89       // On a X=(CosH(t)*major_radius)/2 , Y=(SinH(t)*minor_radius)/2
90       //      la Resolution est en S=Exp(t)
91       nbp=Sol.NbSolutions();
92       Standard_Integer nb_sol_valides=0;
93       for(i=1;i<=nbp;i++) {
94         S=Sol.Value(i);
95         if(S>RealEpsilon()) {
96           tx=0.5*major_radius*(S+1/S);  
97           ty=0.5*minor_radius*(S-1/S);
98
99           //--- Est-on sur la bonne branche de l'Hyperbole
100           //--------------- VERIF-VALIDITE-INTERSECTION ----------
101           //--- On Suppose que l'ecart sur la courbe1 est nul
102           //--- (le point a ete obtenu par parametrage)
103           //--- ??? la tolerance a ete fixee a 1e-10 ?????????????
104
105 #if 0 
106           Standard_Real ecart_sur_courbe2;
107           ecart_sur_courbe2=Conic.Value(tx,ty);
108           if(ecart_sur_courbe2<=1e-10 && ecart_sur_courbe2>=-1e-10) {
109             nb_sol_valides++;
110             Coord_Ancien_Repere(tx,ty,Axe_rep);
111             lpnt[nb_sol_valides-1].SetValue(tx,ty,Log(S));
112           }
113 #else 
114         
115           nb_sol_valides++;
116           Coord_Ancien_Repere(tx,ty,Axe_rep);
117           S = Log(S);
118           if(!HIsDirect)
119             S = -S;
120           lpnt[nb_sol_valides-1].SetValue(tx,ty,S);
121 #endif
122         }   
123       }
124       nbp=nb_sol_valides;
125       Traitement_Points_Confondus(nbp,lpnt);
126     }
127     done=Standard_True;
128   }
129
130
131
132
133