0026747: Some constructors of gp_Parab2d class contain redundant parameters
[occt.git] / src / gce / gce_MakeCirc2d.cxx
CommitLineData
b311480e 1// Created on: 1992-09-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
42cf5bc1 17
18#include <ElCLib.hxx>
19#include <gce_MakeCirc2d.hxx>
7fd59977 20#include <gp.hxx>
42cf5bc1 21#include <gp_Ax2d.hxx>
22#include <gp_Ax22d.hxx>
23#include <gp_Circ2d.hxx>
7fd59977 24#include <gp_Lin2d.hxx>
42cf5bc1 25#include <gp_Pnt2d.hxx>
7fd59977 26#include <IntAna2d_AnaIntersection.hxx>
27#include <IntAna2d_IntPoint.hxx>
42cf5bc1 28#include <StdFail_NotDone.hxx>
7fd59977 29
30//=========================================================================
31// Creation d un cercle 2d de gp passant par trois points. +
32// Trois cas de figures : +
33// 1/ Les trois points sont confondus. +
34// ----------------------------------- +
35// Le resultat est le cercle centre en Point1 de rayon zero. +
36// 2/ Deux des trois points sont confondus. +
37// ---------------------------------------- +
38// On cree la mediatrice a deux points non confondus ainsi que la +
39// droite passant par ces deux points. +
40// La solution a pour centre l intersection de ces deux droite et +
41// pour rayon la distance entre ce centre et l un des trois points. +
42// 3/ Les trois points sont distinct. +
43// ---------------------------------- +
44// On cree la mediatrice a P1P2 ainsi que la mediatrice a P1P3. +
45// La solution a pour centre l intersection de ces deux droite et +
46// pour rayon la distance entre ce centre et l un des trois points. +
47//=========================================================================
7fd59977 48gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& P1 ,
49 const gp_Pnt2d& P2 ,
50 const gp_Pnt2d& P3 )
51{
52 gp_Dir2d dirx(1.0,0.0);
53
54//=========================================================================
55// Traitement. +
56//=========================================================================
57
58 Standard_Real dist1 = P1.Distance(P2);
59 Standard_Real dist2 = P1.Distance(P3);
60 Standard_Real dist3 = P2.Distance(P3);
61
62 if ((dist1<gp::Resolution()) && (dist2<gp::Resolution()) &&
63 (dist3<gp::Resolution())) {
64 TheCirc2d = gp_Circ2d(gp_Ax2d(P1,dirx),0.0);
65 TheError = gce_Done;
66 }
67 else {
68 gp_Lin2d L1;
69 gp_Lin2d L2;
70 Standard_Real x1,y1,x2,y2,x3,y3;
71 P1.Coord(x1,y1);
72 P2.Coord(x2,y2);
73 P3.Coord(x3,y3);
74 if (dist1 >= RealEpsilon()) {
75 L1 = gp_Lin2d(gp_Pnt2d((P1.XY()+P2.XY())/2.0),
76 gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
77 }
78 if (dist2 >= RealEpsilon()) {
79 L2 = gp_Lin2d(gp_Pnt2d((P1.XY()+P3.XY())/2.0),
80 gp_Dir2d(P1.Y()-P3.Y(),P3.X()-P1.X()));
81 }
82 if (dist2 <= RealEpsilon()) {
83 L2 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
84 }
85 else if (dist1 <= RealEpsilon()) {
86 L1 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P3.Y(),P3.X()-P1.X()));
87 }
88 else if (dist3 <= RealEpsilon()) {
89 L2 = gp_Lin2d(P1,gp_Dir2d(P1.Y()-P2.Y(),P2.X()-P1.X()));
90 }
91 IntAna2d_AnaIntersection Intp(L1,L2);
92 if (Intp.IsDone()) {
93 if (!Intp.IsEmpty()) {
94 gp_Pnt2d pInt(Intp.Point(1).Value());
95 dist1 = P1.Distance(pInt);
96 dist2 = P2.Distance(pInt);
97 dist3 = P3.Distance(pInt);
98 Standard_Real xc,yc;
99 pInt.Coord(xc,yc);
100 gp_Dir2d d1(x1-xc,y1-yc);
101 gp_Dir2d d2(xc-x3,yc-y3);
102 TheCirc2d = gp_Circ2d(gp_Ax22d(pInt,d1,d2),(dist1+dist2+dist3)/3.);
103 Standard_Real Alpha1 = ElCLib::Parameter(TheCirc2d,P1);
104 Standard_Real Alpha2 = ElCLib::Parameter(TheCirc2d,P2);
105 Standard_Real Alpha3 = ElCLib::Parameter(TheCirc2d,P3);
106 if (!((Alpha1 <= Alpha2) && (Alpha2 <= Alpha3))) {
107 TheCirc2d.Reverse();
108 }
109 TheError = gce_Done;
110 }
111 }
112 else {
113 TheError = gce_IntersectionError;
114 }
115 }
116}
117
118//==========================================================================
119// Creation d un gp_Circ2d par son Axe <XAxis> et son rayon <Radius>. +
120//==========================================================================
121
122gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax2d& XAxis ,
123 const Standard_Real Radius ,
124 const Standard_Boolean Sense )
125{
126 if (Radius >= 0.) {
127 TheCirc2d = gp_Circ2d(XAxis,Radius,Sense);
128 TheError = gce_Done;
129 }
130 else {
131 TheError = gce_NegativeRadius;
132 }
133}
134
135//==========================================================================
136// Creation d un gp_Circ2d par son Repere <Axis> et son rayon <Radius>. +
137//==========================================================================
138
139gce_MakeCirc2d::gce_MakeCirc2d(const gp_Ax22d& Axis ,
140 const Standard_Real Radius )
141{
142 if (Radius >= 0.) {
143 TheCirc2d = gp_Circ2d(Axis,Radius);
144 TheError = gce_Done;
145 }
146 else {
147 TheError = gce_NegativeRadius;
148 }
149}
150
151//==========================================================================
152// Creation d un gp_Circ2d par son centre <Center> et son rayon +
153// <Radius>. +
154//==========================================================================
155
156gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center ,
157 const Standard_Real Radius ,
158 const Standard_Boolean Sense )
159{
160 if (Radius >= 0.) {
161 TheCirc2d = gp_Circ2d(gp_Ax2d(Center,gp_Dir2d(1.0,0.0)),Radius,Sense);
162 TheError = gce_Done;
163 }
164 else {
165 TheError = gce_NegativeRadius;
166 }
167}
168
169//==========================================================================
170// Creation d un gp_Circ2d par son centre <Center> et un point de sa +
171// circonference <Point>. +
172//==========================================================================
173
174gce_MakeCirc2d::gce_MakeCirc2d(const gp_Pnt2d& Center ,
175 const gp_Pnt2d& Point ,
176 const Standard_Boolean Sense )
177{
178 TheCirc2d = gp_Circ2d(gp_Ax2d(Center,gp_Dir2d(1.0,0.0)),
179 Point.Distance(Center),Sense);
180 TheError = gce_Done;
181}
182
183//==========================================================================
184// Creation d un cercle <TheCirc2d> concentrique a <Circ> passant par le +
185// point <Point1>. +
186//==========================================================================
187
188gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ ,
189 const gp_Pnt2d& Point )
190{
191 TheCirc2d = gp_Circ2d(Circ.Axis(),Point.Distance(Circ.Location()));
192 TheError = gce_Done;
193}
194
195//==========================================================================
196// Creation d un cercle <TheCirc2d> concentrique a <Circ> a une distance +
197// <Dist1>. +
198//==========================================================================
199
200gce_MakeCirc2d::gce_MakeCirc2d(const gp_Circ2d& Circ ,
201 const Standard_Real Dist1 )
202{
203 TheCirc2d = gp_Circ2d(Circ.Axis(),Abs(Circ.Radius()+Dist1));
204 TheError = gce_Done;
205}
206
207const gp_Circ2d& gce_MakeCirc2d::Value() const
208{
82fc327c 209 StdFail_NotDone_Raise_if(TheError != gce_Done,"");
7fd59977 210 return TheCirc2d;
211}
212
213const gp_Circ2d& gce_MakeCirc2d::Operator() const
214{
215 return Value();
216}
217
218gce_MakeCirc2d::operator gp_Circ2d() const
219{
220 return Value();
221}
222
223