0024816: Tool for upgrading OCCT and dependent code
[occt.git] / src / GCE2d / GCE2d_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
18 #include <ElCLib.hxx>
19 #include <GCE2d_MakeArcOfCircle.hxx>
20 #include <gce_MakeCirc2d.hxx>
21 #include <gce_MakeLin2d.hxx>
22 #include <Geom2d_Circle.hxx>
23 #include <Geom2d_TrimmedCurve.hxx>
24 #include <gp_Circ2d.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <IntAna2d_AnaIntersection.hxx>
28 #include <StdFail_NotDone.hxx>
29
30 GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Pnt2d&        P1     ,
31                                              const gp_Pnt2d&        P2     ,
32                                              const gp_Pnt2d&        P3     ) 
33 {
34   gce_MakeCirc2d Cir = gce_MakeCirc2d(P1,P2,P3);
35   TheError = Cir.Status();
36   if (TheError == gce_Done) {
37     gp_Circ2d C(Cir.Value());
38     Standard_Real Alpha1 = ElCLib::Parameter(C,P1);
39     Standard_Real Alpha2 = ElCLib::Parameter(C,P3);
40     Handle(Geom2d_Circle) Circ = new Geom2d_Circle(C);
41     TheArc= new Geom2d_TrimmedCurve(Circ,Alpha1,Alpha2,Standard_True);
42   }
43 }
44
45 GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Pnt2d& P1 ,
46                                              const gp_Vec2d& V  ,
47                                              const gp_Pnt2d& P2 )
48 {
49   Standard_Boolean Sense;
50   gp_Circ2d cir;
51   gp_Lin2d corde = gce_MakeLin2d(P1,P2);
52   gp_Dir2d dir(corde.Direction());
53   gp_Lin2d bis(gp_Pnt2d((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.),
54                gp_Dir2d(-dir.Y(),dir.X()));
55   gp_Lin2d norm(P1,gp_Dir2d(-V.Y(),V.X()));
56   TheError = gce_ConfusedPoints;
57
58   IntAna2d_AnaIntersection Intp(bis,norm);
59
60   if (Intp.IsDone())
61     {
62       if (!Intp.IsEmpty())
63         {
64           gp_Pnt2d center(Intp.Point(1).Value());
65           Standard_Real rad = (center.Distance(P1)+center.Distance(P2))/2.;
66           cir = gce_MakeCirc2d(center,rad);
67           TheError = gce_Done;
68         }
69     }
70
71   if (TheError == gce_Done) {
72     Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
73     Standard_Real Alpha2 = ElCLib::Parameter(cir,P2);
74     Handle(Geom2d_Circle) Circ = new Geom2d_Circle(cir);
75     gp_Vec2d vv(dir);
76     Standard_Real cross = V^vv;
77     Sense = cross > 0.;
78     TheArc= new Geom2d_TrimmedCurve(Circ,Alpha1,Alpha2,Sense);
79   }
80 }
81
82 GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Circ2d&        Circ   ,
83                                              const gp_Pnt2d&         P1     ,
84                                              const gp_Pnt2d&         P2     ,
85                                              const Standard_Boolean  Sense  ) 
86 {
87   Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
88   Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
89   Handle(Geom2d_Circle) C = new Geom2d_Circle(Circ);
90   TheArc= new Geom2d_TrimmedCurve(C,Alpha1,Alpha2,Sense);
91   TheError = gce_Done;
92 }
93
94 GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Circ2d&       Circ  ,
95                                              const gp_Pnt2d&        P     ,
96                                              const Standard_Real    Alpha ,
97                                              const Standard_Boolean Sense ) 
98 {
99   Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
100   Handle(Geom2d_Circle) C = new Geom2d_Circle(Circ);
101   TheArc= new Geom2d_TrimmedCurve(C,Alphafirst,Alpha,Sense);
102   TheError = gce_Done;
103 }
104
105 GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Circ2d&       Circ   ,
106                                              const Standard_Real    Alpha1 ,
107                                              const Standard_Real    Alpha2 ,
108                                              const Standard_Boolean Sense  ) 
109 {
110   Handle(Geom2d_Circle) C = new Geom2d_Circle(Circ);
111   TheArc= new Geom2d_TrimmedCurve(C,Alpha1,Alpha2,Sense);
112   TheError = gce_Done;
113 }
114
115 const Handle(Geom2d_TrimmedCurve)& GCE2d_MakeArcOfCircle::Value() const
116
117   StdFail_NotDone_Raise_if(TheError != gce_Done,"");
118   return TheArc;
119 }