0032137: Coding Rules - merge redundant .lxx files into header files within Package gp
[occt.git] / src / gp / gp_Parab2d.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_Parab2d_HeaderFile
16 #define _gp_Parab2d_HeaderFile
17
18 #include <gp_Ax22d.hxx>
19 #include <gp_Ax2d.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <Standard_ConstructionError.hxx>
22
23 //! Describes a parabola in the plane (2D space).
24 //! A parabola is defined by its focal length (that is, the
25 //! distance between its focus and apex) and positioned in
26 //! the plane with a coordinate system (a gp_Ax22d object) where:
27 //! -   the origin of the coordinate system is on the apex of
28 //! the parabola, and
29 //! -   the "X Axis" of the coordinate system is the axis of
30 //! symmetry; the parabola is on the positive side of this axis.
31 //! This coordinate system is the "local coordinate system"
32 //! of the parabola. Its orientation (direct or indirect sense)
33 //! gives an implicit orientation to the parabola.
34 //! In this coordinate system, the equation for the parabola is:
35 //! @code
36 //! Y**2 = (2*P) * X.
37 //! @endcode
38 //! where P, referred to as the parameter of the parabola, is
39 //! the distance between the focus and the directrix (P is
40 //! twice the focal length).
41 //! See Also
42 //! GCE2d_MakeParab2d which provides functions for
43 //! more complex parabola constructions
44 //! Geom2d_Parabola which provides additional functions
45 //! for constructing parabolas and works, in particular, with
46 //! the parametric equations of parabolas
47 class gp_Parab2d 
48 {
49 public:
50
51   DEFINE_STANDARD_ALLOC
52
53   //! Creates an indefinite parabola.
54   gp_Parab2d()
55   : focalLength (RealLast())
56   {}
57
58   //! Creates a parabola with its vertex point, its axis of symmetry
59   //! ("XAxis") and its focal length.
60   //! The sense of parametrization is given by theSense. If theSense == TRUE
61   //! (by default) then right-handed coordinate system is used,
62   //! otherwise - left-handed.
63   //! Warnings : It is possible to have FocalLength = 0. In this case,
64   //! the parabola looks like a line, which is parallel to the symmetry-axis.
65   //! Raises ConstructionError if FocalLength < 0.0
66   gp_Parab2d (const gp_Ax2d& theMirrorAxis,
67               const Standard_Real theFocalLength,
68               const Standard_Boolean theSense = Standard_True)
69   : focalLength (theFocalLength)
70   {
71     pos = gp_Ax22d (theMirrorAxis, theSense);
72     Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0");
73   }
74
75   //! Creates a parabola with its vertex point, its axis of symmetry
76   //! ("XAxis"), correspond Y-axis and its focal length.
77   //! Warnings : It is possible to have FocalLength = 0. In this case,
78   //! the parabola looks like a line, which is parallel to the symmetry-axis.
79   //! Raises ConstructionError if Focal < 0.0
80   gp_Parab2d (const gp_Ax22d& theAxes, const Standard_Real theFocalLength)
81   : pos (theAxes),
82     focalLength (theFocalLength)
83   {
84     Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0");
85   }
86
87   //! Creates a parabola with the directrix and the focus point.
88   //! Y-axis of the parabola (in User Coordinate System - UCS) is
89   //! the direction of theDirectrix. X-axis always directs from theDirectrix
90   //! to theFocus point and always comes through theFocus.
91   //! Apex of the parabola is a middle point between the theFocus and the
92   //! intersection point of theDirectrix and the X-axis.
93   //! Warnings : It is possible to have FocalLength = 0 (when theFocus lies
94   //! in theDirectrix). In this case, X-direction of the parabola is defined 
95   //! by theSense parameter. If theSense == TRUE (by default) then right-handed
96   //! coordinate system is used, otherwise - left-handed. Result parabola will look
97   //! like a line, which is perpendicular to the directrix.
98   Standard_EXPORT gp_Parab2d (const gp_Ax2d& theDirectrix,
99                               const gp_Pnt2d& theFocus,
100                               const Standard_Boolean theSense = Standard_True);
101
102   //! Changes the focal distance of the parabola
103   //! Warnings : It is possible to have theFocal = 0.
104   //! Raises ConstructionError if theFocal < 0.0
105   void SetFocal (const Standard_Real theFocal)
106   {
107     Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab2d::SetFocal() - focal length should be >= 0");
108     focalLength = theFocal;
109   }
110
111   //! Changes the "Location" point of the parabola. It is the
112   //! vertex of the parabola.
113   void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); }
114
115   //! Modifies this parabola, by redefining its local coordinate system so that
116   //! its origin and "X Direction" become those of the axis
117   //! MA. The "Y Direction" of the local coordinate system is
118   //! then recomputed. The orientation of the local
119   //! coordinate system is not modified.
120   void SetMirrorAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); }
121
122   //! Changes the local coordinate system of the parabola.
123   //! The "Location" point of A becomes the vertex of the parabola.
124   void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); }
125
126   //! Computes the coefficients of the implicit equation of the parabola
127   //! (in WCS - World Coordinate System).
128   //! @code
129   //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0.
130   //! @endcode
131   Standard_EXPORT void Coefficients (Standard_Real& theA, Standard_Real& theB,
132                                      Standard_Real& theC, Standard_Real& theD,
133                                      Standard_Real& theE, Standard_Real& theF) const;
134
135   //! Computes the directrix of the parabola.
136   //! The directrix is:
137   //! -   a line parallel to the "Y Direction" of the local
138   //! coordinate system of this parabola, and
139   //! -   located on the negative side of the axis of symmetry,
140   //! at a distance from the apex which is equal to the focal  length of this parabola.
141   //! The directrix is returned as an axis (a gp_Ax2d object),
142   //! the origin of which is situated on the "X Axis" of this parabola.
143   gp_Ax2d Directrix() const;
144
145   //! Returns the distance between the vertex and the focus
146   //! of the parabola.
147   Standard_Real Focal() const { return focalLength; }
148
149   //! Returns the focus of the parabola.
150   gp_Pnt2d Focus() const
151   {
152     return gp_Pnt2d (pos.Location().X() + focalLength * pos.XDirection().X(),
153                      pos.Location().Y() + focalLength * pos.XDirection().Y());
154   }
155
156   //! Returns the vertex of the parabola.
157   gp_Pnt2d Location() const { return pos.Location(); }
158
159   //! Returns the symmetry axis of the parabola.
160   //! The "Location" point of this axis is the vertex of the parabola.
161   gp_Ax2d MirrorAxis() const { return pos.XAxis(); }
162
163   //! Returns the local coordinate system of the parabola.
164   //! The "Location" point of this axis is the vertex of the parabola.
165   gp_Ax22d Axis() const { return pos; }
166
167   //! Returns the distance between the focus and the
168   //! directrix of the parabola.
169   Standard_Real Parameter() const { return 2.0 * focalLength; }
170
171   void Reverse()
172   {
173     gp_Dir2d aTemp = pos.YDirection();
174     aTemp.Reverse();
175     pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp));
176   }
177
178   //! Reverses the orientation of the local coordinate system
179   //! of this parabola (the "Y Direction" is reversed).
180   //! Therefore, the implicit orientation of this parabola is reversed.
181   //! Note:
182   //! -   Reverse assigns the result to this parabola, while
183   //! -   Reversed creates a new one.
184   Standard_NODISCARD gp_Parab2d Reversed() const;
185
186   //! Returns true if the local coordinate system is direct
187   //! and false in the other case.
188   Standard_Boolean IsDirect() const
189   {
190     return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
191   }
192
193   Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
194
195   //! Performs the symmetrical transformation of a parabola with respect
196   //! to the point theP which is the center of the symmetry
197   Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Pnt2d& theP) const;
198
199   Standard_EXPORT void Mirror (const gp_Ax2d& theA);
200
201   //! Performs the symmetrical transformation of a parabola with respect
202   //! to an axis placement which is the axis of the symmetry.
203   Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Ax2d& theA) const;
204
205   void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate (theP, theAng); }
206
207   //! Rotates a parabola. theP is the center of the rotation.
208   //! theAng is the angular value of the rotation in radians.
209   Standard_NODISCARD gp_Parab2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
210   {
211     gp_Parab2d aPrb = *this;
212     aPrb.pos.Rotate (theP, theAng);
213     return aPrb;
214   }
215
216   void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
217
218   //! Scales a parabola. theS is the scaling value.
219   //! If theS is negative the direction of the symmetry axis
220   //! "XAxis" is reversed and the direction of the "YAxis" too.
221   Standard_NODISCARD gp_Parab2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const;
222
223   void Transform (const gp_Trsf2d& theT);
224
225   //! Transforms an parabola with the transformation theT from class Trsf2d.
226   Standard_NODISCARD gp_Parab2d Transformed (const gp_Trsf2d& theT) const;
227
228   void Translate (const gp_Vec2d& theV) { pos.Translate (theV); }
229
230   //! Translates a parabola in the direction of the vectorthe theV.
231   //! The magnitude of the translation is the vector's magnitude.
232   Standard_NODISCARD gp_Parab2d Translated (const gp_Vec2d& theV) const
233   {
234     gp_Parab2d aPrb = *this;
235     aPrb.pos.Translate (theV);
236     return aPrb;
237   }
238
239   void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); }
240
241   //! Translates a parabola from the point theP1 to the point theP2.
242   Standard_NODISCARD gp_Parab2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
243   {
244     gp_Parab2d aPrb = *this;
245     aPrb.pos.Translate (theP1, theP2);
246     return aPrb;
247   }
248
249 private:
250
251   gp_Ax22d pos;
252   Standard_Real focalLength;
253
254 };
255
256 //=======================================================================
257 //function : Directrix
258 // purpose :
259 //=======================================================================
260 inline gp_Ax2d gp_Parab2d::Directrix() const
261 {
262   gp_Pnt2d aP (pos.Location().X() - focalLength * pos.XDirection().X(),
263                pos.Location().Y() - focalLength * pos.XDirection().Y());
264   gp_Dir2d aV (pos.YDirection());
265   return gp_Ax2d (aP, aV);
266 }
267
268 //=======================================================================
269 //function : Reversed
270 // purpose :
271 //=======================================================================
272 inline gp_Parab2d gp_Parab2d::Reversed() const
273 {
274   gp_Parab2d aP = *this;
275   gp_Dir2d aTemp = pos.YDirection();
276   aTemp.Reverse();
277   aP.pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp));
278   return aP;
279 }
280
281 //=======================================================================
282 //function : Scale
283 // purpose :
284 //=======================================================================
285 inline void gp_Parab2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
286 {
287   focalLength *= theS;
288   if (focalLength < 0)
289   {
290     focalLength = -focalLength;
291   }
292   pos.Scale (theP, theS);
293 }
294
295 //=======================================================================
296 //function : Scaled
297 // purpose :
298 //=======================================================================
299 inline gp_Parab2d gp_Parab2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
300 {
301   gp_Parab2d aPrb = *this;
302   aPrb.focalLength *= theS;
303   if (aPrb.focalLength < 0)
304   {
305     aPrb.focalLength = -aPrb.focalLength;
306   }
307   aPrb.pos.Scale (theP, theS);
308   return aPrb;
309 }
310
311 //=======================================================================
312 //function : Transform
313 // purpose :
314 //=======================================================================
315 inline void gp_Parab2d::Transform (const gp_Trsf2d& theT)
316 {
317   focalLength *= theT.ScaleFactor();
318   if (focalLength < 0)
319   {
320     focalLength = -focalLength;
321   }
322   pos.Transform (theT);
323 }
324
325 //=======================================================================
326 //function : Transformed
327 // purpose :
328 //=======================================================================
329 inline gp_Parab2d gp_Parab2d::Transformed (const gp_Trsf2d& theT) const
330 {
331   gp_Parab2d aPrb = *this;
332   aPrb.focalLength *= theT.ScaleFactor();
333   if (aPrb.focalLength < 0)
334   {
335     aPrb.focalLength = -aPrb.focalLength;
336   }
337   aPrb.pos.Transform (theT);
338   return aPrb;
339 }
340
341 #endif // _gp_Parab2d_HeaderFile