0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / gp / gp_Ax22d.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_Ax22d_HeaderFile
16 #define _gp_Ax22d_HeaderFile
17
18 #include <gp_Ax2d.hxx>
19 #include <gp_Dir2d.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <gp_Trsf2d.hxx>
22 #include <gp_Vec2d.hxx>
23
24 //! Describes a coordinate system in a plane (2D space).
25 //! A coordinate system is defined by:
26 //! -   its origin (also referred to as its "Location point"), and
27 //! -   two orthogonal unit vectors, respectively, called the "X
28 //! Direction" and the "Y Direction".
29 //! A gp_Ax22d may be right-handed ("direct sense") or
30 //! left-handed ("inverse" or "indirect sense").
31 //! You use a gp_Ax22d to:
32 //! - describe 2D geometric entities, in particular to position
33 //! them. The local coordinate system of a geometric
34 //! entity serves for the same purpose as the STEP
35 //! function "axis placement two axes", or
36 //! -   define geometric transformations.
37 //! Note: we refer to the "X Axis" and "Y Axis" as the axes having:
38 //! -   the origin of the coordinate system as their origin, and
39 //! -   the unit vectors "X Direction" and "Y Direction",
40 //! respectively, as their unit vectors.
41 class gp_Ax22d 
42 {
43 public:
44
45   DEFINE_STANDARD_ALLOC
46
47   //! Creates an object representing the reference
48   //! coordinate system (OXY).
49   gp_Ax22d() : vydir (0., 1.)
50   // vxdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir(1, 0)
51   {}
52
53   //! Creates a coordinate system with origin theP and where:
54   //! -   theVx is the "X Direction", and
55   //! -   the "Y Direction" is orthogonal to theVx and
56   //! oriented so that the cross products theVx^"Y
57   //! Direction" and theVx^theVy have the same sign.
58   //! Raises ConstructionError if theVx and theVy are parallel (same or opposite orientation).
59   gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theVx, const gp_Dir2d& theVy)
60   : point (theP),
61     vydir (theVy),
62     vxdir (theVx)
63   {
64     Standard_Real aValue = theVx.Crossed (theVy);
65     if (aValue >= 0.0)
66     {
67       vydir.SetCoord (-vxdir.Y(), vxdir.X());
68     }
69     else
70     {
71       vydir.SetCoord (vxdir.Y(), -vxdir.X());
72     }
73   }
74
75   //! Creates -   a coordinate system with origin theP and "X Direction"
76   //! theV, which is:
77   //! -   right-handed if theIsSense is true (default value), or
78   //! -   left-handed if theIsSense is false
79   gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theV, const Standard_Boolean theIsSense = Standard_True)
80   : point (theP),
81     vxdir (theV)
82   {
83     if (theIsSense)
84     {
85       vydir.SetCoord (-theV.Y(), theV.X());
86     }
87     else
88     {
89       vydir.SetCoord (theV.Y(), -theV.X());
90     }
91   }
92
93   //! Creates -   a coordinate system where its origin is the origin of
94   //! theA and its "X Direction" is the unit vector of theA, which   is:
95   //! -   right-handed if theIsSense is true (default value), or
96   //! -   left-handed if theIsSense is false.
97   gp_Ax22d (const gp_Ax2d& theA, const Standard_Boolean theIsSense = Standard_True)
98   : point (theA.Location()),
99     vxdir (theA.Direction())
100   {
101     if (theIsSense)
102     {
103       vydir.SetCoord (-vxdir.Y(), vxdir.X());
104     }
105     else
106     {
107       vydir.SetCoord (vxdir.Y(), -vxdir.X());
108     }
109   }
110
111   //! Assigns the origin and the two unit vectors of the
112   //! coordinate system theA1 to this coordinate system.
113   void SetAxis (const gp_Ax22d& theA1)
114   {
115     point = theA1.Location();
116     vxdir = theA1.XDirection();
117     vydir = theA1.YDirection();
118   }
119
120   //! Changes the XAxis and YAxis ("Location" point and "Direction")
121   //! of <me>.
122   //! The "YDirection" is recomputed in the same sense as before.
123   void SetXAxis (const gp_Ax2d& theA1);
124
125   //! Changes the XAxis and YAxis ("Location" point and "Direction") of <me>.
126   //! The "XDirection" is recomputed in the same sense as before.
127   void SetYAxis (const gp_Ax2d& theA1);
128
129   //! Changes the "Location" point (origin) of <me>.
130   void SetLocation (const gp_Pnt2d& theP) { point = theP; }
131
132   //! Assigns theVx to the "X Direction"  of
133   //! this coordinate system. The other unit vector of this
134   //! coordinate system is recomputed, normal to theVx ,
135   //! without modifying the orientation (right-handed or
136   //! left-handed) of this coordinate system.
137   void SetXDirection (const gp_Dir2d& theVx);
138
139   //! Assignsr theVy to the  "Y Direction" of
140   //! this coordinate system. The other unit vector of this
141   //! coordinate system is recomputed, normal to theVy,
142   //! without modifying the orientation (right-handed or
143   //! left-handed) of this coordinate system.
144   void SetYDirection (const gp_Dir2d& theVy);
145
146   //! Returns an axis, for which
147   //! -   the origin is that of this coordinate system, and
148   //! -   the unit vector is either the "X Direction"  of this coordinate system.
149   //! Note: the result is the "X Axis" of this coordinate system.
150   gp_Ax2d XAxis() const { return gp_Ax2d (point, vxdir); }
151
152   //! Returns an axis, for which
153   //! -   the origin is that of this coordinate system, and
154   //! - the unit vector is either the  "Y Direction" of this coordinate system.
155   //! Note: the result is the "Y Axis" of this coordinate system.
156   gp_Ax2d YAxis() const { return gp_Ax2d (point, vydir); }
157
158   //! Returns the "Location" point (origin) of <me>.
159   const gp_Pnt2d& Location() const { return point; }
160
161   //! Returns the "XDirection" of <me>.
162   const gp_Dir2d& XDirection() const { return vxdir; }
163
164   //! Returns the "YDirection" of <me>.
165   const gp_Dir2d& YDirection() const { return vydir; }
166
167   Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
168
169   //! Performs the symmetrical transformation of an axis
170   //! placement with respect to the point theP which is the
171   //! center of the symmetry.
172   //! Warnings :
173   //! The main direction of the axis placement is not changed.
174   //! The "XDirection" and the "YDirection" are reversed.
175   //! So the axis placement stay right handed.
176   Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Pnt2d& theP) const;
177
178   Standard_EXPORT void Mirror (const gp_Ax2d& theA);
179
180   //! Performs the symmetrical transformation of an axis
181   //! placement with respect to an axis placement which
182   //! is the axis of the symmetry.
183   //! The transformation is performed on the "Location"
184   //! point, on the "XDirection" and "YDirection".
185   //! The resulting main "Direction" is the cross product between
186   //! the "XDirection" and the "YDirection" after transformation.
187   Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Ax2d& theA) const;
188
189   void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng);
190
191   //! Rotates an axis placement. <theA1> is the axis of the
192   //! rotation . theAng is the angular value of the rotation
193   //! in radians.
194   Standard_NODISCARD gp_Ax22d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
195   {
196     gp_Ax22d aTemp = *this;
197     aTemp.Rotate (theP, theAng);
198     return aTemp;
199   }
200
201   void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
202
203   //! Applies a scaling transformation on the axis placement.
204   //! The "Location" point of the axisplacement is modified.
205   //! Warnings :
206   //! If the scale <theS> is negative :
207   //! . the main direction of the axis placement is not changed.
208   //! . The "XDirection" and the "YDirection" are reversed.
209   //! So the axis placement stay right handed.
210   Standard_NODISCARD gp_Ax22d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
211   {
212     gp_Ax22d aTemp = *this;
213     aTemp.Scale (theP, theS);
214     return aTemp;
215   }
216
217   void Transform (const gp_Trsf2d& theT);
218
219   //! Transforms an axis placement with a Trsf.
220   //! The "Location" point, the "XDirection" and the
221   //! "YDirection" are transformed with theT.  The resulting
222   //! main "Direction" of <me> is the cross product between
223   //! the "XDirection" and the "YDirection" after transformation.
224   Standard_NODISCARD gp_Ax22d Transformed (const gp_Trsf2d& theT) const
225   {
226     gp_Ax22d aTemp = *this;
227     aTemp.Transform (theT);
228     return aTemp;
229   }
230
231   void Translate (const gp_Vec2d& theV) { point.Translate (theV); }
232
233   //! Translates an axis plaxement in the direction of the vector
234   //! <theV>. The magnitude of the translation is the vector's magnitude.
235   Standard_NODISCARD gp_Ax22d Translated (const gp_Vec2d& theV) const
236   {
237     gp_Ax22d aTemp = *this;
238     aTemp.Translate (theV);
239     return aTemp;
240   }
241
242   void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { point.Translate (theP1, theP2); }
243
244   //! Translates an axis placement from the point <theP1> to the
245   //! point <theP2>.
246   Standard_NODISCARD gp_Ax22d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
247   {
248     gp_Ax22d aTemp = *this;
249     aTemp.Translate (theP1, theP2);
250     return aTemp;
251   }
252
253   //! Dumps the content of me into the stream
254   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
255
256 private:
257
258   gp_Pnt2d point;
259   gp_Dir2d vydir;
260   gp_Dir2d vxdir;
261
262 };
263
264 // =======================================================================
265 // function : SetDirection
266 // purpose  :
267 // =======================================================================
268 inline void gp_Ax22d::SetXAxis (const gp_Ax2d& theA1)
269 {
270   Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
271   point = theA1.Location ();
272   vxdir = theA1.Direction();
273   if (isSign)
274   {
275     vydir.SetCoord (-vxdir.Y(), vxdir.X());
276   }
277   else
278   {
279     vydir.SetCoord (vxdir.Y(), -vxdir.X());
280   }
281 }
282
283 // =======================================================================
284 // function : SetDirection
285 // purpose  :
286 // =======================================================================
287 inline void gp_Ax22d::SetYAxis (const gp_Ax2d& theA1)
288 {
289   Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
290   point = theA1.Location ();
291   vydir = theA1.Direction();
292   if (isSign)
293   {
294     vxdir.SetCoord (vydir.Y(), -vydir.X());
295   }
296   else
297   {
298     vxdir.SetCoord (-vydir.Y(), vydir.X());
299   }
300 }
301
302 // =======================================================================
303 // function : SetXDirection
304 // purpose  :
305 // =======================================================================
306 inline void gp_Ax22d::SetXDirection (const gp_Dir2d& theVx)
307
308   Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
309   vxdir = theVx;
310   if (isSign)
311   {
312     vydir.SetCoord (-theVx.Y(), theVx.X());
313   }
314   else
315   {
316     vydir.SetCoord (theVx.Y(), -theVx.X());
317   }
318 }
319
320 // =======================================================================
321 // function : SetYDirection
322 // purpose  :
323 // =======================================================================
324 inline void gp_Ax22d::SetYDirection (const gp_Dir2d& theVy)
325 {
326   Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
327   vydir = theVy;
328   if (isSign)
329   {
330     vxdir.SetCoord (theVy.Y(), -theVy.X());
331   }
332   else
333   {
334     vxdir.SetCoord (-theVy.Y(), theVy.X());
335   }
336 }
337
338 // =======================================================================
339 // function : Rotate
340 // purpose  :
341 // =======================================================================
342 inline void gp_Ax22d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
343 {
344   gp_Pnt2d aTemp = point;
345   aTemp.Rotate (theP, theAng);
346   point = aTemp;
347   vxdir.Rotate (theAng);
348   vydir.Rotate (theAng);
349 }
350
351 // =======================================================================
352 // function : Scale
353 // purpose  :
354 // =======================================================================
355 inline void gp_Ax22d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
356 {
357   gp_Pnt2d aTemp = point;
358   aTemp.Scale (theP, theS);
359   point = aTemp;
360   if (theS < 0.0)
361   {
362     vxdir.Reverse();
363     vydir.Reverse();
364   }
365 }
366
367 // =======================================================================
368 // function : Transform
369 // purpose  :
370 // =======================================================================
371 inline void gp_Ax22d::Transform (const gp_Trsf2d& theT)
372 {
373   gp_Pnt2d aTemp = point;
374   aTemp.Transform (theT);
375   point = aTemp;
376   vxdir.Transform (theT);
377   vydir.Transform (theT);
378 }
379
380 #endif // _gp_Ax22d_HeaderFile