0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / GccAna / GccAna_Circ2d2TanRad_5.cxx
1 // Created on: 1991-09-24
2 // Created by: Remi GILET
3 // Copyright (c) 1991-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 under
9 // the terms of the GNU Lesser General Public License 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
18 #include <ElCLib.hxx>
19 #include <GccAna_Circ2d2TanRad.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedCirc.hxx>
22 #include <GccEnt_QualifiedLin.hxx>
23 #include <gp_Ax2d.hxx>
24 #include <gp_Circ2d.hxx>
25 #include <gp_Lin2d.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <IntAna2d_AnaIntersection.hxx>
28 #include <IntAna2d_IntPoint.hxx>
29 #include <Standard_NegativeValue.hxx>
30 #include <Standard_OutOfRange.hxx>
31 #include <StdFail_NotDone.hxx>
32
33 //   Circle passing by two points of given radius.
34 //   ==============================================
35 //==============================================================================
36 //   Solution of the equation of second degree showing that the center of the  +
37 //   circle is equidistant from two points.                                    +
38 //==============================================================================
39 GccAna_Circ2d2TanRad::
40    GccAna_Circ2d2TanRad (const gp_Pnt2d&             Point1     ,
41                          const gp_Pnt2d&             Point2     ,
42                          const Standard_Real         Radius     ,
43                          const Standard_Real         Tolerance  ):
44    qualifier1(1,2) ,
45    qualifier2(1,2),
46    TheSame1(1,2)   ,
47    TheSame2(1,2)   ,
48    cirsol(1,2)     ,
49    pnttg1sol(1,2)  ,
50    pnttg2sol(1,2)  ,
51    par1sol(1,2)    ,
52    par2sol(1,2)    ,
53    pararg1(1,2)    ,
54    pararg2(1,2)    
55 {
56
57   gp_Dir2d dirx(1.0,0.0);
58   Standard_Real Tol = Abs(Tolerance);
59   NbrSol = 0;
60   WellDone = Standard_False;
61   if (Radius < 0.0) { throw Standard_NegativeValue(); }
62   else {
63     if (Point1.Distance(Point2)-Radius*2.0 > Tol) { WellDone = Standard_True; }
64     else {
65       if (Point1.Distance(Point2)-Radius*2.0 >0.0) {
66         WellDone = Standard_True;
67         NbrSol = 1;
68         gp_Ax2d axe(gp_Pnt2d(0.5*(Point1.XY()+Point2.XY())),dirx);
69         cirsol(1) = gp_Circ2d(axe,Radius);
70 //      =================================
71         qualifier1(1) = GccEnt_noqualifier;
72         qualifier2(1) = GccEnt_noqualifier;
73         TheSame1(1) = 0;
74         TheSame2(1) = 0;
75         pnttg1sol(1) = Point1;
76         pnttg2sol(1) = Point2;
77       }
78       else {
79         gp_Circ2d C1(gp_Ax2d(Point1,dirx),Radius);
80         gp_Circ2d C2(gp_Ax2d(Point2,dirx),Radius);
81         IntAna2d_AnaIntersection Intp(C1,C2);
82         if (Intp.IsDone()) {
83           if (!Intp.IsEmpty()) {
84             for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
85               NbrSol++;
86               gp_Pnt2d Center(Intp.Point(i).Value());
87               cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
88 //            =======================================================
89               qualifier1(NbrSol) = GccEnt_noqualifier;
90               qualifier2(NbrSol) = GccEnt_noqualifier;
91               TheSame1(NbrSol) = 0;
92               TheSame2(NbrSol) = 0;
93               pnttg1sol(NbrSol) = Point1;
94               pnttg2sol(NbrSol) = Point2;
95             }
96           }
97           WellDone = Standard_True;
98         }
99       }
100     }
101   }
102   for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
103     pararg1(i) = 0.;
104     pararg2(i) = 0.;
105     par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i));
106     par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i));
107   }
108 }
109