0024893: CLang warnings -Wlogical-not-parentheses for gce_Done comparisons
[occt.git] / src / gce / gce_MakeCylinder.cxx
1 // Created on: 1992-09-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 <gce_MakeCylinder.ixx>
18 #include <StdFail_NotDone.hxx>
19 #include <gp.hxx>
20 #include <gp_Lin.hxx>
21
22 //=========================================================================
23 //  Constructions d un cylindre de gp par son Ax2 A2 et son rayon         +
24 //  Radius.                                                               +
25 //=========================================================================
26
27 gce_MakeCylinder::gce_MakeCylinder(const gp_Ax2&       A2     ,
28                                    const Standard_Real Radius ) 
29 {
30   if (Radius < 0.0) { TheError = gce_NegativeRadius; }
31   else {
32     TheCylinder = gp_Cylinder(A2,Radius);
33     TheError = gce_Done;
34   }
35 }
36
37 //=========================================================================
38 //  Constructions d un cylindre de gp par son axe Axis et son rayon       +
39 //  Radius.                                                               +
40 //=========================================================================
41
42 gce_MakeCylinder::gce_MakeCylinder(const gp_Ax1&       Axis   ,
43                                    const Standard_Real Radius ) 
44 {
45   if (Radius < 0.0) { TheError = gce_NegativeRadius; }
46   else {
47     gp_Dir D(Axis.Direction());
48     gp_Dir Direc;
49     Standard_Real x = D.X();
50     Standard_Real y = D.Y();
51     Standard_Real z = D.Z();
52     if (Abs(x) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); }
53     else if (Abs(y) > gp::Resolution()) { Direc = gp_Dir(-y,x,0.0); }
54     else if (Abs(z) > gp::Resolution()) { Direc = gp_Dir(0.0,-z,y); }
55     TheCylinder = gp_Cylinder(gp_Ax2(Axis.Location(),D,Direc),Radius);
56     TheError = gce_Done;
57   }
58 }
59
60 //=========================================================================
61 //  Constructions d un cylindre de gp par un cercle.                      +
62 //=========================================================================
63
64 gce_MakeCylinder::gce_MakeCylinder(const gp_Circ& Circ ) 
65 {
66   TheCylinder = gp_Cylinder(Circ.Position(),Circ.Radius());
67   TheError = gce_Done;
68 }
69
70 //=========================================================================
71 //  Constructions d un cylindre de gp par trois points P1, P2, P3.        +
72 //  P1 et P2 donnent l axe du cylindre, la distance de P3 a l axe donne   +
73 //  le rayon du cylindre.                                                 +
74 //=========================================================================
75
76 gce_MakeCylinder::gce_MakeCylinder(const gp_Pnt& P1 ,
77                                    const gp_Pnt& P2 ,
78                                    const gp_Pnt& P3 ) 
79 {
80   if (P1.Distance(P2) < gp::Resolution()) { TheError = gce_ConfusedPoints; }
81   else {
82     gp_Dir D1(P2.XYZ()-P1.XYZ());
83     gp_Dir D2;
84     Standard_Real x = D1.X();
85     Standard_Real y = D1.Y();
86     Standard_Real z = D1.Z();
87     if (Abs(x) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
88     else if (Abs(y) > gp::Resolution()) { D2 = gp_Dir(-y,x,0.0); }
89     else if (Abs(z) > gp::Resolution()) { D2 = gp_Dir(0.0,-z,y); }
90     TheCylinder = gp_Cylinder(gp_Ax2(P1,D1,D2 ),gp_Lin(P1,D1).Distance(P3));
91     TheError = gce_Done;
92   }
93 }
94
95 //=========================================================================
96 //  Constructions d un cylindre de gp concentrique a un autre cylindre de +
97 //  gp a une distance Dist.                                               +
98 //=========================================================================
99
100 gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder&  Cyl  ,
101                                    const Standard_Real Dist ) 
102 {
103   Standard_Real Rad = Cyl.Radius()+Dist;
104   if (Rad < 0.) { TheError = gce_NegativeRadius; }
105   else {
106     TheCylinder = gp_Cylinder(Cyl);
107     TheCylinder.SetRadius(Rad);
108     TheError = gce_Done;
109   }
110 }
111
112 //=========================================================================
113 //  Constructions d un cylindre de gp concentrique a un autre cylindre de +
114 //  gp passant par le point P.                                            +
115 //=========================================================================
116
117 gce_MakeCylinder::gce_MakeCylinder(const gp_Cylinder& Cyl ,
118                                    const gp_Pnt&      P   ) 
119 {
120   gp_Lin L(Cyl.Axis());
121   Standard_Real Rad = L.Distance(P);
122   TheCylinder = gp_Cylinder(Cyl);
123   TheCylinder.SetRadius(Rad);
124   TheError = gce_Done;
125 }
126
127 const gp_Cylinder& gce_MakeCylinder::Value() const
128
129   StdFail_NotDone_Raise_if(TheError != gce_Done,"");
130   return TheCylinder;
131 }
132
133 const gp_Cylinder& gce_MakeCylinder::Operator() const 
134 {
135   return Value();
136 }
137
138 gce_MakeCylinder::operator gp_Cylinder() const
139 {
140   return Value();
141 }
142
143
144
145
146