0024157: Parallelization of assembly part of BO
[occt.git] / src / gp / gp_Hypr.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <gp.hxx>
21 #include <Standard_DomainError.hxx>
22 #include <Standard_ConstructionError.hxx>
23
24 inline gp_Hypr::gp_Hypr () :
25 majorRadius(RealLast()),
26 minorRadius(RealFirst())
27 { }
28
29 inline gp_Hypr::gp_Hypr (const gp_Ax2& A2,
30                          const Standard_Real MajorRadius,
31                          const Standard_Real MinorRadius):
32                          pos(A2),
33                          majorRadius(MajorRadius),
34                          minorRadius(MinorRadius)
35
36   Standard_ConstructionError_Raise_if
37     (MinorRadius < 0.0 || MajorRadius < 0.0,"");
38 }
39
40 inline void gp_Hypr::SetAxis (const gp_Ax1& A1)
41 { pos.SetAxis (A1); }
42
43 inline void gp_Hypr::SetLocation (const gp_Pnt& P)
44 { pos = gp_Ax2 (P, pos.Direction(), pos.XDirection()); }
45
46 inline void gp_Hypr::SetMajorRadius (const Standard_Real R)
47 {
48   Standard_ConstructionError_Raise_if(R < 0.0,"");
49   majorRadius = R;
50 }
51
52 inline void gp_Hypr::SetMinorRadius (const Standard_Real R)
53 {
54   Standard_ConstructionError_Raise_if(R < 0.0,"");
55   minorRadius = R;
56 }
57
58 inline void gp_Hypr::SetPosition (const gp_Ax2& A2)
59 { pos = A2; }
60
61 inline gp_Ax1 gp_Hypr::Asymptote1 () const
62 {
63   Standard_ConstructionError_Raise_if
64     (majorRadius <= gp::Resolution(), "");
65   gp_Vec V1 = gp_Vec (pos.YDirection());
66   V1.Multiply (minorRadius / majorRadius);
67   gp_Vec V = gp_Vec (pos.XDirection());
68   V.Add (V1);
69   return  gp_Ax1(pos.Location(), gp_Dir(V));
70 }
71
72 inline gp_Ax1 gp_Hypr::Asymptote2 () const
73 {
74   Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), "");
75   gp_Vec V1 = gp_Vec (pos.YDirection());
76   V1.Multiply (-minorRadius / majorRadius);
77   gp_Vec V = gp_Vec (pos.XDirection());
78   V.Add (V1);
79   return  gp_Ax1( pos.Location(), gp_Dir(V));
80 }
81
82 inline const gp_Ax1& gp_Hypr::Axis () const
83 { return pos.Axis(); }
84
85 inline gp_Hypr gp_Hypr::ConjugateBranch1 () const
86 {
87   return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), pos.YDirection()),
88                   minorRadius, 
89                   majorRadius);
90 }
91
92 inline gp_Hypr gp_Hypr::ConjugateBranch2 () const
93 {
94   gp_Dir D = pos.YDirection();
95   D.Reverse ();
96   return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), D),
97                   minorRadius, 
98                   majorRadius);
99 }
100
101 inline gp_Ax1 gp_Hypr::Directrix1 () const
102 {
103   Standard_Real E = Eccentricity();
104   gp_XYZ Orig = pos.XDirection().XYZ();
105   Orig.Multiply (majorRadius/E);
106   Orig.Add (pos.Location().XYZ());
107   return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
108 }
109
110 inline gp_Ax1 gp_Hypr::Directrix2 () const
111 {
112   Standard_Real E = Eccentricity();
113   gp_XYZ Orig = pos.XDirection().XYZ();
114   Orig.Multiply (-majorRadius/E);
115   Orig.Add (pos.Location().XYZ());
116   return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
117 }
118
119 inline Standard_Real gp_Hypr::Eccentricity () const
120 {
121   Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), "");
122   return sqrt(majorRadius * majorRadius +
123               minorRadius * minorRadius) / majorRadius;
124 }
125
126 inline Standard_Real gp_Hypr::Focal () const
127 {
128   return 2.0 * sqrt(majorRadius * majorRadius +
129                     minorRadius * minorRadius);
130 }
131
132 inline gp_Pnt gp_Hypr::Focus1 () const
133 {
134   Standard_Real C = sqrt(majorRadius * majorRadius +
135                          minorRadius * minorRadius);
136   const gp_Pnt& PP = pos.Location  ();
137   const gp_Dir& DD = pos.XDirection();
138   return gp_Pnt (PP.X() + C * DD.X(),
139                  PP.Y() + C * DD.Y(),
140                  PP.Z() + C * DD.Z());
141 }
142
143 inline gp_Pnt gp_Hypr::Focus2 () const
144 {
145   Standard_Real C = sqrt(majorRadius * majorRadius +
146                          minorRadius * minorRadius);
147   const gp_Pnt& PP = pos.Location  ();
148   const gp_Dir& DD = pos.XDirection();
149   return gp_Pnt (PP.X() - C * DD.X(),
150                  PP.Y() - C * DD.Y(),
151                  PP.Z() - C * DD.Z());
152 }
153
154 inline const gp_Pnt& gp_Hypr::Location () const
155 { return pos.Location(); }
156
157 inline   Standard_Real gp_Hypr::MajorRadius() const
158 { return majorRadius; }
159
160 inline   Standard_Real gp_Hypr::MinorRadius() const
161 { return minorRadius; }
162
163 inline gp_Hypr gp_Hypr::OtherBranch () const
164 {
165   gp_Dir D = pos.XDirection ();
166   D.Reverse ();
167   return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), D),
168                   majorRadius, minorRadius);
169 }
170
171 inline Standard_Real gp_Hypr::Parameter() const
172 {
173   Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), "");
174   return (minorRadius * minorRadius) / majorRadius;
175 }
176
177 inline   const gp_Ax2& gp_Hypr::Position() const
178 { return pos; }
179
180 inline gp_Ax1 gp_Hypr::XAxis () const
181 {return gp_Ax1 (pos.Location(), pos.XDirection());}
182
183 inline gp_Ax1 gp_Hypr::YAxis () const
184 {return gp_Ax1 (pos.Location(), pos.YDirection());}
185
186 inline void gp_Hypr::Rotate (const gp_Ax1& A1,
187                              const Standard_Real Ang)
188 { pos.Rotate(A1, Ang); }
189
190 inline gp_Hypr gp_Hypr::Rotated (const gp_Ax1& A1,
191                                  const Standard_Real Ang) const
192 {
193   gp_Hypr H = *this;
194   H.pos.Rotate(A1, Ang);
195   return H; 
196 }
197
198 inline void gp_Hypr::Scale (const gp_Pnt& P,
199                             const Standard_Real S)
200 {
201   majorRadius *= S;
202   if (majorRadius < 0) majorRadius = - majorRadius;
203   minorRadius *= S;
204   if (minorRadius < 0) minorRadius = - minorRadius;
205   pos.Scale(P, S);
206 }
207
208 inline gp_Hypr gp_Hypr::Scaled (const gp_Pnt& P,
209                                 const Standard_Real S) const
210 {
211   gp_Hypr H = *this;
212   H.majorRadius *= S;
213   if (H.majorRadius < 0) H.majorRadius = - H.majorRadius;
214   H.minorRadius *= S;
215   if (H.minorRadius < 0) H.minorRadius = - H.minorRadius;
216   H.pos.Scale(P, S);
217   return H; 
218 }
219
220 inline void gp_Hypr::Transform (const gp_Trsf& T)
221
222   majorRadius *= T.ScaleFactor();
223   if (majorRadius < 0) majorRadius = - majorRadius;
224   minorRadius *= T.ScaleFactor();
225   if (minorRadius < 0) minorRadius = - minorRadius;
226   pos.Transform(T);
227 }
228
229 inline gp_Hypr gp_Hypr::Transformed (const gp_Trsf& T) const
230 {
231   gp_Hypr H = *this;
232   H.majorRadius *= T.ScaleFactor();
233   if (H.majorRadius < 0) H.majorRadius = - H.majorRadius;
234   H.minorRadius *= T.ScaleFactor();
235   if (H.minorRadius < 0) H.minorRadius = - H.minorRadius;
236   H.pos.Transform(T);
237   return H; 
238 }
239
240 inline void gp_Hypr::Translate (const gp_Vec& V)
241 { pos.Translate(V); }
242
243 inline gp_Hypr gp_Hypr::Translated (const gp_Vec& V) const
244 {
245   gp_Hypr H = *this;
246   H.pos.Translate(V);
247   return H; 
248 }
249
250 inline void gp_Hypr::Translate (const gp_Pnt& P1,
251                                 const gp_Pnt& P2)
252 {pos.Translate(P1,P2);}
253
254 inline gp_Hypr gp_Hypr::Translated (const gp_Pnt& P1,
255                                     const gp_Pnt& P2) const
256 {
257   gp_Hypr H = *this;
258   H.pos.Translate(P1, P2);
259   return H; 
260 }
261