0024023: Revamp the OCCT Handle -- GC
[occt.git] / src / GCE2d / GCE2d_MakeArcOfCircle.cxx
CommitLineData
b311480e 1// Created on: 1992-10-02
2// Created by: Remi GILET
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <GCE2d_MakeArcOfCircle.ixx>
18#include <gp_Vec2d.hxx>
19#include <Geom2d_Circle.hxx>
20#include <gce_MakeCirc2d.hxx>
21#include <gce_MakeLin2d.hxx>
22#include <ElCLib.hxx>
23#include <StdFail_NotDone.hxx>
24#include <IntAna2d_AnaIntersection.hxx>
25
26
27GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Pnt2d& P1 ,
28 const gp_Pnt2d& P2 ,
29 const gp_Pnt2d& P3 )
30{
31 gce_MakeCirc2d Cir = gce_MakeCirc2d(P1,P2,P3);
32 TheError = Cir.Status();
33 if (TheError == gce_Done) {
34 gp_Circ2d C(Cir.Value());
35 Standard_Real Alpha1 = ElCLib::Parameter(C,P1);
36 Standard_Real Alpha2 = ElCLib::Parameter(C,P3);
37 Handle(Geom2d_Circle) Circ = new Geom2d_Circle(C);
38 TheArc= new Geom2d_TrimmedCurve(Circ,Alpha1,Alpha2,Standard_True);
39 }
40}
41
42GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Pnt2d& P1 ,
43 const gp_Vec2d& V ,
44 const gp_Pnt2d& P2 )
45{
46 Standard_Boolean Sense;
47 gp_Circ2d cir;
48 gp_Lin2d corde = gce_MakeLin2d(P1,P2);
49 gp_Dir2d dir(corde.Direction());
50 gp_Lin2d bis(gp_Pnt2d((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.),
51 gp_Dir2d(-dir.Y(),dir.X()));
52 gp_Lin2d norm(P1,gp_Dir2d(-V.Y(),V.X()));
53 TheError = gce_ConfusedPoints;
54
55 IntAna2d_AnaIntersection Intp(bis,norm);
56
57 if (Intp.IsDone())
58 {
59 if (!Intp.IsEmpty())
60 {
61 gp_Pnt2d center(Intp.Point(1).Value());
62 Standard_Real rad = (center.Distance(P1)+center.Distance(P2))/2.;
63 cir = gce_MakeCirc2d(center,rad);
64 TheError = gce_Done;
65 }
66 }
67
68 if (TheError == gce_Done) {
69 Standard_Real Alpha1 = ElCLib::Parameter(cir,P1);
70 Standard_Real Alpha2 = ElCLib::Parameter(cir,P2);
71 Handle(Geom2d_Circle) Circ = new Geom2d_Circle(cir);
72 gp_Vec2d vv(dir);
73 Standard_Real cross = V^vv;
74 Sense = cross > 0.;
75 TheArc= new Geom2d_TrimmedCurve(Circ,Alpha1,Alpha2,Sense);
76 }
77}
78
79GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Circ2d& Circ ,
80 const gp_Pnt2d& P1 ,
81 const gp_Pnt2d& P2 ,
82 const Standard_Boolean Sense )
83{
84 Standard_Real Alpha1 = ElCLib::Parameter(Circ,P1);
85 Standard_Real Alpha2 = ElCLib::Parameter(Circ,P2);
86 Handle(Geom2d_Circle) C = new Geom2d_Circle(Circ);
87 TheArc= new Geom2d_TrimmedCurve(C,Alpha1,Alpha2,Sense);
88 TheError = gce_Done;
89}
90
91GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Circ2d& Circ ,
92 const gp_Pnt2d& P ,
93 const Standard_Real Alpha ,
94 const Standard_Boolean Sense )
95{
96 Standard_Real Alphafirst = ElCLib::Parameter(Circ,P);
97 Handle(Geom2d_Circle) C = new Geom2d_Circle(Circ);
98 TheArc= new Geom2d_TrimmedCurve(C,Alphafirst,Alpha,Sense);
99 TheError = gce_Done;
100}
101
102GCE2d_MakeArcOfCircle::GCE2d_MakeArcOfCircle(const gp_Circ2d& Circ ,
103 const Standard_Real Alpha1 ,
104 const Standard_Real Alpha2 ,
105 const Standard_Boolean Sense )
106{
107 Handle(Geom2d_Circle) C = new Geom2d_Circle(Circ);
108 TheArc= new Geom2d_TrimmedCurve(C,Alpha1,Alpha2,Sense);
109 TheError = gce_Done;
110}
111
112const Handle(Geom2d_TrimmedCurve)& GCE2d_MakeArcOfCircle::Value() const
113{
82fc327c 114 StdFail_NotDone_Raise_if(TheError != gce_Done,"");
7fd59977 115 return TheArc;
116}