0024624: Lost word in license statement in source files
[occt.git] / src / GC / GC_MakeArcOfCircle.cxx
1 // Created on: 1992-10-02
2 // Created by: Remi GILET
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 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 #include <GC_MakeArcOfCircle.ixx>
18 #include <gce_MakeCirc.hxx>
19 #include <gce_MakeLin.hxx>
20 #include <Geom_Circle.hxx>
21 #include <Extrema_ExtElC.hxx>
22 #include <Extrema_POnCurv.hxx>
23 #include <StdFail_NotDone.hxx>
24 #include <ElCLib.hxx>
25
26 //=======================================================================
27 //function : GC_MakeArcOfCircle
28 //purpose  : 
29 //=======================================================================
30 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt&  P1 ,
31                                        const gp_Pnt&  P2 ,
32                                        const gp_Pnt&  P3  ) 
33 {
34   Standard_Boolean sense;
35   //
36   gce_MakeCirc Cir(P1, P2, P3);
37   TheError = Cir.Status();
38   if (TheError == gce_Done) {
39     Standard_Real Alpha1, Alpha3;//,Alpha2
40     gp_Circ C(Cir.Value());
41     //modified by NIZNHY-PKV Thu Mar  3 10:53:02 2005f
42     //Alpha1 is always =0.
43     //Alpha1 = ElCLib::Parameter(C,P1);
44     //Alpha2 = ElCLib::Parameter(C,P2);
45     //Alpha3 = ElCLib::Parameter(C,P3);
46     //
47     //if (Alpha2 >= Alpha1 && Alpha2 <= Alpha3) sense = Standard_True;
48     //else if (Alpha1 <= Alpha3 && Alpha2 >= Alpha3 ) sense = Standard_True;
49     //else sense = Standard_False;
50     // 
51     Alpha1=0.;
52     Alpha3 = ElCLib::Parameter(C, P3);
53     sense=Standard_True;
54     //modified by NIZNHY-PKV Thu Mar  3 10:53:04 2005t
55     
56     Handle(Geom_Circle) Circ = new Geom_Circle(C);
57     TheArc= new Geom_TrimmedCurve(Circ, Alpha1, Alpha3, sense);
58   }
59 }
60
61 //=======================================================================
62 //function : GC_MakeArcOfCircle
63 //purpose  : 
64 //=======================================================================
65 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Pnt& P1 ,
66                                        const gp_Vec& V  ,
67                                        const gp_Pnt& P2 )
68 {
69   gp_Circ cir;
70   gce_MakeLin Corde(P1,P2);
71   TheError = Corde.Status();
72   if (TheError == gce_Done) {
73     gp_Lin corde(Corde.Value());
74     gp_Dir dir(corde.Direction());
75     gp_Dir dbid(V);
76     gp_Dir Daxe(dbid^dir);
77     gp_Dir Dir1(Daxe^dir);
78     gp_Lin bis(gp_Pnt((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.,
79                       (P1.Z()+P2.Z())/2.),Dir1);
80     gp_Dir d(dbid^Daxe);
81     gp_Lin norm(P1,d);
82     Standard_Real Tol = 0.000000001;
83     Extrema_ExtElC distmin(bis,norm,Tol);
84     if (!distmin.IsDone()) { TheError = gce_IntersectionError; }
85     else {
86       Standard_Integer nbext = distmin.NbExt();
87       if (nbext == 0) { TheError = gce_IntersectionError; }
88       else {
89         Standard_Real TheDist = RealLast();
90         gp_Pnt pInt,pon1,pon2;
91         Standard_Integer i = 1;
92         Extrema_POnCurv Pon1,Pon2;
93         while (i<=nbext) {
94           if (distmin.SquareDistance(i)<TheDist) {
95             TheDist = distmin.SquareDistance(i);
96             distmin.Points(i,Pon1,Pon2);
97             pon1 = Pon1.Value();
98             pon2 = Pon2.Value();
99             pInt = gp_Pnt((pon1.XYZ()+pon2.XYZ())/2.);
100           }
101           i++;
102         }
103         Standard_Real Rad = (pInt.Distance(P1)+pInt.Distance(P2))/2.;
104         cir = gp_Circ(gp_Ax2(pInt,Daxe,d),Rad);
105         Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
106         Standard_Real Alpha3 = ElCLib::Parameter(cir,P2);
107         Handle(Geom_Circle) Circ = new Geom_Circle(cir);
108         TheArc= new Geom_TrimmedCurve(Circ,Alpha1,Alpha3, Standard_True);
109       }
110     }
111   }
112 }
113 //=======================================================================
114 //function : GC_MakeArcOfCircle
115 //purpose  : 
116 //=======================================================================
117 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
118                                        const gp_Pnt&  P1     ,
119                                        const gp_Pnt&  P2     ,
120                                        const Standard_Boolean  Sense  ) 
121 {
122   Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
123   Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
124   Handle(Geom_Circle) C = new Geom_Circle(Circ);
125   TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
126   TheError = gce_Done;
127 }
128 //=======================================================================
129 //function : GC_MakeArcOfCircle
130 //purpose  : 
131 //=======================================================================
132 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
133                                        const gp_Pnt&  P      ,
134                                        const Standard_Real     Alpha  ,
135                                        const Standard_Boolean  Sense  ) 
136 {
137   Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
138   Handle(Geom_Circle) C = new Geom_Circle(Circ);
139   TheArc= new Geom_TrimmedCurve(C,Alphafirst,Alpha,Sense);
140   TheError = gce_Done;
141 }
142 //=======================================================================
143 //function : GC_MakeArcOfCircle
144 //purpose  : 
145 //=======================================================================
146 GC_MakeArcOfCircle::GC_MakeArcOfCircle(const gp_Circ& Circ   ,
147                                          const Standard_Real     Alpha1 ,
148                                          const Standard_Real     Alpha2 ,
149                                          const Standard_Boolean  Sense  ) 
150 {
151   Handle(Geom_Circle) C = new Geom_Circle(Circ);
152   TheArc= new Geom_TrimmedCurve(C,Alpha1,Alpha2,Sense);
153   TheError = gce_Done;
154 }
155 //=======================================================================
156 //function : Value
157 //purpose  : 
158 //=======================================================================
159 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Value() const
160
161   StdFail_NotDone_Raise_if(!TheError == gce_Done,"");
162   return TheArc;
163 }
164 //=======================================================================
165 //function : Operator
166 //purpose  : 
167 //=======================================================================
168 const Handle(Geom_TrimmedCurve)& GC_MakeArcOfCircle::Operator() const 
169 {
170   return Value();
171 }
172 //=======================================================================
173 //function : operator
174 //purpose  : 
175 //=======================================================================
176 GC_MakeArcOfCircle::operator Handle(Geom_TrimmedCurve) () const
177 {
178   return Value();
179 }
180