0024927: Getting rid of "Persistent" functionality -- Storable
[occt.git] / src / gp / gp_Ax2.lxx
CommitLineData
b311480e 1// Copyright (c) 1996-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15#include <gp.hxx>
16#include <gp_Ax1.hxx>
17#include <Precision.hxx>
18
19inline gp_Ax2::gp_Ax2() : vydir(0.,1.,0.), vxdir(1.,0.,0.)
20{ }
21
22inline gp_Ax2::gp_Ax2(const gp_Pnt& P,
23 const gp_Dir& N,
24 const gp_Dir& Vx) : axis(P, N), vydir(N), vxdir(N)
25{
26 vxdir.CrossCross(Vx, N);
27 vydir.Cross(vxdir);
28}
29
30inline void gp_Ax2::SetAxis (const gp_Ax1& A1)
31{
32 Standard_Real a = A1.Direction() * vxdir;
33 if(Abs(Abs(a) - 1.) <= Precision::Angular()) {
34 if(a > 0.) {
35 vxdir = vydir;
36 vydir = axis.Direction();
37 axis = A1;
38 }
39 else {
40 vxdir = axis.Direction();
41 axis = A1;
42 }
43 }
44 else {
45 axis = A1;
46 vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction());
47 vydir = axis.Direction().Crossed (vxdir);
48 }
49}
50
51inline void gp_Ax2::SetDirection (const gp_Dir& V)
52{
53 Standard_Real a = V * vxdir;
54 if(Abs(Abs(a) - 1.) <= Precision::Angular()) {
55 if(a > 0.) {
56 vxdir = vydir;
57 vydir = axis.Direction();
58 axis.SetDirection (V);
59 }
60 else {
61 vxdir = axis.Direction();
62 axis.SetDirection (V);
63 }
64 }
65 else {
66 axis.SetDirection (V);
67 vxdir = V.CrossCrossed (vxdir, V);
68 vydir = V.Crossed (vxdir);
69 }
70}
71
72inline void gp_Ax2::SetLocation (const gp_Pnt& P)
73{ axis.SetLocation(P); }
74
75inline void gp_Ax2::SetXDirection (const gp_Dir& Vx)
76{
77 vxdir = axis.Direction().CrossCrossed (Vx, axis.Direction());
78 vydir = axis.Direction().Crossed (vxdir);
79}
80
81inline void gp_Ax2::SetYDirection (const gp_Dir& Vy)
82{
83 vxdir = Vy.Crossed (axis.Direction());
84 vydir = (axis.Direction()).Crossed (vxdir);
85}
86
87inline Standard_Real gp_Ax2::Angle (const gp_Ax2& Other) const
88{ return axis.Angle (Other.axis); }
89
90inline const gp_Ax1& gp_Ax2::Axis () const
91{ return axis; }
92
93inline const gp_Dir& gp_Ax2::Direction () const
94{ return axis.Direction(); }
95
96inline const gp_Pnt& gp_Ax2::Location () const
97{ return axis.Location(); }
98
99inline const gp_Dir& gp_Ax2::XDirection () const
100{ return vxdir; }
101
102inline const gp_Dir& gp_Ax2::YDirection () const
103{ return vydir; }
104
105inline Standard_Boolean gp_Ax2::IsCoplanar
106(const gp_Ax2& Other,
107 const Standard_Real LinearTolerance,
108 const Standard_Real AngularTolerance) const
109{
110 const gp_Dir& DD = axis.Direction();
111 const gp_Pnt& PP = axis.Location ();
112 const gp_Pnt& OP = Other.axis.Location ();
113 Standard_Real D1 = (DD.X() * (OP.X() - PP.X()) +
114 DD.Y() * (OP.Y() - PP.Y()) +
115 DD.Z() * (OP.Z() - PP.Z()));
116 if (D1 < 0 ) D1 = - D1;
117 return (D1 <= LinearTolerance &&
118 axis.IsParallel (Other.axis, AngularTolerance));
119}
120
121inline Standard_Boolean gp_Ax2::IsCoplanar
122(const gp_Ax1& A,
123 const Standard_Real LinearTolerance,
124 const Standard_Real AngularTolerance) const
125{
126 const gp_Dir& DD = axis.Direction();
127 const gp_Pnt& PP = axis.Location ();
128 const gp_Pnt& AP = A .Location ();
129 Standard_Real D1 = (DD.X() * (AP.X() - PP.X()) +
130 DD.Y() * (AP.Y() - PP.Y()) +
131 DD.Z() * (AP.Z() - PP.Z()));
132 if (D1 < 0) D1 = - D1;
133 return (D1 <= LinearTolerance &&
134 axis.IsNormal (A, AngularTolerance));
135}
136
137inline void gp_Ax2::Rotate(const gp_Ax1& A1, const Standard_Real Ang)
138{
139 gp_Pnt Temp = axis.Location();
140 Temp.Rotate (A1, Ang);
141 axis.SetLocation (Temp);
142 vxdir.Rotate (A1, Ang);
143 vydir.Rotate (A1, Ang);
144 axis.SetDirection (vxdir.Crossed (vydir));
145}
146
147inline gp_Ax2 gp_Ax2::Rotated(const gp_Ax1& A1,
148 const Standard_Real Ang) const
149{
150 gp_Ax2 Temp = *this;
151 Temp.Rotate (A1, Ang);
152 return Temp;
153}
154
155inline void gp_Ax2::Scale (const gp_Pnt& P, const Standard_Real S)
156{
157 gp_Pnt Temp = axis.Location();
158 Temp.Scale (P, S);
159 axis.SetLocation (Temp);
160 if (S < 0.0) {
161 vxdir.Reverse ();
162 vydir.Reverse ();
163 }
164}
165
166inline gp_Ax2 gp_Ax2::Scaled(const gp_Pnt& P,
167 const Standard_Real S) const
168{
169 gp_Ax2 Temp = *this;
170 Temp.Scale (P, S);
171 return Temp;
172}
173
174inline void gp_Ax2::Transform (const gp_Trsf& T)
175{
176 gp_Pnt Temp = axis.Location();
177 Temp.Transform (T);
178 axis.SetLocation (Temp);
179 vxdir.Transform (T);
180 vydir.Transform (T);
181 axis.SetDirection (vxdir.Crossed (vydir));
182}
183
184inline gp_Ax2 gp_Ax2::Transformed(const gp_Trsf& T) const
185{
186 gp_Ax2 Temp = *this;
187 Temp.Transform (T);
188 return Temp;
189}
190
191inline void gp_Ax2::Translate (const gp_Vec& V)
192{ axis.Translate (V); }
193
194inline gp_Ax2 gp_Ax2::Translated(const gp_Vec& V) const
195{
196 gp_Ax2 Temp = *this;
197 Temp.Translate (V);
198 return Temp;
199}
200
201inline void gp_Ax2::Translate (const gp_Pnt& P1, const gp_Pnt& P2)
202{ axis.Translate (P1, P2); }
203
204inline gp_Ax2 gp_Ax2::Translated (const gp_Pnt& P1,
205 const gp_Pnt& P2) const
206{
207 gp_Ax2 Temp = *this;
208 Temp.Translate (P1, P2);
209 return Temp;
210}
211