0032137: Coding Rules - merge redundant .lxx files into header files within Package gp
[occt.git] / src / gp / gp_Cylinder.hxx
1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _gp_Cylinder_HeaderFile
16 #define _gp_Cylinder_HeaderFile
17
18 #include <gp_Ax1.hxx>
19 #include <gp_Ax3.hxx>
20
21 //! Describes an infinite cylindrical surface.
22 //! A cylinder is defined by its radius and positioned in space
23 //! with a coordinate system (a gp_Ax3 object), the "main
24 //! Axis" of which is the axis of the cylinder. This coordinate
25 //! system is the "local coordinate system" of the cylinder.
26 //! Note: when a gp_Cylinder cylinder is converted into a
27 //! Geom_CylindricalSurface cylinder, some implicit
28 //! properties of its local coordinate system are used explicitly:
29 //! -   its origin, "X Direction", "Y Direction" and "main
30 //! Direction" are used directly to define the parametric
31 //! directions on the cylinder and the origin of the parameters,
32 //! -   its implicit orientation (right-handed or left-handed)
33 //! gives an orientation (direct or indirect) to the
34 //! Geom_CylindricalSurface cylinder.
35 //! See Also
36 //! gce_MakeCylinder which provides functions for more
37 //! complex cylinder constructions
38 //! Geom_CylindricalSurface which provides additional
39 //! functions for constructing cylinders and works, in
40 //! particular, with the parametric equations of cylinders gp_Ax3
41 class gp_Cylinder 
42 {
43 public:
44
45   DEFINE_STANDARD_ALLOC
46
47   //! Creates a indefinite cylinder.
48   gp_Cylinder() { radius = RealLast(); }
49
50   //! Creates a cylinder of radius Radius, whose axis is the "main
51   //! Axis" of theA3. theA3 is the local coordinate system of the cylinder.   Raises ConstructionErrord if theRadius < 0.0
52   gp_Cylinder (const gp_Ax3& theA3, const Standard_Real theRadius)
53   : pos (theA3),
54     radius (theRadius)
55   {
56     Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Cylinder() - radius should be positive number");
57   }
58
59   //! Changes the symmetry axis of the cylinder. Raises ConstructionError if the direction of theA1 is parallel to the "XDirection"
60   //! of the coordinate system of the cylinder.
61   void SetAxis (const gp_Ax1& theA1)  { pos.SetAxis (theA1); }
62
63   //! Changes the location of the surface.
64   void SetLocation (const gp_Pnt& theLoc)  { pos.SetLocation (theLoc); }
65
66   //! Change the local coordinate system of the surface.
67   void SetPosition (const gp_Ax3& theA3) { pos = theA3; }
68
69   //! Modifies the radius of this cylinder.
70   //! Exceptions
71   //! Standard_ConstructionError if theR is negative.
72   void SetRadius (const Standard_Real theR)
73   {
74     Standard_ConstructionError_Raise_if (theR < 0.0, "gp_Cylinder::SetRadius() - radius should be positive number");
75     radius = theR;
76   }
77
78   //! Reverses the   U   parametrization of   the cylinder
79   //! reversing the YAxis.
80   void UReverse() { pos.YReverse(); }
81
82   //! Reverses the   V   parametrization of   the  plane
83   //! reversing the Axis.
84   void VReverse() { pos.ZReverse(); }
85
86   //! Returns true if the local coordinate system of this cylinder is right-handed.
87   Standard_Boolean Direct() const { return pos.Direct(); }
88
89   //! Returns the symmetry axis of the cylinder.
90   const gp_Ax1& Axis() const { return pos.Axis(); }
91
92   //! Computes the coefficients of the implicit equation of the quadric
93   //! in the absolute cartesian coordinate system :
94   //! theA1.X**2 + theA2.Y**2 + theA3.Z**2 + 2.(theB1.X.Y + theB2.X.Z + theB3.Y.Z) +
95   //! 2.(theC1.X + theC2.Y + theC3.Z) + theD = 0.0
96   Standard_EXPORT void Coefficients (Standard_Real& theA1, Standard_Real& theA2, Standard_Real& theA3,
97                                      Standard_Real& theB1, Standard_Real& theB2, Standard_Real& theB3,
98                                      Standard_Real& theC1, Standard_Real& theC2, Standard_Real& theC3, Standard_Real& theD) const;
99
100   //! Returns the "Location" point of the cylinder.
101   const gp_Pnt& Location() const { return pos.Location(); }
102
103   //! Returns the local coordinate system of the cylinder.
104   const gp_Ax3& Position() const { return pos; }
105
106   //! Returns the radius of the cylinder.
107   Standard_Real Radius() const { return radius; }
108
109   //! Returns the axis X of the cylinder.
110   gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); }
111
112   //! Returns the axis Y of the cylinder.
113   gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); }
114
115   Standard_EXPORT void Mirror (const gp_Pnt& theP);
116
117   //! Performs the symmetrical transformation of a cylinder
118   //! with respect to the point theP which is the center of the
119   //! symmetry.
120   Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Pnt& theP) const;
121
122   Standard_EXPORT void Mirror (const gp_Ax1& theA1);
123
124   //! Performs the symmetrical transformation of a cylinder with
125   //! respect to an axis placement which is the axis of the
126   //! symmetry.
127   Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Ax1& theA1) const;
128
129   Standard_EXPORT void Mirror (const gp_Ax2& theA2);
130
131   //! Performs the symmetrical transformation of a cylinder with respect
132   //! to a plane. The axis placement theA2 locates the plane of the
133   //! of the symmetry : (Location, XDirection, YDirection).
134   Standard_NODISCARD Standard_EXPORT gp_Cylinder Mirrored (const gp_Ax2& theA2) const;
135
136   void Rotate (const gp_Ax1& theA1, const Standard_Real theAng)  { pos.Rotate (theA1, theAng); }
137
138   //! Rotates a cylinder. theA1 is the axis of the rotation.
139   //! theAng is the angular value of the rotation in radians.
140   Standard_NODISCARD gp_Cylinder Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const
141   {
142     gp_Cylinder aCyl = *this;
143     aCyl.pos.Rotate (theA1, theAng);
144     return aCyl;
145   }
146
147   void Scale (const gp_Pnt& theP, const Standard_Real theS);
148
149   //! Scales a cylinder. theS is the scaling value.
150   //! The absolute value of theS is used to scale the cylinder
151   Standard_NODISCARD gp_Cylinder Scaled (const gp_Pnt& theP, const Standard_Real theS) const;
152
153   void Transform (const gp_Trsf& theT);
154
155   //! Transforms a cylinder with the transformation theT from class Trsf.
156   Standard_NODISCARD gp_Cylinder Transformed (const gp_Trsf& theT) const;
157
158   void Translate (const gp_Vec& theV)  { pos.Translate (theV); }
159
160   //! Translates a cylinder in the direction of the vector theV.
161   //! The magnitude of the translation is the vector's magnitude.
162   Standard_NODISCARD gp_Cylinder Translated (const gp_Vec& theV) const
163   {
164     gp_Cylinder aCyl = *this;
165     aCyl.pos.Translate (theV);
166     return aCyl;
167   }
168
169   void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2)  { pos.Translate (theP1, theP2); }
170
171   //! Translates a cylinder from the point theP1 to the point theP2.
172   Standard_NODISCARD gp_Cylinder Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const
173   {
174     gp_Cylinder aCyl = *this;
175     aCyl.pos.Translate (theP1, theP2);
176     return aCyl;
177   }
178
179 private:
180
181   gp_Ax3 pos;
182   Standard_Real radius;
183
184 };
185
186 // =======================================================================
187 // function : Scale
188 // purpose  :
189 // =======================================================================
190 inline void gp_Cylinder::Scale (const gp_Pnt& theP, const Standard_Real theS)
191 {
192   pos.Scale (theP, theS);
193   radius *= theS;
194   if (radius < 0)
195   {
196     radius = -radius;
197   }
198 }
199
200 // =======================================================================
201 // function : Scaled
202 // purpose  :
203 // =======================================================================
204 inline gp_Cylinder gp_Cylinder::Scaled (const gp_Pnt& theP, const Standard_Real theS) const
205 {
206   gp_Cylinder aCyl = *this;
207   aCyl.pos.Scale (theP, theS);
208   aCyl.radius *= theS;
209   if (aCyl.radius < 0)
210   {
211     aCyl.radius = -aCyl.radius;
212   }
213   return aCyl;
214 }
215
216 // =======================================================================
217 // function : Transform
218 // purpose  :
219 // =======================================================================
220 inline void gp_Cylinder::Transform (const gp_Trsf& theT)
221 {
222   pos.Transform (theT);
223   radius *= theT.ScaleFactor();
224   if (radius < 0)
225   {
226     radius = -radius;
227   }
228 }
229
230 // =======================================================================
231 // function : Transformed
232 // purpose  :
233 // =======================================================================
234 inline gp_Cylinder gp_Cylinder::Transformed (const gp_Trsf& theT) const
235 {
236   gp_Cylinder aCyl = *this;
237   aCyl.pos.Transform (theT);
238   aCyl.radius *= theT.ScaleFactor();
239   if (aCyl.radius < 0)
240   {
241     aCyl.radius = -aCyl.radius;
242   }
243   return aCyl;
244 }
245
246 #endif // _gp_Cylinder_HeaderFile